There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

SHARE WITH THE CLASS: What aliases are you using?

From bash to zsh and everywhere in between, show me yours and I'll show you mines. Inspire others or get some feedback.

Simply copy & paste the output of alias in your terminal or add some comments to explain things for others.

Edit: Kbin users, click 'More' on a comment and use the fediverse link to read responses that have funky formatting

TexasCrowbarMassacre ,

alias forgethist=unset HISTFILE

Useful when I run the same two commands 20 times in a row

tho ,
@tho@lemmy.ml avatar

in zsh you can just forbid it to save duplicates

doomkernel ,

I’ve got the standard ones (l, ll, ls) to be forms of ls -flags


<span style="color:#323232;">df = df -h
</span><span style="color:#323232;">mv = mv -i
</span><span style="color:#323232;">rm = rm -i
</span><span style="color:#323232;">nix-switch = sudo nix-rebuild --switch flake .
</span><span style="color:#323232;">nix-upd = nix flake update
</span><span style="color:#323232;">systat = systemctl status
</span><span style="color:#323232;">sysena = sudo systemctl enable
</span><span style="color:#323232;">systop = sudo systemctl stop
</span><span style="color:#323232;">
</span>
macallik OP ,

Digging the systemctl ones. I added myself to the group so that I wouldn't have to write sudo each time, but I might as well alias the entire prompt for restart and status to make it even shorter

rutrum ,
@rutrum@lm.paradisus.day avatar

I also use alias nd=nix develop a lot.

tho ,
@tho@lemmy.ml avatar

<span style="color:#323232;">ccd() {
</span><span style="color:#323232;">  mkdir "$1" &amp;&amp; cd "$1"
</span><span style="color:#323232;">}
</span>
bennieandthez ,
@bennieandthez@lemmygrad.ml avatar

These are some pacman+fzf implementations from the arch wiki + a flatpak implementation i did with fzf(still needs some polish but it works).

alias pacq=$‘pacman -Q | fzf’

alias pacs=$‘pacman -Slq | fzf --multi --preview 'pacman -Si {1}' | xargs -ro sudo pacman -S’

alias pacr=$‘pacman -Qq | fzf --multi --preview 'pacman -Si {1}' | xargs -ro sudo pacman -Rns’

alias flatr=$‘flatpak list | fzf --preview 'flatpak info {2} ' | grep -Eo '[a-ZA-Z]+.[^ ]+' |awk '{print $1}' | xargs -ro flatpak remove --delete-data’

megane_kun ,

Some QoL stuff my good friend set-up for me.


<span style="color:#323232;"># ALIASES -- EXA
</span><span style="color:#323232;">alias ls='exa --group-directories-first --color=auto -h -aa -l --git'
</span><span style="color:#323232;">
</span><span style="color:#323232;"># ALIASES -- YAY
</span><span style="color:#323232;">alias yy='yay -Y --needed --norebuild --nocleanafter --nodiffmenu --noredownload --nocleanmenu --removemake --sudoloop'
</span><span style="color:#323232;">alias ya='yay -S --needed --norebuild --nocleanafter --nodiffmenu --noredownload --nocleanmenu --removemake --sudoloop'
</span><span style="color:#323232;">alias yu='yay -R --recursive --nosave'
</span><span style="color:#323232;">
</span><span style="color:#323232;"># ALIASES -- CP
</span><span style="color:#323232;">alias cp="cp --reflink=auto -i"
</span>

And then there’s a bunch of stuff from the output of alias, most of them are git aliases. Those which aren’t git-related are listed below:


