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. It's one of the many personalizable aspects of Linux. Why not share it to inspire others on what is possible or get feedback. You can simply copy & paste the output of 'alias' in your terminal or insert some comments to explain things for others. #sharewiththeclass #bash #zsh #aliases

https://kbin.social/m/[email protected]/t/472971

SHARE WITH THE CLASS: What aliases are you using? - linux - kbin.social

From bash to zsh and everywhere in between, show me yours and I'll show you mines. It's one of the many personalizable aspects of Linux. Why not share it to inspire others on what is possible or get feedback. You can simply copy & paste the output of 'alias' in your terminal or insert some comments to explain things for others.

BASH

App-Specific

alias webcord='nohup webcord &' # Open the less intrusive version of discord automatically alias battery='upower -i $(upower -e | grep 'BAT') | grep -E "state|to\ full|percentage"' # Get the battery level of my laptop server when I ssh into it alias audio="yt-dlp -f 'ba' -x --audio-format mp3" # Download the audio version of a youtube video alias worst="yt-dlp -f worst" # Download the lowest quality video of a youtube video (for when audio isn't available) alias wttr="curl wttr.in/Chicago" # Get the weather of my city in the terminal

Terminal Navigation

alias cba='batcat ~/.bash_aliases --theme=ansi' # print my bash aliases (w/ formatting) alias ba2sy="cp ~/.bash_aliases ~/Sync/" # copy my current iteration of my aliases to my shared syncthing folder so that it's accessible across devices alias sy2ba="cp ~/Sync/.bash_aliases ~/" # replace the current iteration of my aliases w/ the synced version from my syncthing folder alias mba='micro .bash_aliases' # open my aliases file in the modernized version of 'nano' alias sudo='sudo ' #Can't remember why I have this one lol alias ug='nala list --upgradeable' # Shortcut to see what upgrades are available when I run nala update alias reload="source ~/.bashrc" # Quickly refresh my system so that the latest alias file is loaded alias gh='history|grep' # search history for <insert string> alias l='exa --group-directories-first -hlras modified --no-user --icons' # exa is basically a prettier version of ls. Options toggled: Human-readable, long format, reverse output, show hidden files/folders, sort by modified date. Show icons in the output and remove the user column alias lls='exa --group-directories-first -hlras size --no-user --icons' # Same as the first one except sort by file size alias ll='exa --group-directories-first -hlrs modified --no-user --icons' # Same as above but ignored hidden files/folder

Replaced Commands

alias cat='batcat --theme=ansi ' # Replace the generic output of cat w/ a formatted version. This is bat (batcat in Debian). Use the theme called 'ansi' alias catt='batcat ' # Same as the above, but using the default theme (can be hard to read w/ solarized background) alias rm='trash ' # Instead of auto-deleting files, put them in the 'trash' bin for 30 days, then delete.

Server & Docker-related

alias lazy='/home/macallik/.local/bin/lazydocker' # Run Docker alias pad='ssh MyPad20334' # shorthand to ssh into my server
I wonder if you can be a madlad and symlink your bash-aliases to a synced file.
Not a symlink, but you can add source /path/to/aliases one your bashrc file to load them from another file. I do that and keep all of my dot files in a hit repo.
exa is unmaintained, as per the the developer you should use eza instead.
GitHub - ogham/exa: A modern replacement for ‘ls’.

A modern replacement for ‘ls’. Contribute to ogham/exa development by creating an account on GitHub.

GitHub
Thanks for the heads up

alias hgrep=‘function _f(){ history | grep $1; };_f’

Because I’m to lazy to type

history | grep whatever_I’m_looking_for

