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.
I Alias “sudo !!” with “plz”
(Bash-Specific)
App-Specific
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 wttr="curl wttr.in/Chicago" # Get the weather of my city in the terminal
Terminal Navigation
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 reload="source ~/.bashrc" # Quickly refresh my system so that the latest alias file is loaded alias l='exa --group-directories-first -hlras modified --no-user --icons' # exa is a prettier version of ls. Options toggled: Human-readable, long format, reverse output, show hidden files/folders, sort by modified, hide the 'user' column since I'm the only one that uses the computer, and show the icons to make it look fancy```
Replaced Commands
alias cat='batcat --theme=ansi ' # Replace generic output of cat w/ a formatted version. This is bat (batcat in Debian) 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.
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”
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.
ETA: If you want it to be a persistent alias, though, you gotta add it to your .bashrc
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}' history=omz_history l='ls -lah' la='ls -lAh' ll='ls -lh' ls='exa --group-directories-first --color=auto -h -aa -l --git' lsa='ls -lah' md='mkdir -p' rd=rmdir run-help=man which-command=whence
Good to see another exa user. Care to break down what yay does btw?
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
.
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 clear="clear; fastfetch"
alias sudo="doas"
alias clr="clear"
alias kx="killall Xwayland"
alias vpython="~/newVenv/bin/python"
alias vpip="~/newVenv/bin/pip"
alias hgrep='function _f(){ history | grep $1; };_f'
Because I’m to lazy to type
history | grep whatever_I'm_looking_for
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 the entire prompt for restart and status to make it even shorter
For system updates:
[ -r /etc/os-release ] && . /etc/os-release case "$ID" in arch|archarm) if which paru > /dev/null 2>&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 && 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>&1 } if exists dnf; then #Fedora sudo dnf update && sudo dnf install -y $PACKAGE elif exists apt; then #Debian sudo apt update && sudo apt install -y $PACKAGE elif exists apk; then #Alpine apk -U upgrade && apk add $PACKAGE elif exists emerge; then #Gentoo sudo emerge $PACKAGE elif exists zypper; then #Suse sudo zypper ref && 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>&1 } if exists dnf; then #Fedora sudo dnf update && sudo dnf -y upgrade && sudo dnf -y autoremove elif exists apt; then #Debian sudo apt update && 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 && sudo emerge --ask --verbose --depclean elif exists zypper; then #Suse sudo zypper ref && sudo zypper update elif exists pacman; then #Arch pacman -Syu elif exists brew; then #MacOS brew update && 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 }
Very nice
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 }
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.
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 functionseparator_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_char» «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 « half_line_width; i++)) do echo -n ${separator_char} done echo -n ${contents_str} for ((i = 0; i < 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 [[«name_filter»] «extension»] «separator» «timestamp_field_number» read_latest_log () { # Check if the function has sufficient parameters if [[ $# -lt 2 ]]; then echo "Error: insufficient parameters." echo "Usage: read_latest_log [[«name_filter» = *] [«extension» = log] «separator» «timestamp_field_number»" return 1 fi # Supposing only two parameters are provided # «name_filter» parameter is "*" # «extension» 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 «name_filter» 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)" }
Sorry for all the edits, for some reason anything that looks like an HTML tag gets erased.
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.
Edit: Click the ‘more’ button on the comment and get the fediverse link to view the formatted post
alias cat lolcat
alias ccat whatever ohmyzsh does for their colorize extension, I know it’s a function aliasdeleted by creator