<span style="color:#323232;">-='cd -'
</span><span style="color:#323232;">...=../..
</span><span style="color:#323232;">....=../../..
</span><span style="color:#323232;">.....=../../../..
</span><span style="color:#323232;">......=../../../../..
</span><span style="color:#323232;">1='cd -1'
</span><span style="color:#323232;">2='cd -2'
</span><span style="color:#323232;">3='cd -3'
</span><span style="color:#323232;">4='cd -4'
</span><span style="color:#323232;">5='cd -5'
</span><span style="color:#323232;">6='cd -6'
</span><span style="color:#323232;">7='cd -7'
</span><span style="color:#323232;">8='cd -8'
</span><span style="color:#323232;">9='cd -9'
</span><span style="color:#323232;">_='sudo '
</span><span style="color:#323232;">cp='cp --reflink=auto -i'
</span><span style="color:#323232;">egrep='grep -E --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox}'
</span><span style="color:#323232;">fgrep='grep -F --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox}'
</span><span style="color:#323232;">history=omz_history
</span><span style="color:#323232;">l='ls -lah'
</span><span style="color:#323232;">la='ls -lAh'
</span><span style="color:#323232;">ll='ls -lh'
</span><span style="color:#323232;">ls='exa --group-directories-first --color=auto -h -aa -l --git'
</span><span style="color:#323232;">lsa='ls -lah'
</span><span style="color:#323232;">md='mkdir -p'
</span><span style="color:#323232;">rd=rmdir
</span><span style="color:#323232;">run-help=man
</span><span style="color:#323232;">which-command=whence
</span>
macallik OP ,

Good to see another exa user. Care to break down what yay does btw?

megane_kun , (edited )

Ah, yay is an AUR helper, though I personally see it as a pacman helper as well. Link here. Some of the flags and options that can be used for pacman can be used for yay, thus, some of the flags in the aliases I use are actually for pacman. Anyways, on to the breakdown.

alias yy=‘yay -Y --needed --norebuild --nocleanafter --nodiffmenu --noredownload --nocleanmenu --removemake --sudoloop’

This one is what I use to look up for packages. The result of runnning yy «search term» would be a list of packages matching the search term and prompting the user on which package(s) to install.

flag description
-Y performs yay-specific operations.
–needed (pacman) do not reinstall up to date packages
–norebuild skips package build if in cache and up to date
–nocleanafter do not remove package sources after successful build
–noredownlod skip pkgbuild download if in cache and up to date
–nodiffmenu don’t show diffs for build files
–nocleanmenu don’t clean build PKGBUILDS
–removemake remove makedepends after install
–sudoloop loop sudo calls in the background to avoid timeout

alias ya=‘yay -S --needed --norebuild --nocleanafter --nodiffmenu --noredownload --nocleanmenu --removemake --sudoloop’

This one is what I use for installing packages. Useful if I already know what package I would be installing.

flag description
-S (pacman, extended by Yay to cover AUR as well) Synchronize packages. Packages are installed directly from the remote repositories, including all dependencies required to run the packages.

alias yu=‘yay -R --recursive --nosave’

This one is what I use when uninstalling packages. I usually check the package name with something like yay -Qi «package-name-guess» beforehand.

flag description
-R (pacman, extended by Yay to also remove cached data about devel packages) Remove package(s) from the system.
–recursive (pacman) Remove each target specified including all of their dependencies, provided that (A) they are not required by other packages; and (B) they were not explicitly installed by the user. This operation is recurisve and analogous to a backwards –sync operation.
–nosave (pacman) Instructs pacman to ignore file backup designations. (This avoids the removed files being renamed with a .pacsave extension.)