alias rpmfind='rpm -qa | grep' ```'
OMG. I originally got the impression (from somewhere) that you couldn’t pass arguments to an alias, so I googled and found that weird function nonsense. Oh well, live and learn. Thanks.

For system updates:

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

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

function ins { PACKAGE="${1}" exists() { command -v "$1" >/dev/null 2>&amp;1 } if exists dnf; then #Fedora sudo dnf update &amp;&amp; sudo dnf install -y $PACKAGE elif exists apt; then #Debian sudo apt update &amp;&amp; sudo apt install -y $PACKAGE elif exists apk; then #Alpine apk -U upgrade &amp;&amp; apk add $PACKAGE elif exists emerge; then #Gentoo sudo emerge $PACKAGE elif exists zypper; then #Suse sudo zypper ref &amp;&amp; sudo zypper install $PACKAGE elif exists pacman; then #Arch pacman -S $PACKAGE elif exists brew; then #MacOS brew install $PACKAGE else echo "Error can't install package $PACKAGE. No package manager is detected." exit 1; fi }

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

function upg { exists() { command -v "$1" >/dev/null 2>&amp;1 } if exists dnf; then #Fedora sudo dnf update &amp;&amp; sudo dnf -y upgrade &amp;&amp; sudo dnf -y autoremove elif exists apt; then #Debian sudo apt update &amp;&amp; sudo apt full-upgrade -y elif exists apk; then #Alpine apk -U upgrade elif exists emerge; then #Gentoo sudo emerge --ask --verbose --update --deep --newuse @world &amp;&amp; sudo emerge --ask --verbose --depclean elif exists zypper; then #Suse sudo zypper ref &amp;&amp; sudo zypper update elif exists pacman; then #Arch pacman -Syu elif exists brew; then #MacOS brew update &amp;&amp; brew upgrade else echo "Error: cannot update packages. No package manager is detected." exit 1; fi if exists snap; then #Snaps sudo snap refresh fi if exists flatpak; then #Flatpak flatpak update -y fi }
alias getmp4="yt-dlp -f 'bestvideo+bestaudio[ext=m4a]/best[ext=mp4]' --recode-video mp4" alias getmp3="yt-dlp -x --audio-format mp3" alias downloadwebsite="wget -mkEpnp" flushall () { sudo pacman -Scc sudo pacman -Rns $(pacman -Qdtq) flatpak uninstall --unused } updateall () { yay flatpak update while read -p "Clear cache and uninstall orphans? (y/N)" answer do case $answer in ([yY][eE][sS] | [yY]) flushall;; (*) break;; esac done }

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

df = df -h mv = mv -i rm = rm -i nix-switch = sudo nix-rebuild --switch flake . nix-upd = nix flake update systat = systemctl status sysena = sudo systemctl enable systop = sudo systemctl stop
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 restart and status to make it even shorter
I also use alias nd=nix develop a lot.

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

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

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:

-='cd -' ...=../.. ....=../../.. .....=../../../.. ......=../../../../.. 1='cd -1' 2='cd -2' 3='cd -3' 4='cd -4' 5='cd -5' 6='cd -6' 7='cd -7' 8='cd -8' 9='cd -9' _='sudo ' cp='cp --reflink=auto -i' egrep='grep -E --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox}' fgrep='grep -F --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox}'
Good to see another exa user. Care to break down what yay does btw?

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.

  • -Y perform 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.

  • -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.

  • -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`).

GitHub - Jguer/yay: Yet another Yogurt - An AUR Helper written in Go

Yet another Yogurt - An AUR Helper written in Go. Contribute to Jguer/yay development by creating an account on GitHub.

GitHub
I like the idea of binding numbers to parent directory traversal. I do ca …/… 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.
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.
What… I didn’t know this was a thing.
you can just put “gimme-dat-new-new”

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.

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.

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

Feel free to call me a poser, a scrub, etc but I don’t use aliases (other than the default ones, that is).

Why? Two words:

Brain. Exercise.

Finger. Exercise.
I’ve got a “println” finger reflex now xD
I'm going to assume all these syntax highlighted HTML embeds are from Lemmy users. Sadly, illegible on Kbin.
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.

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'
alias cat lolcat
alias clear="clear; fastfetch"
alias sudo="doas"
alias clr="clear"
alias kx="killall Xwayland"
alias vpython="~/newVenv/bin/python"
alias vpip="~/newVenv/bin/pip"
I just use ^L instead of clear.

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

I’ve got aliases for every faltpak app I launch in the terminal for instance I’ve got code for vscodium or steam for well steam for example, I also alias some system commands so I have an update-grub, update, etc…

I also alias LSD to LS for obvious reasons.

When I switched to KDE and started using kate, but I used to have code as my vscodium alias as well.

A different way to do the usual ‘…’=“cd …” type of alias and filling half of your config with further version like :

bash/ksh version:

function .. { cd $(printf "../%.s" { 1..${1:-1} }) }

single-line zsh version:

.. () { cd $(printf "../%.s" {1..${1:-1}}) }

This takes the number of directories you want to move backwards as an argument. So doing or … 1 takes you back a single directory, … 2 takes you back two directories, etc.

`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’`

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’

I rawdog every single command, I use no aliases at all.

I couldn’t even work if I had aliases in my muscle memory. Imagine ssh’ing to a server and every second command you issue doesn’t exist because it’s some weird alias you set up for yourself.

I’ll stick with the “pure” command and use tab completion.

That’s also part of the reason why I don’t use some of the fancy new tools like ripgrep and exa.

Yeah, I remember when Linux was first becoming cool, in the mid-to-late 90s. There was a lot of folk wisdom going around, and one of them was “make an alias rm=‘rm -i’ so you don’t accidentally delete anything!”

And then there was the (correct, IMHO) counter-wisdom of “no, that actually makes it more likely to accidentally delete something, because one day you’re going to be on a machine where that alias doesn’t exist, but you’ve become dependent on it existing”.

I don’t mind creating aliases to add colour or change formatting a little bit or something, but don’t make an alias to keep yourself safe, because it’ll probably backfire on you.

You couldn’t even work if you made a few longer commonly used commands convenient aliases? Well alright.

I can’t imagine how you feel about bash scripts lol.

Not the person you responded to, but sure. Breaking muscle memory is extremely grating.

Also, it’s pretty easy to type long commands with little typing. If you use ctrl+r to search backward in your history, you can easily recall long commands - and also, you can use ctrl+x,ctrl+e to edit the current command line in $EDITOR so you can edit long commands. These two tricks make it very easy to type long commands quickly with very little typing.

it’s pretty easy to type long commands with little typing

Big if true

That’s why I use a shell script to connect to servers instead of just ssh.

The script connects via ssh and then sets a bunch of aliases and then leaves me at a bash prompt.

Servers may be reimaged, so I can’t just have things in a .bashrc or whatever.

A different way to do the usual …=“cd …” and endless chains of …=“cd …/…” aliases:

bash/ksh version:

..() { local count="${1:-1}" local path="../" while (( --count > 0 )); do path="$path../" done cd -- "$path" }

zsh single-line version:

..() { cd $(printf "../%.s" {1..${1:-1}}) }

This version takes the number of directories that you want to move up as an argument (e.g. … 3), otherwise it moves you up one directory when used with no arguments.

Thanks for sharing, likely will implement this!
There is a shell option for this (at least in zsh): setopt autocd. This allows you to change directories while omitting the cd in front
ccd() { mkdir "$1" &amp;&amp; cd "$1" }
I mainly use an alias to ssh into my server and another to stream lofi girl audio with mpv
Care to share the lofi mpv one? I use both lol
alias lofi='mpv --no-video www.youtube.com/watch?v=jfKfPfyJRdk
lofi hip hop radio 📚 beats to relax/study to

🎼 | Listen on Spotify, Apple music and more→ https://link.lofigirl.com/m/music🌎 | Lofi Girl on all social media→ https://link.lofigirl.com/m/Community🌐|...

YouTube