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 got so much crap gathered throughout the years... some of them I don't even use, but, here they are:
#!/usr/bin/zsh
# vi: ft=zsh
#############
# zsh aliases
#############
# grep
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias zgrep='zgrep --color=auto'
# processes
#alias pss='ps auxww | grep -v grep | grep' # show all processes with user, hide grep itself
alias top='top -i -e m -E m' # hide inactive and zombie processes, show ram in MB
# update system
alias p='sudo pacman'
alias pu='paru -Sua --noconfirm'
# clean up
alias pc='sudo pacman -Rsn $(pacman -Qdtq) --noconfirm 2>/dev/null; paru -Sccd --noconfirm'
# lvim
alias nvim='lvim'
alias vim='lvim'
alias vi='lvim'
alias v='lvim'
# cpg & mvg
alias cp='/usr/bin/cpg -ig'
alias mv='/usr/bin/mvg -ig'
# other useful ones
alias rm='trash'
alias duu='du -d 1 -h'
# wayland
alias gparted='sudo /bin/env WAYLAND_DISPLAY="$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY" XDG_RUNTIME_DIR=/user/run/0 /usr/sbin/gparted'
# edit configs
alias vcs="$EDITOR $XDG_CONFIG_HOME/starship/config.toml" # starship
alias vca="$EDITOR $XDG_CONFIG_HOME/alacritty/alacritty.yml" # alacritty
alias vct="$EDITOR $XDG_CONFIG_HOME/tmux/tmux.conf" # tmux
alias vcv="$EDITOR $XDG_CONFIG_HOME/nvim/init.vim" # neovim
alias vcl="$EDITOR $XDG_CONFIG_HOME/lvim/config.lua" # lunarvim
alias vch="$EDITOR $XDG_CONFIG_HOME/hypr/hyprland.conf" # hyprland
alias vcw="$EDITOR $XDG_CONFIG_HOME/waybar/config" # waybar
# edit & source zsh configs
alias scz="source $ZDOTDIR/.zshrc"
alias vcz="$EDITOR $ZDOTDIR/.zshrc && source $ZDOTDIR/.zshrc"
alias vczo="$EDITOR $ZDOTDIR/options && source $ZDOTDIR/options"
alias vczb="$EDITOR $ZDOTDIR/bindkeys && source $ZDOTDIR/bindkeys"
alias vcze="$EDITOR $ZDOTDIR/exports && source $ZDOTDIR/exports"
alias vcza="$EDITOR $ZDOTDIR/aliases && source $ZDOTDIR/aliases"
alias vczc="$EDITOR $ZDOTDIR/completions && source $ZDOTDIR/completions"
alias vczf="$EDITOR $ZDOTDIR/functions && source $ZDOTDIR/functions"
# other cool toys
alias exa='exa --long --header --git --sort=name --group-directories-first'
alias ls='exa'
alias cat='bat -pp'
alias bat='bat --style=full'
# x11
# alias X='startx ${XDG_CONFIG_HOME}/X11/xinitrc'
# alias XX='~/.screenlayout/home2.sh'
# alias kb='setxkbmap -rules evdev -model pc105 -layout "ro,de" -variant "basic" -option "grp:shift_caps_toggle"'
# tmux
alias tmux="tmux -f $XDG_CONFIG_HOME/tmux/tmux.conf"
alias t="tmux new-session -A -s id"
# dmenu stuff
# alias dnm='networkmanager_dmenu'
# alias dbt='dmenu-bluetooth'
# other cli utils
alias pm='pulsemixer'
# locations
alias lab='cd ~/priv/code/lab'
alias own='cd ~/priv/code/own'
alias pixl='aft-mtp-mount ~/priv/pixl'
# cleanup home
alias irssi="irssi --home ${XDG_CONFIG_HOME}/irssi"
alias svn="svn --config-dir ${XDG_CONFIG_HOME}/subversion"
alias wget="wget --hsts-file=$XDG_DATA_HOME/wget-hsts"
# dotfiles
alias stowe="sudo stow -d $HOME/.dotfiles/etc/ -t /etc/"
# ansible
alias ansible-vault='EDITOR=lvim ansible-vault'
# acme
alias acme='acme.sh --home "$XDG_CONFIG_HOME"/acme.sh/'
# vscode
alias code='vscodium --enable-features=UseOzonePlatform --ozone-platform=wayland'
# time sync
alias synctime='echo "time now:" && date && sudo systemctl stop ntpd && sudo ntpd -gq && sudo systemctl start ntpd && echo "new time:" && date'
# nordvpn
alias nvro='sudo systemctl start nordvpnd && nordvpn c ro && nordvpn whitelist add subnet 10.0.0.0/8 && nordvpn set dns 10.10.10.10'
alias nvdown='nordvpn d && sudo systemctl stop nordvpnd'
# work
alias vpnup='nmcli con up vpn-work --ask'
alias vpndown='nmcli con down vpn-work'
alias vpn='nmcli con down vpn-work; nmcli con up vpn-work --ask'
alias vault-connect='source $HOME/work/secrets/vault.work'
alias terraform-connect='source $HOME/work/secrets/terraform.work'
alias teamsx='killall -15 teams'
alias adm='sudo mount /home/$HOME/work/adm'
alias mongo='ssh -L \*:27777:appserver:27017 jumphost'
alias ls='ls --time-style=long-iso'
alias la='ls -alh'
alias ncdu='ncdu --color=off'
alias wttr='curl wttr.in/?T0'
alias vim='vimx'
alias ipinfo='curl ipinfo.io --no-progress-meter | jq "del(.readme)"'
alias pp="pkill -SIGSTOP -f "
alias pc="pkill -SIGCONT -f "
alias la='ls -a'
alias mplayer='mplayer -noautosub -alang en'
alias ll='ls $LS_OPTIONS -lh'
alias l='ls $LS_OPTIONS -lAa'
alias x='startx'
alias ekgi='ekg -i'
alias glinks='links2 -g'
My god, this must be in my .bashrc since forever. I mean... links2? ekg? startx? It's like archeology.
A different way to do the usual ..="cd .." and endless chains of ...="cd ../.." types of 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}}) }
These take the number of directories that you want to move up as an argument (e.g. .. 3),
otherwise they move you up one directory when used with no arguments.
alias a='alias'
a c='clear'
a p='pwd'
a e='exit'
a q='exit'
a h='history | tail -n20'
# turn off history, use 'set -o history' to turn it on again
a so='set +o history'
a b1='cd ../'
a b2='cd ../../'
a b3='cd ../../../'
a b4='cd ../../../../'
a b5='cd ../../../../../'
a ls='ls --color=auto'
a l='ls -ltrhG'
a la='l -A'
a vi='gvim'
a grep='grep --color=auto'
# open and source aliases
a oa='vi ~/.bash_aliases'
a sa='source ~/.bash_aliases'
# sort file/directory sizes in current directory in human readable format
a s='du -sh -- * | sort -h'
# save last command from history to a file
# tip, add a comment to end of command before saving, ex: ls --color=auto # colored ls output
a sl='fc -ln -1 | sed "s/^\s*//" >> ~/.saved_commands.txt'
# short-cut to grep that file
a slg='< ~/.saved_commands.txt grep'
# change ascii alphabets to unicode bold characters
a ascii2bold="perl -Mopen=locale -Mutf8 -pe 'tr/a-zA-Z/𝗮-𝘇𝗔-𝗭/'"
### functions
# 'command help' for command name and single option - ex: ch ls -A
# see https://github.com/learnbyexample/command_help for a better script version
ch() { whatis $1; man $1 | sed -n "/^\s*$2/,/^$/p" ; }
# add path to filename(s)
# usage: ap file1 file2 etc
ap() { for f in "$@"; do echo "$PWD/$f"; done; }
# simple case-insensitive file search based on name
# usage: fs name
# remove '-type f' if you want to match directories as well
fs() { find -type f -iname '*'"$1"'*' ; }
# open files with default application, don't print output/error messages
# useful for opening docs, pdfs, images, etc from command line
o() { xdg-open "$@" &> /dev/null ; }
# if unix2dos and dos2unix commands aren't available by default
unix2dos() { sed -i 's/$/\r/' "$@" ; }
dos2unix() { sed -i 's/\r$//' "$@" ; }
alias search='apt search'
alias file='apt-file search'
alias policy='apt policy'
alias show="nala show"
if user is not root, pass all commands via sudo
if [ $UID -ne 0 ]; then
alias update='sudo apt update'
alias ainstall='sudo apt install'
alias apurge='sudo apt purge -y --autoremove'
alias upgrade='sudo nala upgrade'
alias aremove='sudo apt autoremove -y'
alias clean='sudo nala clean'
alias reboot='sudo reboot'
alias shutdown="sudo shutdown -P now"
fi
Handy-dandy aliases for journalctl and systemctl
alias jc='sudo journalctl -b'
alias jca='sudo journalctl'
alias jcf='sudo journalctl -f'
alias jcr='sudo journalctl --list-boots'
alias sc='sudo systemctl'
Making files immortal & executable
alias im+="sudo chattr +i"
alias im-="sudo chattr -i"
alias exe="sudo chmod +x"
#Add safety nets
do not delete / or prompt if deleting more than 3 files at a time
alias rm='rm -I --preserve-root'
confirmation
alias mv='mv -i'
alias cp='cp -i'
alias ln='ln -i'
Parenting changing perms on /
alias chown='chown --preserve-root'
alias chmod='chmod --preserve-root'
alias chgrp='chgrp --preserve-root'
copy the current working directory to the clipboard
alias cpwd='pwd | xclip -selection clipboard'
Clipboard
alias cpy="xclip -selection clipboard"
quick directory movement
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
go to the last directory you were in
alias back='cd $OLDPWD'
quickly find files and directory
alias ff='find . -type f -name'
alias fd='find . -type d -name'
Create Python virtual environment
alias ve='python3 -m venv ./venv'
alias va='source ./venv/bin/activate'
Ping Commands
Stop after sending count ECHO_REQUEST packets
alias ping='ping -c 5'
alias pg="ping google.com -c 5"
alias shortcuts
alias rpi="sudo rpi-update"
alias rpi-next="sudo BRANCH=next rpi-update"
alias raspi="sudo raspi-config"
alias clr="clear"
alias clrh="history -c -w ~/.bash_history"
alias df='df -H'
alias du='du -ch'
alias mk="mkdir -p"
alias loading="sudo dmesg > ~/dmesg.txt"
ls Commands
Colorize the ls output and human readable sizes
alias ls='ls --color=auto --human-readable -al'
Use a long listing format
alias ll='ls -la'
Show hidden files
alias l.='ls -d .* --color=auto'
Listing files in folder
alias listkb="ls -l --block-size=K"
alias listmb="ls -l --block-size=M"
Colorize the grep command output for ease of use (good for log files)##
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
Colorize diff output
alias diff='colordiff'
Start calculator with math support
alias bc="bc -l"
Resume wget by default
alias wget="wget -c"
ps Commands
alias ps="ps auxf"
Get top process eating cpu
alias pscpu="ps auxf | sort -nr -k 3"
alias pscpu10="ps auxf | sort -nr -k 3 | head -10"
Get top process eating memory
alias psmem='ps auxf | sort -nr -k 4'
alias psmem10='ps auxf | sort -nr -k 4 | head -10'
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
alias clear="clear; fastfetch" alias sudo="doas" alias clr="clear" alias kx="killall Xwayland" alias vpython="~/newVenv/bin/python" alias vpip="~/newVenv/bin/pip"
Don't really organize my aliases after making them, so this might be a mess.
##################
# ~/.aliases #
##################
# Colours
alias color-GREEN='tput setaf 2'
alias color-RED='tput setaf 1'
alias color-CYAN='tput setaf 78'
alias color-PURPLE='tput setaf 128'
#alias color-BLUE='tput setaf 4'
alias color-RESET='tput sgr0'
alias color-LIGHT_PURPLE='tput setaf 5'
alias color-LIGHT_BLUE='tput setaf 12'
alias color-TEXT='tput setaf 15'
alias color-HIDDEN='tput setaf 236'
# don't set a shutdown timer
alias shutdown='shutdown now'
# grep
alias grep='grep --color=auto'
alias pgrep='pgrep -l'
# package manager
alias pacman='sudo pacman --color=auto'
alias paru='paru --color=auto'
# ls
alias ls='eza -aMF --hyperlink --group-directories-first --icons --color=auto'
alias ll='eza -alhMF@ --hyperlink --group-directories-first --icons --color=auto --color-scale'
alias lg='eza -alhMF@ --hyperlink --group-directories-first --icons --git --git-repos --git-ignore --color=auto --color-scale'
# confirm before overwriting
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
# update grub.cfg
alias grub-update='sudo grub-mkconfig -o /boot/grub/grub.cfg'
# update function
u() {
# update distro specific packages
if command -v pacman &> /dev/null
then
# update pacman packages
printf "\n[Update] Updating Standard Packages:\n\n"
sudo pacman -Syu --color=auto
# update aur packages
if command -v paru &> /dev/null
then
printf "\n[Uodate] Updating AUR Packages:\n\n"
paru -Sau --color=auto
fi
elif command -v apt &> /dev/null
then
# update apt packages
printf "\n[Update] Updating Standard Packages:\n\n"
sudo apt-get update
sudo apt-get upgrade
fi
# update flatpaks
if command -v flatpak &> /dev/null
then
printf "\n[Update] Updating flatpaks:\n\n"
flatpak update
fi
# todo:
# - update grub
# - source shell config
printf "\n[Update] Done\n"
}
# view metadata
alias meta='exiftool'
# makepkg dependencies and install
alias makepkg='makepkg -si'
# git
alias gc='git clone'
# quick probe
alias probe='sudo -E hw-probe -all -upload -show -verbose'
# shorten pacman commands
alias pm='pacman'
alias pms='pm -Syu'
alias pmr='pm -Rns'
alias pmq='pm -Q'
alias pmu='pm -U'
alias pmd='sudo downgrade'
alias pmc='sudo paccache'
# rm pacman lock
alias rmpml='sudo rm /var/lib/pacman/db.lck'
# quick access to configs
alias brc='$EDITOR ~/.bashrc'
alias bash='exec bash'
alias zrc='$EDITOR ~/.zshrc'
alias zsh='exec zsh'
alias alia='$EDITOR ~/.aliases'
alias expo='$EDITOR ~/.exports'
alias swayc='$EDITOR ~/.config/sway/config'
#alias alac-conf='$EDITOR ~/.config/alacritty/alacritty.yml'
alias starc='$EDITOR ~/.config/starship.toml'
alias kittc='$EDITOR ~/.config/kitty/kitty.conf'
alias nvimc='$EDITOR ~/.config/nvim/init.vim'
# alias fetch scripts with hyfetch during pride month
[[ $(date +'%b') == "Jun" ]] && alias neofetch='hyfetch -b neofetch'
[[ $(date +'%b') == "Jun" ]] && alias fastfetch='hyfetch -b fastfetch'
# use fastfetch backend for hyfetch
alias hyfetch='hyfetch -b fastfetch'
# add sudo
alias docker='sudo docker'
alias systemctl='sudo systemctl'
# systemd
alias sc='systemctl'
alias sce='sc enable'
alias scd='sc disable'
alias scs='sc start'
alias scu='sc stop' # the u comes from unset
alias scr='sc restart'
# yt-dlp
alias ytm='yt-dlp -x -o "~/Music/%(title)s.%(ext)s" --add-metadata --embed-thumbnail --audio-quality 0'
alias ytv='yt-dlp -o "~/Videos/%(title)s.%(ext)s" --add-metadata --embed-thumbnail --embed-subs --embed-chapters'
# edit quicker
alias e='$EDITOR'
alias se='sudoedit'
# ryujinx (created by pinejinx)
alias ryu="AMD_DEBUG=w32ge,w32cs,nohyperz,nofmask glsl_zero_init=true radeonsi_clamp_div_by_zero=true force_integer_tex_nearest=true mesa_glthread=false vblank_mode=0 RADV_PERFTEST=bolist gamemoderun DOTNET_EnableAlternateStackCheck=1 GDK_BACKEND=x11 /home/luna/.local/share/Ryujinx/Ryujinx"
# Vencord
alias inven="sudo VencordInstallerCli-linux -install && sudo VencordInstallerCli-linux -install-openasar"
alias unven="sudo VencordInstallerCli-linux -uninstall && sudo VencordInstallerCli-linux -uninstall-openasar"
# bun > npm
alias npm='bun'
# replace cat
alias cat='bat'
# sudo
alias s='sudo'
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...
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_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.
[ -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
(NOTE: A lot of my more interesting "aliases" are actually short functions, but I'm keeping myself to alias.)
Some of mine that I haven't seen yet:
# Simple python calculator
alias pycalc='python3 -ic "
from math import *\nimport cmath as C
try:
import numpy as np
except:
pass
i, j = 1j, 1j
"'
# Defaults
alias cp='cp --interactive --reflink=auto'
alias gcc='gcc -fdiagnostics-color=auto'
# Lemmy doesn't handle ampersands in codeblocks correctly
alias rg='rg --max-columns=$((COLUMNS > 60 && ! ZSH_SUBSHELL ? COLUMNS - 30 : 0))'
alias rj='rg --json'
alias rm='rm -s'
alias rscp='rsync -azP --human-readable --info=flist0,progress2,stats1'
alias rust-c='rustc --out-dir build -O'
# Shorter forms
alias g=git
alias v=$VISUAL
alias py=python
alias jfeu='journalctl --user -xfeu'
alias sys='systemctl --user'
alias Jfeu='journalctl -xfeu'
alias Sys=systemctl
# Desktop stuff
alias trash='gio trash'
alias ud=udisksctl
alias y=wl-copy
alias Y='wl-copy -p'
alias p=wl-paste
alias P='wl-paste -p'
# Colorize with acolor/grc
alias GRC='grc -es'
alias LA='acol ls -lFAhb --color'
alias LS='acol ls -lFhb --color'
alias df='GRC df -hT'
alias dig='GRC dig'
alias docker='GRC docker'
alias docker-machine='GRC docker-machine'
alias env='acol env'
alias lsblk='acol lsblk'
alias lsmount='command mount | rg --color=never "^/" | acol -i -o mount'
alias lspci='acol lspci'
alias mount='acol mount'
alias nmap='acol nmap'
alias ping='GRC ping'
alias ps='GRC ps --columns $COLUMNS'
alias traceroute='GRC traceroute'
I don't like having to renavigate to my project directory in a new terminal:
alias clone='(pwd | urxvt & disown $!)'
Takes my current directory and opens it in my terminal. Then it disowns that new terminal process, so if I close the current terminal the new one doesnt disappear with it.