I actually don’t know much about both yay and pacman myself, since the aliases were just passed onto me by the same friend who helped me (re-)install my system (long story) and set-up the aliases. Having looked all these up, however, I might make a few changes (like changing the –nocleanafter and –nocleanmenu options to their clean ones`).

soloner ,

I like the idea of binding numbers to parent directory traversal. I do cd …/… a lot in one of my projects (switching between source code and terraform folder), it’d be handy to get out of the terraform folder by just typing 2.

megane_kun ,

I actually would do cd … and then do a pwd (and so on, repeatedly) because I often get confused and have a very short attention span that the aliases ended up unused.

olafurp ,

I have codebase of 5k lines. Most used are git commands (squash all to merge base, push to current branch, commit with format etc), work shortcuts for starting projects, time logging, startup programs. Then I have some cli interface for redo commands, size of current folders for disk pruning, abandoned project alias, os commands like brightness adjust, launch game on steam with qwert instead of dvorak keyboard, search cli history, kill with regex matching…

Just anything that I don’t want to Google twice. bash is life

iHUNTcriminals ,

What… I didn’t know this was a thing.

So I could make be “sudo gimme-dat-new-new” Instead of “sudo DNF upgrade -y”

Vilian ,

you can just put “gimme-dat-new-new”

s20 ,

alias gimmie-dat-new-new=‘sudo dnf upgrade -y’

Although you should probably look over your upgrade before applying it as a general good practice. But, hey, I do this myself (dnfup instead of gimmie-dat-etc.), so I can’t talk too much shit.

ETA: If you want it to be a persistent alias, though, you gotta add it to your .bashrc

Scio ,
@Scio@kbin.social avatar

I'm going to assume all these syntax highlighted HTML embeds are from Lemmy users. Sadly, illegible on Kbin.

macallik OP ,

Ahhh I was wondering what that was as a fellow kbin-er. I was pleasantly surprised when I found out I could create threads across the fediverse today as a consolation.

Edit: Click the 'more' button on the comment and get the fediverse link to view the formatted post

Aatube ,
@Aatube@kbin.social avatar

alias cat lolcat
alias ccat whatever ohmyzsh does for their colorize extension, I know it’s a function alias

ProtonBadger ,

Just some simple stuff:

Strix ~> alias
alias balanced 'asusctl profile -P balanced'
alias performance 'asusctl profile -P performance'
alias quiet 'asusctl profile -P quiet'
alias upd 'yay ; flatpak update'

I_Am_Jacks_____ ,

For system updates:


<span style="color:#323232;">[ -r /etc/os-release ] &amp;&amp; . /etc/os-release
</span><span style="color:#323232;">case "$ID" in
</span><span style="color:#323232;">  arch|archarm)
</span><span style="color:#323232;">    if which paru > /dev/null 2>&amp;1; then
</span><span style="color:#323232;">      alias updates='echo Using paru; paru'
</span><span style="color:#323232;">    else
</span><span style="color:#323232;">      alias updates='echo Using pacman; sudo pacman -Syu --noconfirm'
</span><span style="color:#323232;">    fi
</span><span style="color:#323232;">    ;;
</span><span style="color:#323232;">  debian|ubuntu)
</span><span style="color:#323232;">    alias updates='echo Using apt dist-upgrade; sudo apt update &amp;&amp; sudo apt dist-upgrade -y'
</span><span style="color:#323232;">    ;;
</span><span style="color:#323232;">esac
</span>
ShittyBeatlesFCPres ,

I have a similar one but I did it this way:


<span style="color:#323232;">
</span><span style="font-weight:bold;color:#a71d5d;">function </span><span style="font-weight:bold;color:#795da3;">ins </span><span style="color:#323232;">{
</span><span style="color:#323232;">  PACKAGE</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">"${</span><span style="color:#323232;">1</span><span style="color:#183691;">}"
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#795da3;">exists</span><span style="color:#323232;">() {
</span><span style="color:#323232;">    </span><span style="color:#62a35c;">command </span><span style="color:#323232;">-v </span><span style="color:#183691;">"$</span><span style="color:#323232;">1</span><span style="color:#183691;">" </span><span style="font-weight:bold;color:#a71d5d;">></span><span style="color:#323232;">/dev/null </span><span style="color:#0086b3;">2</span><span style="font-weight:bold;color:#a71d5d;">>&</span><span style="color:#323232;">amp</span><span style="font-weight:bold;color:#a71d5d;">;</span><span style="color:#323232;">1
</span><span style="color:#323232;">  }
</span><span style="color:#323232;">
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">if </span><span style="color:#323232;">exists dnf</span><span style="font-weight:bold;color:#a71d5d;">; then </span><span style="font-style:italic;color:#969896;">#Fedora
</span><span style="color:#323232;">    sudo dnf update </span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp;</span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp</span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">sudo dnf install -y $PACKAGE
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">elif </span><span style="color:#323232;">exists apt</span><span style="font-weight:bold;color:#a71d5d;">; then </span><span style="font-style:italic;color:#969896;">#Debian
</span><span style="color:#323232;">    sudo apt update </span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp;</span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp</span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">sudo apt install -y $PACKAGE
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">elif </span><span style="color:#323232;">exists apk</span><span style="font-weight:bold;color:#a71d5d;">; then </span><span style="font-style:italic;color:#969896;">#Alpine
</span><span style="color:#323232;">    apk -U upgrade </span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp;</span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp</span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">apk add $PACKAGE
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">elif </span><span style="color:#323232;">exists emerge</span><span style="font-weight:bold;color:#a71d5d;">; then </span><span style="font-style:italic;color:#969896;">#Gentoo
</span><span style="color:#323232;">    sudo emerge $PACKAGE
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">elif </span><span style="color:#323232;">exists zypper</span><span style="font-weight:bold;color:#a71d5d;">; then </span><span style="font-style:italic;color:#969896;">#Suse
</span><span style="color:#323232;">    sudo zypper ref </span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp;</span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp</span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">sudo zypper install $PACKAGE
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">elif </span><span style="color:#323232;">exists pacman</span><span style="font-weight:bold;color:#a71d5d;">; then </span><span style="font-style:italic;color:#969896;">#Arch
</span><span style="color:#323232;">    pacman -S $PACKAGE
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">elif </span><span style="color:#323232;">exists brew</span><span style="font-weight:bold;color:#a71d5d;">; then </span><span style="font-style:italic;color:#969896;">#MacOS
</span><span style="color:#323232;">    brew install $PACKAGE
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">else
</span><span style="color:#323232;">    </span><span style="color:#62a35c;">echo </span><span style="color:#183691;">"Error can't install package $</span><span style="color:#323232;">PACKAGE</span><span style="color:#183691;">. No package manager is detected."
</span><span style="color:#323232;">    </span><span style="color:#62a35c;">exit</span><span style="color:#323232;"> 1</span><span style="font-weight:bold;color:#a71d5d;">;
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">fi
</span><span style="color:#323232;">}
</span>
ShittyBeatlesFCPres ,

Actually that’s the install one. Here’s the upgrade one:


<span style="color:#323232;">
</span><span style="font-weight:bold;color:#a71d5d;">function </span><span style="font-weight:bold;color:#795da3;">upg </span><span style="color:#323232;">{
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#795da3;">exists</span><span style="color:#323232;">() {
</span><span style="color:#323232;">    </span><span style="color:#62a35c;">command </span><span style="color:#323232;">-v </span><span style="color:#183691;">"$</span><span style="color:#323232;">1</span><span style="color:#183691;">" </span><span style="font-weight:bold;color:#a71d5d;">></span><span style="color:#323232;">/dev/null </span><span style="color:#0086b3;">2</span><span style="font-weight:bold;color:#a71d5d;">>&</span><span style="color:#323232;">amp</span><span style="font-weight:bold;color:#a71d5d;">;</span><span style="color:#323232;">1
</span><span style="color:#323232;">  }
</span><span style="color:#323232;">
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">if </span><span style="color:#323232;">exists dnf</span><span style="font-weight:bold;color:#a71d5d;">; then </span><span style="font-style:italic;color:#969896;">#Fedora
</span><span style="color:#323232;">    sudo dnf update </span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp;</span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp</span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">sudo dnf -y upgrade </span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp;</span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp</span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">sudo dnf -y autoremove
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">elif </span><span style="color:#323232;">exists apt</span><span style="font-weight:bold;color:#a71d5d;">; then </span><span style="font-style:italic;color:#969896;">#Debian
</span><span style="color:#323232;">    sudo apt update </span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp;</span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp</span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">sudo apt full-upgrade -y
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">elif </span><span style="color:#323232;">exists apk</span><span style="font-weight:bold;color:#a71d5d;">; then </span><span style="font-style:italic;color:#969896;">#Alpine
</span><span style="color:#323232;">    apk -U upgrade
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">elif </span><span style="color:#323232;">exists emerge</span><span style="font-weight:bold;color:#a71d5d;">; then </span><span style="font-style:italic;color:#969896;">#Gentoo
</span><span style="color:#323232;">    sudo emerge --ask --verbose --update --deep --newuse @world </span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp;</span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp</span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">sudo emerge --ask --verbose --depclean
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">elif </span><span style="color:#323232;">exists zypper</span><span style="font-weight:bold;color:#a71d5d;">; then </span><span style="font-style:italic;color:#969896;">#Suse
</span><span style="color:#323232;">    sudo zypper ref </span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp;</span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp</span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">sudo zypper update
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">elif </span><span style="color:#323232;">exists pacman</span><span style="font-weight:bold;color:#a71d5d;">; then </span><span style="font-style:italic;color:#969896;">#Arch
</span><span style="color:#323232;">    pacman -Syu
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">elif </span><span style="color:#323232;">exists brew</span><span style="font-weight:bold;color:#a71d5d;">; then </span><span style="font-style:italic;color:#969896;">#MacOS
</span><span style="color:#323232;">    brew update </span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp;</span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp</span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">brew upgrade
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">else
</span><span style="color:#323232;">    </span><span style="color:#62a35c;">echo </span><span style="color:#183691;">"Error: cannot update packages. No package manager is detected."
</span><span style="color:#323232;">    </span><span style="color:#62a35c;">exit</span><span style="color:#323232;"> 1</span><span style="font-weight:bold;color:#a71d5d;">;
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">fi
</span><span style="color:#323232;">
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">if </span><span style="color:#323232;">exists snap</span><span style="font-weight:bold;color:#a71d5d;">; then </span><span style="font-style:italic;color:#969896;">#Snaps
</span><span style="color:#323232;">    sudo snap refresh
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">fi
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">if </span><span style="color:#323232;">exists flatpak</span><span style="font-weight:bold;color:#a71d5d;">; then </span><span style="font-style:italic;color:#969896;">#Flatpak
</span><span style="color:#323232;">    flatpak update -y
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">fi
</span><span style="color:#323232;">}
</span>
I_Am_Jacks_____ ,

Very nice

megane_kun , (edited )

This is a separate reply since I didn’t know that you can include shell functions here.

I made this little function read_latest_log() because I just want to “read the latest log file” in a directory full of timestamped log files. I made a helper function separator_line_with_text() to help with the output, basically setting off the file-info portion (just the filename for now) from the file contents.


<span style="color:#323232;"># # separator_line_with_text
</span><span style="color:#323232;"># # Centers text in a separator line
</span><span style="color:#323232;"># #
</span><span style="color:#323232;"># # Usage:
</span><span style="color:#323232;"># # separator_line_with_text «separator_char» «text»
</span><span style="color:#323232;">separator_line_with_text() {
</span><span style="color:#323232;">local separator_char="$1"
</span><span style="color:#323232;">local contents_str="$2"
</span><span style="color:#323232;">
</span><span style="color:#323232;"># Calculate separator_length
</span><span style="color:#323232;">local separator_length=$(( $(tput cols) - 2 - ${#contents_str} ))
</span><span style="color:#323232;">
</span><span style="color:#323232;"># Calculate the width of the left and right parts of the separator line
</span><span style="color:#323232;">local half_line_width=$(( (${separator_length}) / 2 ))
</span><span style="color:#323232;">
</span><span style="color:#323232;"># Construct the separator line using the $separator_char and $contents_str
</span><span style="color:#323232;">for ((i = 0; i « half_line_width; i++))
</span><span style="color:#323232;">do
</span><span style="color:#323232;">echo -n ${separator_char}
</span><span style="color:#323232;">done
</span><span style="color:#323232;">
</span><span style="color:#323232;">echo -n ${contents_str}
</span><span style="color:#323232;">
</span><span style="color:#323232;">for ((i = 0; i &lt; half_line_width; i++))
</span><span style="color:#323232;">do
</span><span style="color:#323232;">echo -n ${separator_char}
</span><span style="color:#323232;">done
</span><span style="color:#323232;">
</span><span style="color:#323232;">echo ""
</span><span style="color:#323232;">}
</span><span style="color:#323232;">
</span><span style="color:#323232;"># # read_latest_log
</span><span style="color:#323232;"># # Reads the latest log file with a timestamp in the filename.
</span><span style="color:#323232;"># #
</span><span style="color:#323232;"># # Usage:
</span><span style="color:#323232;"># # read_latest_log [[«name_filter»] «extension»] «separator» «timestamp_field_number»
</span><span style="color:#323232;">read_latest_log () {
</span><span style="color:#323232;">  # Check if the function has sufficient parameters
</span><span style="color:#323232;">  if [[ $# -lt 2 ]]; then
</span><span style="color:#323232;">    echo "Error: insufficient parameters."
</span><span style="color:#323232;">    echo "Usage: read_latest_log [[«name_filter» = *] [«extension» = log] «separator» «timestamp_field_number»"
</span><span style="color:#323232;">    return 1
</span><span style="color:#323232;">  fi
</span><span style="color:#323232;">
</span><span style="color:#323232;">  # Supposing only two parameters are provided
</span><span style="color:#323232;">  # «name_filter» parameter is "*"
</span><span style="color:#323232;">  # «extension» parameter is "log"
</span><span style="color:#323232;">  if [[ $# -eq 2 ]]; then
</span><span style="color:#323232;">    local name_filter="*"
</span><span style="color:#323232;">    local extension="log"
</span><span style="color:#323232;">    local separator="$1"
</span><span style="color:#323232;">    local field="$2"
</span><span style="color:#323232;">  fi
</span><span style="color:#323232;">
</span><span style="color:#323232;">  # Supposing only three parameters are provided,
</span><span style="color:#323232;">  # assume that the «name_filter» parameter is "*"
</span><span style="color:#323232;">  if [[ $# -eq 3 ]]; then
</span><span style="color:#323232;">    local name_filter="*"
</span><span style="color:#323232;">    local extension="$1"
</span><span style="color:#323232;">    local separator="$2"
</span><span style="color:#323232;">    local field="$3"
</span><span style="color:#323232;">  fi
</span><span style="color:#323232;">
</span><span style="color:#323232;">  # If all parameters are provided, assign them accordingly
</span><span style="color:#323232;">  if [[ $# -eq 4 ]]; then
</span><span style="color:#323232;">    local name_filter="$1"
</span><span style="color:#323232;">    local extension="$2"
</span><span style="color:#323232;">    local separator="$3"
</span><span style="color:#323232;">    local field="$4"
</span><span style="color:#323232;">  fi
</span><span style="color:#323232;">
</span><span style="color:#323232;">  # Find all log files with the specified extension, sort them based on the separator and field
</span><span style="color:#323232;">  local log_files=$(find . -type f -name "${name_filter}.${extension}" | sort -n -t "${separator}" -k "${field}")
</span><span style="color:#323232;">
</span><span style="color:#323232;">  # If no log files are found, display a message and return
</span><span style="color:#323232;">  if [[ -z "$log_files" ]]; then
</span><span style="color:#323232;">    echo "No log files found."
</span><span style="color:#323232;">    return 0
</span><span style="color:#323232;">  fi
</span><span style="color:#323232;">
</span><span style="color:#323232;">  # Get the latest log file and its full path
</span><span style="color:#323232;">  local latest_log_file=$(echo "$log_files" | tail -1)
</span><span style="color:#323232;">  local full_path=$(realpath "$latest_log_file")
</span><span style="color:#323232;">
</span><span style="color:#323232;">  # Define the strings for the separator line and
</span><span style="color:#323232;">  # calculate the appropriate length of the separator line
</span><span style="color:#323232;">  local contents_str=" Contents "
</span><span style="color:#323232;">  local separator_char="—"
</span><span style="color:#323232;">
</span><span style="color:#323232;">  separator_line_with_text ${separator_char} ""
</span><span style="color:#323232;">  separator_line_with_text " " ${full_path}
</span><span style="color:#323232;">  separator_line_with_text ${separator_char} ${contents_str}
</span><span style="color:#323232;">  cat "$(echo "$log_files" | tail -1)"
</span><span style="color:#323232;">}
</span>

Sorry for all the edits, for some reason anything that looks like an HTML tag gets erased.

chrishazfun ,
@chrishazfun@lemmy.world avatar

<span style="color:#323232;">alias getmp4="yt-dlp -f 'bestvideo+bestaudio[ext=m4a]/best[ext=mp4]' --recode-video mp4"
</span><span style="color:#323232;">alias getmp3="yt-dlp -x --audio-format mp3"
</span><span style="color:#323232;">alias downloadwebsite="wget -mkEpnp"
</span><span style="color:#323232;">
</span><span style="color:#323232;">flushall () {
</span><span style="color:#323232;">	sudo pacman -Scc
</span><span style="color:#323232;">	sudo pacman -Rns $(pacman -Qdtq)
</span><span style="color:#323232;">	flatpak uninstall --unused
</span><span style="color:#323232;">}
</span><span style="color:#323232;">
</span><span style="color:#323232;">updateall () {
</span><span style="color:#323232;">	yay
</span><span style="color:#323232;">	flatpak update
</span><span style="color:#323232;">	while
</span><span style="color:#323232;">		read -p "Clear cache and uninstall orphans? (y/N)" answer
</span><span style="color:#323232;">	do
</span><span style="color:#323232;">		case $answer in
</span><span style="color:#323232;">			([yY][eE][sS] | [yY]) flushall;;
</span><span style="color:#323232;">			(*) break;;
</span><span style="color:#323232;">		esac
</span><span style="color:#323232;">	done
</span><span style="color:#323232;">}
</span>
  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines