Zsh

Welcome to my Zshrc. This configuration does not use any package managers or frameworks. This literate configuration is available online on my GitHub Pages. If you appreciate my work, please consider making a donation.

Table of Contents

Theme

This first block of code sets the $PATH environment variable, and sources my $LS_COLORS script from this project. I have a cross-compiler installed, and that’s what those other variables are for.

#              __
#  ____  _____/ /_  __________
# /_  / / ___/ __ \/ ___/ ___/
#  / /_(__  ) / / / /  / /__
# /___/____/_/ /_/_/   \___/

export PATH=/sbin:$HOME/bin:$HOME/.emacs.d/bin:/usr/local/bin:$HOME/.local/bin:$HOME/.cargo/bin:/usr/local/go/bin:/usr/local/i386elfgcc/bin:$HOME/.zsh/forgit/bin:$PATH

export PREFIX="/usr/local/i386elfgcc"
export TARGET=i386-elf
export VOIDPKG="/home/babkock/git/void-packages"

source "$HOME/.ssh/zsh/secrets.zsh"
VIVID_THEME="alabaster_dark"

#LSCOLORS=$LS_COLORS
#ZLS_COLORS=$LS_COLORS
if [ -v $TERM ]; then
    if [[ ${TERM} = "st-256color" || ${TERM} = "rxvt-unicode" || ${TERM} = "xterm-256color" || ${TERM} = "foot" || ${TERM} = "kitty" || ${TERM} = "alacritty" ]]; then
        export LS_COLORS="$(vivid generate $VIVID_THEME)"
    else
        export LS_COLORS="$(vivid -m 8-bit generate $VIVID_THEME)"
    fi
else
    export LS_COLORS="$(vivid -m 8-bit generate $VIVID_THEME)"
fi

export LSCOLORS=$LS_COLORS
ZLS_COLORS=$LS_COLORS

Completion Styles

These are my styles for the various TAB-completion menus that appear in ZSH themes.

zstyle ':completion:*:*:kill:*' list-colors '=(#b) #([0-9]#)*( *[a-z])*=34=31=33'
zstyle ':completion:*' use-cache on
zstyle ':completion:' cache-path "$HOME/.cache/zsh/.zcompcache"
zstyle ':completion:*:parameters' list-colors '=*=1;35'
zstyle ':completion:*:builtins' list-colors '=*=1;34'
zstyle ':completion:*:aliases' list-colors '=*=1;33'
zstyle ':completion:*:*:*:*:descriptions' format '%F{yellow}%d %f'
zstyle ':completion:*:warnings' format ' %F{red}no matches found %f'
zstyle ':completion:*:options' list-colors '=^(-- *)=34'
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} "ma=4;37"
zstyle ':completion:*:*:-command-:*:*' group-order alias functions builtins commands
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'

Preferences

Set some preferences. Auto CD, and no duplicates in history.

export LANG=en_US.UTF-8

source <(fzf --zsh)
setopt autocd
setopt appendhistory
setopt hist_ignore_all_dups
setopt hist_save_no_dups
setopt hist_find_no_dups
setopt hist_ignore_dups

Conditional Aliases

Determine if the shell is being loaded locally, or over SSH, and set aliases accordingly. The reason I do this is so I don’t strain the SSH connection with too many colors or icons. The shell should behave and feel differently.

SSH

# Preferred editor for local and remote sessions
if [[ -n $SSH_CONNECTION ]]; then
    alias d="fd"
    alias c="/usr/bin/cat"
    alias cat="/usr/bin/cat"
    alias grep="/usr/bin/grep --color=auto"
    alias g="/usr/bin/grep --color=auto"
    alias gh="/usr/bin/grep --color=auto --context=4"
    alias xx="echo Can not reboot from SSH > /dev/stderr"
    alias reboot="echo Can not reboot from SSH > /dev/stderr"
    alias shutdown="echo Can not shutdown from SSH > /dev/stderr"
else
    alias c="bat"
    alias cat="bat"
    alias d="fd"
    alias grep="ug"
    alias g="ug"
    alias gh="ug --context=4"
    alias reboot="loginctl reboot"
    alias shutdown="sudo /usr/bin/shutdown -h now"
    alias xx="loginctl reboot"

Login Shell Functions

    # functions only for login shells
    if [[ "$TERM" == "linux" ]]; then
        function shy() {
            export GTK_THEME="Vimix-dark-ruby"
            export GDK_BACKEND="wayland"
            export SDL_VIDEODRIVER="wayland"
            export XDG_CURRENT_DESKTOP="Hyprland"
            export XDG_SESSION_DESKTOP="Hyprland"
            export XDG_SESSION_TYPE="wayland"
            export QT_QPA_PLATFORM="wayland-egl"
            export QT_QPA_PLATFORMTHEME="qt6ct"
            export QT_WAYLAND_DISABLE_WINDOWDECORATION=1
            export XCURSOR_THEME="Adwaita"
            export XCURSOR_SIZE=32
            export MOZ_ENABLE_WAYLAND=1
            export MOZ_WEBRENDER=1
            export WLR_DRM_NO_MODIFIERS=1
            export AQ_DRM_DEVICES="/dev/dri/card0:/dev/dri/renderD128"
            pgrep mpdas | xargs kill 2> /dev/null
            pgrep pipewire | xargs kill 2> /dev/null
            pgrep pulseaudio | xargs kill 2> /dev/null
            echo "Starting Hyprland..."
            gsettings set org.gnome.desktop.interface color-scheme prefer-dark
            gsettings set org.gnome.desktop.interface gtk-theme Vimix-dark-ruby
            gsettings set org.gnome.desktop.interface cursor-theme Adwaita
            gsettings set org.gnome.desktop.interface cursor-size 32
            dbus-launch --exit-with-session Hyprland &> /dev/null
            pgrep hypridle | xargs kill 2> /dev/null
            pgrep stash | xargs kill 2> /dev/null
            pgrep mako | xargs kill 2> /dev/null
            pgrep emacs | xargs kill 2> /dev/null
            pgrep hydroxide | xargs kill 2> /dev/null
            pkill -x hydroxide
            pgrep mpdas | xargs kill 2> /dev/null
            pkill -x mpdas
            true
        }
        function swa() {
            export GTK_THEME="Vimix-dark-ruby"
            export GDK_BACKEND="wayland"
            export SDL_VIDEODRIVER="wayland"
            export XDG_CURRENT_DESKTOP="sway"
            export XDG_SESSION_DESKTOP="sway"
            export XDG_SESSION_TYPE="wayland"
            export QT_QPA_PLATFORM="wayland-egl"
            export QT_QPA_PLATFORMTHEME="qt6ct"
            export QT_WAYLAND_DISABLE_WINDOWDECORATION=1
            export XCURSOR_THEME="Adwaita"
            export XCURSOR_SIZE=32
            export MOZ_ENABLE_WAYLAND=1
            export MOZ_WEBRENDER=1
            pgrep mpdas | xargs kill 2> /dev/null
            pgrep pipewire | xargs kill 2> /dev/null
            pgrep pulseaudio | xargs kill 2> /dev/null
            echo "Starting Sway..."
            gsettings set org.gnome.desktop.interface color-scheme prefer-dark &> /dev/null
            gsettings set org.gnome.desktop.interface gtk-theme Vimix-dark-ruby &> /dev/null
            gsettings set org.gnome.desktop.interface cursor-theme Adwaita &> /dev/null
            gsettings set org.gnome.desktop.interface cursor-size 32 &> /dev/null
            dbus-launch --exit-with-session sway &> /dev/null
            pkill -x eww
            pgrep emacs | xargs kill 2> /dev/null
            pgrep stash | xargs kill 2> /dev/null
            pgrep hydroxide | xargs kill 2> /dev/null
            pkill -x hydroxide
            pgrep mpdas | xargs kill 2> /dev/null
            pkill -x mpdas
            true
        }
        function swf() {
            export GTK_THEME="Vimix-dark-ruby"
            export GDK_BACKEND="wayland"
            export SDL_VIDEODRIVER="wayland"
            export XDG_CURRENT_DESKTOP="sway"
            export XDG_SESSION_DESKTOP="sway"
            export XDG_SESSION_TYPE="wayland"
            export QT_QPA_PLATFORM="wayland-egl"
            export QT_QPA_PLATFORMTHEME="qt6ct"
            export QT_WAYLAND_DISABLE_WINDOWDECORATION=1
            export XCURSOR_THEME="Adwaita"
            export XCURSOR_SIZE=32
            export MOZ_ENABLE_WAYLAND=1
            export MOZ_WEBRENDER=1
            pgrep mpdas | xargs kill 2> /dev/null
            pgrep pipewire | xargs kill 2> /dev/null
            pgrep pulseaudio | xargs kill 2> /dev/null
            echo "Starting Wayfire..."
            gsettings set org.gnome.desktop.interface color-scheme prefer-dark &> /dev/null
            gsettings set org.gnome.desktop.interface gtk-theme Vimix-dark-ruby &> /dev/null
            gsettings set org.gnome.desktop.interface cursor-theme Adwaita &> /dev/null
            gsettings set org.gnome.desktop.interface cursor-size 32 &> /dev/null
            dbus-launch --exit-with-session wayfire &> /dev/null
            pkill -x eww
            pgrep emacs | xargs kill 2> /dev/null
            pgrep stash | xargs kill 2> /dev/null
            pgrep hydroxide | xargs kill 2> /dev/null
            pkill -x hydroxide
            pgrep mpdas | xargs kill 2> /dev/null
            pkill -x mpdas
            true
        }
        function sri() {
            export GTK_THEME="Vimix-dark-ruby"
            export GDK_BACKEND="wayland"
            export SDL_VIDEODRIVER="wayland"
            export XDG_CURRENT_DESKTOP="sway"
            export XDG_SESSION_DESKTOP="sway"
            export XDG_SESSION_TYPE="wayland"
            export QT_QPA_PLATFORM="wayland-egl"
            export QT_QPA_PLATFORMTHEME="qt6ct"
            export QT_WAYLAND_DISABLE_WINDOWDECORATION=1
            export XCURSOR_THEME="Adwaita"
            export XCURSOR_SIZE=32
            export MOZ_ENABLE_WAYLAND=1
            export MOZ_WEBRENDER=1
            pgrep mpdas | xargs kill 2> /dev/null
            pgrep pipewire | xargs kill 2> /dev/null
            pgrep pulseaudio | xargs kill 2> /dev/null
            echo "Starting River..."
            gsettings set org.gnome.desktop.interface color-scheme prefer-dark &> /dev/null
            gsettings set org.gnome.desktop.interface gtk-theme Vimix-dark-ruby
            gsettings set org.gnome.desktop.interface cursor-theme Adwaita &> /dev/null
            gsettings set org.gnome.desktop.interface cursor-size 32 &> /dev/null
            dbus-launch --exit-with-session river &> /dev/null
            pkill -x eww
            pgrep emacs | xargs kill 2> /dev/null
            pgrep stash | xargs kill 2> /dev/null
            pgrep hydroxide | xargs kill 2> /dev/null
            pkill -x hydroxide
            pgrep mpdas | xargs kill 2> /dev/null
            true
        }
    fi
fi

Terminal

Here is where I check if the Zsh shell is being loaded in a graphical terminal, or an actual tty. If I change my terminal away from st, then I will have to modify this part. Nerd Font icons do not render in the tty, so we should use the standard versions of fancy programs in that context.

All of these ls commands have flags to show directories first, show human-readable file sizes, and show file symbols. All of the exa commands show icons and group directories first, also.

Command In Terminal In TTY
ls Regular Eza listing Regular LS listing
l Regular Eza listing Regular LS listing
la Long listing with total directory sizes, all files LS long listing, all files
ll Eza Long listing with total sizes, all files LS long listing, all files
lc Eza Long listing with total sizes N/A
lct Eza Long listing with total sizes and tree N/A
lctl Eza Long listing with total sizes and tree N/A
lsl Long listing, all files LS long listing, all files
lsa Long listing, all files LS long listing, all files
lsla Long listing with total sizes, all files LS long listing, all files
lst Eza listing with tree N/A
lstl Eza long listing with tree N/A
ltl Eza long listing with total sizes and tree N/A
a Run YT-DLP on the given URL N/A
al Eza long listing, all files Same, without icons
e Opens new Emacs window Opens Emacs in Console
ez Edit zsh.org in new Emacs window Edit zsh.org in Console
eb Edit bspwm.org in new Emacs window Edit bspwm.org in Console
ep Edit Polybar config in new Emacs window Edit Polybar in Console
eq Edit Qutebrowser config in new Emacs window Edit Qutebrowser in Console
ec Edit init.org in new Emacs window Edit init.org in Console
ed Edit config.org in new Emacs window Edit config.org in Console
ew Edit Waybar config in new Emacs window Edit Waybar in Console
es Edit Waybar style.org in new Emacs window Edit style.org in Console
ef Edit foot.org in new Emacs window Edit foot.org in Console
egp Run Magit Push on repository inside Emacs Run Magit Push in Console
egs Run Magit Status on repository inside Emacs Run Magit Status in Console
ei Run Magit Log on repository inside Emacs Run Magit Log in Console
egl Run Magit Log on repository inside Emacs Run Magit Log in Console
ee Open current directory in Dired in Emacs Open current directory in Console
er Open Elfeed in Emacs N/A
j Open NNN file browser N/A
me Open webcam image in MPV in Wayland N/A
mx Open webcam image in MPV in X.org N/A
if [ -v TERM ]; then
    if [[ ${TERM} = "st-256color" || ${TERM} = "rxvt-unicode" || ${TERM} = "xterm-256color" || ${TERM} = "foot" || ${TERM} = "alacritty" || ${TERM} = "kitty" ]]; then
        # graphical terminal
        alias ls="eza --icons --group-directories-first --no-quotes -X -F"
        alias l="eza --icons --group-directories-first --no-quotes -X -F"
        alias lsla="eza --icons --group-directories-first --no-quotes -X -F -l -A --git --git-repos --time-style=relative -S"
        alias la="eza --icons --group-directories-first --no-quotes -X -F -A"
        alias ll="eza --icons --group-directories-first --no-quotes -X -F -l --git --git-repos --time-style=relative -S"
        alias lsl="eza --icons --group-directories-first --no-quotes -X -F -l --git --git-repos --time-style=relative -S"
        alias lsa="eza --icons --group-directories-first --no-quotes -X -F -l -A --git --git-repos --time-style=relative -S"
        alias lst="eza --icons --group-directories-first --no-quotes -X -F -l -A --git --git-repos --time-style=relative -S -T --level 3"
        alias lstl="eza --icons --group-directories-first --no-quotes -X -F -l -A --git --git-repos --time-style=relative -S -T --level 3"
        alias ltl="eza --icons --group-directories-first --no-quotes -X -F -l -A --git --git-repos --time-style=relative -S -T --level 3"
        alias lc="eza --icons --group-directories-first --no-quotes -X -F -l -A --total-size --git --git-repos --time-style=relative -S"
        alias lct="eza --icons --group-directories-first --no-quotes -X -F -l -A --total-size --git --git-repos --time-style=relative -S -T --level 3"
        alias lctl="eza --icons --group-directories-first --no-quotes -X -F -l -A --total-size --git --git-repos --time-style=relative -S -T --level 3"
        alias a="yt-dlp --remux-video 'mkv' --embed-metadata --embed-chapters --sleep-requests 3 --limit-rate 9M --exec '/home/babkock/bin/ytdone'"
        alias al="eza --icons --group-directories-first --no-quotes -X -F -l --git --git-repos --time-style=relative -S"
        alias e="swaymsg \"workspace 4\" 2> /dev/null; hyprctl dispatch workspace 4 &> /dev/null; emacsclient -c -a 'emacs' -q"
        alias ee="swaymsg \"workspace 4\" 2> /dev/null; hyprctl dispatch workspace 4 &> /dev/null; emacsclient -c -a 'emacs' -q -r . &"
        alias ea="swaymsg \"workspace 4\" 2> /dev/null; hyprctl dispatch workspace 4 &> /dev/null; emacsclient -c -a 'emacs' -q -r \"$HOME/.config/alacritty/config.org\" &"
        alias ez="swaymsg \"workspace 4\" 2> /dev/null; hyprctl dispatch workspace 4 &> /dev/null; emacsclient -c -a 'emacs' -q -r \"$HOME/.zsh.org\" &"
        #alias eb="hyprctl dispatch workspace 4 2> /dev/null; swaymsg \"workspace 4\" 2> /dev/null; emacsclient -c -a 'emacs' -q -r \"$HOME/.config/bspwm/bspwm.org\" &"
        #alias ep="hyprctl dispatch workspace 4 2> /dev/null; swaymsg \"workspace 4\" 2> /dev/null; emacsclient -c -a 'emacs' -q -r \"$HOME/.config/polybar/config.org\" &"
        alias eq="swaymsg \"workspace 4\" 2> /dev/null; hyprctl dispatch workspace 4 &> /dev/null; emacsclient -c -a 'emacs' -q -r \"$HOME/.config/qutebrowser/config.org\" &"
        alias ec="swaymsg \"workspace 4\" 2> /dev/null; hyprctl dispatch workspace 4 &> /dev/null; emacsclient -c -a 'emacs' -q -r \"$HOME/.doom.d/init.org\" &"
        alias ed="swaymsg \"workspace 4\" 2> /dev/null; hyprctl dispatch workspace 4 &> /dev/null; emacsclient -c -a 'emacs' -q -r \"$HOME/.doom.d/config.org\" &"
        alias ew="swaymsg \"workspace 4\" 2> /dev/null; hyprctl dispatch workspace 4 &> /dev/null; emacsclient -c -a 'emacs' -q -r \"$HOME/.config/waybar/config.org\" &"
        alias es="swaymsg \"workspace 4\" 2> /dev/null; hyprctl dispatch workspace 4 &> /dev/null; emacsclient -c -a 'emacs' -q -r \"$HOME/.config/waybar/style.org\" &"
        alias ef="swaymsg \"workspace 4\" 2> /dev/null; hyprctl dispatch workspace 4 &> /dev/null; emacsclient -c -a 'emacs' -q -r \"$HOME/.config/foot/foot.org\" &"
        alias egp="swaymsg \"workspace 4\" 2> /dev/null; hyprctl dispatch workspace 4 &> /dev/null; emacsclient -c -a 'emacs' -q -r --eval \"(magit-push)\" > /dev/null &"
        alias egs="swaymsg \"workspace 4\" 2> /dev/null; hyprctl dispatch workspace 4 &> /dev/null; emacsclient -c -a 'emacs' -q -r --eval \"(magit-status)\" > /dev/null &"
        alias ei="swaymsg \"workspace 4\" 2> /dev/null; hyprctl dispatch workspace 4 &> /dev/null; emacsclient -c -a 'emacs' -q -r --eval \"(magit-log-all)\" > /dev/null &"
        alias egl="swaymsg \"workspace 4\" 2> /dev/null; hyprctl dispatch workspace 4 &> /dev/null; emacsclient -c -a 'emacs' -q -r --eval \"(magit-log-all)\" > /dev/null &"
        alias er="swaymsg \"workspace 4\" 2> /dev/null; hyprctl dispatch workspace 4 &> /dev/null; emacsclient -c -a 'emacs' -q -r --eval \"(elfeed)\" > /dev/null &"
        alias eo="swaymsg \"workspace 4\" 2> /dev/null; hyprctl dispatch workspace 4 &> /dev/null; emacsclient -c -a 'emacs' -q -r \"$HOME/.config/eww/eww.org\" &"
        alias mx="mpv av://v4l2:/dev/video0 --vo=gpu --hwdec=vaapi --untimed --profile=low-latency --no-osc --ontop --cache=no"
        alias mo="mpv av://v4l2:/dev/video2 --vo=gpu --hwdec=vaapi --untimed --profile=low-latency --no-osc --ontop --cache=no"
        alias me="mpv av://v4l2:/dev/video2 --untimed --profile=low-latency --no-osc --ontop --cache=no --demuxer-lavf-format=video4linux2 --demuxer-lavf-o=video_size=960x720,input_format=mjpeg,framerate=30 --window-scale=0.5"
        alias mj="mpv av://v4l2:/dev/video0 --untimed --profile=low-latency --no-osc --ontop --cache=no --demuxer-lavf-format=video4linux2 --demuxer-lavf-o=video_size=1920x1080,input_format=mjpeg,framerate=30 --window-scale=0.55"
        alias jt="tmux new-session \"export NNN_FIFO=/tmp/nnn.fifo; export NNN_PLUG='p:preview-tui'; nnn -d -i -l 2 -H -G -U -R -Q -D -P preview-tui\""
#    elif [[ ${TERM} = "screen-256color" ]]; then
        # tmux
#        alias j="nnn -d -i -l 2 -H -G -U -R -Q -D -P preview-tui & ~/.config/nnn/plugins/preview-tui; fg"
    else
        # login shell or SSH
        alias ls="ls --group-directories-first -F --color=auto"
        alias lsla="ls -l -A -h --group-directories-first -F --color=auto"
        alias l="ls --group-directories-first -F --color=auto"
        alias lsl="ls -l -A -h --group-directories-first -F --color=auto"
        alias la="ls -l -A -h --group-directories-first -F --color=auto"
        alias ll="ls -l -A -h --group-directories-first -F --color=auto"
        alias e="emacsclient -c -a 'emacs' -nw"
        alias ee="emacsclient -c -a 'emacs' -nw ."
        alias ez="emacsclient -c -a 'emacs' -nw \"$HOME/.zsh.org\""
        alias eb="emacsclient -c -a 'emacs' -nw \"$HOME/.config/bspwm/bspwm.org\""
        alias ep="emacsclient -c -a 'emacs' -nw \"$HOME/.config/polybar/config.org\""
        alias eq="emacsclient -c -a 'emacs' -nw \"$HOME/.config/qutebrowser/config.org\""
        alias ec="emacsclient -c -a 'emacs' -nw \"$HOME/.doom.d/init.org\""
        alias ed="emacsclient -c -a 'emacs' -nw \"$HOME/.doom.d/config.org\""
        alias ew="emacsclient -c -a 'emacs' -nw \"$HOME/.config/waybar/config.org\""
        alias es="emacsclient -c -a 'emacs' -nw \"$HOME/.config/waybar/style.org\""
        alias ef="emacsclient -c -a 'emacs' -nw \"$HOME/.config/foot/foot.org\""
        alias ea="emacsclient -c -a 'emacs' -nw \"$HOME/.config/alacritty/config.org\""
        alias eo="emacsclient -c -a 'emacs' -nw \"$HOME/.config/eww/eww.org\""
        alias egp="emacsclient -c -a 'emacs' -nw --eval \"(magit-push)\""
        alias egs="emacsclient -c -a 'emacs' -nw --eval \"(magit-status)\""
        alias ei="emacsclient -c -a 'emacs' -nw --eval \"(magit-log-all)\""
        alias egl="emacsclient -c -a 'emacs' -nw --eval \"(magit-log-all)\""
    fi
fi

Functions

tbef

“TBcom Edit Film”

function tbef() {
    if [ -z "$1" ]; then
        printf "Must specify the name of a film file to edit\n" > /dev/stderr
        false
    elif [ -z "$2" ]; then
        vim -n -T alacritty "$HOME/TBcom/resources/op/film/$1.html"
        pushd "$HOME/TBcom/resources/op" > /dev/null
        git add film
        popd > /dev/null
        true
    else
        vim -n -T alacritty "$HOME/TBcom/resources/op/film/$1.html"
        vim -n -T alacritty "$HOME/TBcom/resources/op/film/$2.html"
        pushd "$HOME/TBcom/resources/op" > /dev/null
        git add film
        popd > /dev/null
        true
    fi
}

tbem

“TBcom Edit Music”

function tbem() {
    if [ -z "$1" ]; then
        printf "Must specify the name of an artist file to edit\n" > /dev/stderr
        false
    elif [ -z "$2" ]; then
        vim -n -T alacritty "$HOME/TBcom/resources/op/music/$1.html"
        pushd "$HOME/TBcom/resources/op" > /dev/null
        git add music
        popd > /dev/null
        true
    else
        vim -n -T alacritty "$HOME/TBcom/resources/op/music/$1.html"
        vim -n -T alacritty "$HOME/TBcom/resources/op/music/$2.html"
        pushd "$HOME/TBcom/resources/op" > /dev/null
        git add music
        popd > /dev/null
        true
    fi
}

pf

This function searches the list of running processes provided with ps and returns a match.

function pf() {
    if [ -z "$1" ]; then
        printf "pf needs a process name to search for\n" > /dev/stderr
        false
    else
        ps -aux | rg "$1"
    fi
}

t

This function, when given no arguments, simply starts the tremc Transmission client. If it is given a single argument, it is assumed it is a torrent file: it gives it to Transmission, then deletes it, and starts tremc. If it is given a second argument, it interprets that as the preferred download speed in kB/s.

function t() {
    if [ -z "$1" ]; then
        tremc --ssl -X -r -c "$TRANS_CREDENTIALS" 2> /dev/null
        true
     elif [ -z "$2" ]; then
        printf "Starting %s...\n" "$1"
        tremc --ssl -c "$TRANS_CREDENTIALS" "$1" > /dev/null
        rm "$1" 2> /dev/null
        tremc --ssl -X -r -c "$TRANS_CREDENTIALS" 2> /dev/null
        true
    elif [ -z "$3" ]; then
        printf "Starting %s with speed %s kbps...\n" "$1" "$2"
        tremc --ssl -c  "$1" > /dev/null
        transmission-remote --auth="$TRANS_PASS" -asd "$2"
        rm "$1" 2> /dev/null
        tremc --ssl -X -r -c "$TRANS_CREDENTIALS" 2> /dev/null
        true
    else
        printf "Too many arguments\n" > /dev/stderr
        false
    fi
}

y

Open a file with mupdf.

function y() {
    if [ -z "$1" ]; then
        printf "Please specify file to read\n" > /dev/stderr
        false
    else
        mupdf -I "$1"
        true
    fi
}

XBPS-Src Helper Functions

xs

function xs() {
    if [ -z "$1" ]; then
        printf "Please specify package name\n" > /dev/stderr
        false
    else
        pushd $VOIDPKG > /dev/null
        ./xbps-src show "$1"
        popd > /dev/null
        true
    fi
}

xb

function xb() {
    if [ -z "$1" ]; then
        printf "Please specify package name\n" > /dev/stderr
        false
    else
        pushd $VOIDPKG > /dev/null
        ./xbps-src build -C -f -j 4 "$1"
        popd > /dev/null
        true
    fi
}

xp

function xp() {
    if [ -z "$1" ]; then
        printf "Please specify package name\n" > /dev/stderr
        false
    else
        pushd $VOIDPKG > /dev/null
        ./xbps-src pkg -C -f -Q -j 4 "$1"
        popd > /dev/null
        true
    fi
}

xxr

function xxr() {
    if [ -z "$1" ]; then
        printf "Please specify package name\n" > /dev/stderr
        false
    elif [ -z "$2" ]; then
        pushd $VOIDPKG > /dev/null
        ./xbps-src remove "$1"
        popd > /dev/null
        true
    elif [ -z "$3" ]; then
        pushd $VOIDPKG > /dev/null
        ./xbps-src remove "$1" "$2"
        popd > /dev/null
        true
    elif [ -z "$4" ]; then
        pushd $VOIDPKG > /dev/null
        ./xbps-src remove "$1" "$2" "$3"
        popd > /dev/null
        true
    fi
}

j

A wrapper function for nnn that changes the current directory when it exits.

function j()
{
    if [[ ${TERM} = "screen-256color" ]]; then
        \nnn -d -i -l 2 -HGURQD -x -e -P preview-tui & ~/.config/nnn/plugins/preview-tui; fg
        return
    fi
    # Block nesting of nnn in subshells
    if [[ "${NNNLVL:-0}" -ge 1 ]]; then
        echo "nnn is already running"
        return
    fi
    export NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"

    \nnn -d -i -l 2 -GUHRQD -x -e "$@"

    if [ -f "$NNN_TMPFILE" ]; then
        . "$NNN_TMPFILE"
        rm -f "$NNN_TMPFILE" > /dev/null
    fi
}

wb

Set the wallpaper with two images, one for the left, and one for the right.

function wb() {
    swaybg -o eDP-1 -i "$1" -o HDMI-A-2 -i "$2"
}

Backup Website

This shell function backs up my website. It takes one argument, the output directory to store the backup in.

function backup() {
    if [ -z "$1" ]; then
        printf "Please specify directory to store backup in\n" > /dev/stderr
        false
    else
        sudo rsync -Pa -e "ssh -p 2222 -i $HOME/.ssh/tbcom_ssh" "$WEBSITE_ADDRESS:$RSYNC_PATH" "$1"
        true
    fi
}

Twitch

function twitch() {
    /home/babkock/git/twitch-chat-cli/cli.js connect babkock
}

Make a Video with Audio

function record() {
    if [[ -z "$1" && -z "$2" ]]; then
        printf "USAGE: %s [display] [output file]\n" "$0" > /dev/stderr
        false
    elif [ -z "$2" ]; then
        wf-recorder --audio=alsa_input.pci-0000_00_1f.3.analog-stereo -o HDMI-A-2 -c libx264rgb -r 60 -f "$1"
        true
    else
        wf-recorder --audio=alsa_input.pci-0000_00_1f.3.analog-stereo -o "$1" -c libx264rgb -r 60 -f "$2"
        true
    fi
}

Mount External Encrypted Drive

My external encrypted hard drive is automatically mounted on boot, but this is how to mount it manually.

function mm() {
    sudo cryptsetup luksOpen /dev/sda mega
    sudo mount -o rw,users /dev/mapper/mega /mnt/mega
    sudo chown -R babkock:babkock /mnt/mega
    sudo chown babkock:audio /mnt/mega
    sudo chown -R babkock:audio /mnt/mega/Music
    echo "sda Mounted"
}

Unmount External Encrypted Drive

This is how to unmount that drive.

function um() {
    sudo umount /mnt/mega
    sudo cryptsetup luksClose mega
    echo "sda Unmounted"
}

SSH Agent

I have to do this every time I use Git, or log in to my website.

function b() {
    pkill -x ssh-agent
    eval $(ssh-agent) > /dev/null 2>&1
    printf "SSH identities loaded\n"
    ssh-add "$HOME/.ssh/gitlab_rsa"
    ssh-add "$HOME/.ssh/github_rsa"
    ssh-add "$HOME/.ssh/tbcom_ssh"
}

Raspberry Pi Copy

function pcp() {
    if [[ -z "$1" ]]; then
        printf "No file specified\n" > /dev/stderr
        false
    elif [[ -z "$2" ]]; then
        scp -i "$HOME/.ssh/comp2pinew" "$1" pi@192.168.0.13:~
    else
        scp -i "$HOME/.ssh/comp2pinew" "$1" "$2" pi@192.168.0.13:~
    fi
}

Cheat.sh Lookup

function ch() {
    if [[ -z "$1" ]]; then
        printf "No command to look up\n" > /dev/stderr
        false
    elif [[ -z "$2" ]]; then
        curl "https://cht.sh/$1"
        true
    else
        curl "https://cht.sh/$1/$2"
        true
    fi
}

Cheat.sh Learn

function chp() {
    if [[ -z "$1" ]]; then
        printf "Enter a programming language to learn\n" > /dev/stderr
        false
    else
        curl "https://cht.sh/$1/:learn"
        true
    fi
}
function chl() {
    if [[ -z "$1" ]]; then
        printf "Enter a programming language to list topics for\n" > /dev/stderr
        false
    else
        curl "https://cht.sh/$1/:list"
        true
    fi
}

Fix PulseAudio Sink

function pv() {
    pactl set-default-sink alsa_output.pci-0000_00_1f.3.analog-stereo
    pactl set-default-source alsa_input.pci-0000_00_1f.3.analog-stereo
}

Aliases

This is my collection of aliases. Each letter of the alphabet should have its own command, to make the overall way of life easier. This was apparent before, but I use a number of tools written in Rust that serve as faster and better-looking versions of standard commands, like duf for df, lsd for ls, and ripgrep for grep. These commands look different, but behave exactly the same as the GNU coreutils they’re modeled after. These projects are worth checking out.

Command Arguments What It Does
ba N/A Snow 5-day forecast in Denver
bb N/A Run neofetch with fancy bars
c File name Run Bat on given files
ca File name Run Bat on given files
cb N/A Cargo build –release
co N/A Run btm task manager
ct N/A Cargo test –release
d N/A Run fd Find
dcr File name Decrypt given file with GNUPG
df N/A Run duf
e File name or directory Open given file or directory in Emacs
f N/A A file picker with preview pane
g Pattern, file name Run Ripgrep with given pattern on file
ga File name Add given file to staging area
gb N/A Run onefetch with fancy colors
gc Branch Check out branch on Git repository
gd File name Run Git diff on given file
ge N/A Git Fetch All
gf File name Check out given file from HEAD, reverting changes
ggo N/A Returns URL for repo’s origin
ggu N/A Returns URL for repo’s upstream
gh Pattern, file name Run Ripgrep with context with given pattern on file
gl N/A Run Git log with nice formatting
gm File name, file name Move or rename file and add to staging area
gn Repository URL Git clone
gnn Repository URL Git clone –depth 2
gp Options GNUPG
gpull N/A Git Pull Origin master
gpulm N/A Git Pull Origin main
gpush N/A Git Push Origin master
gpusm N/A Git Push Origin main
gpash N/A Git Push All master
gpasm N/A Git Push All main
gr File name Delete file from staging area
grc File name Delete file from staging area
gs N/A Run Git Status
gso URL Set URL for repo’s origin
gsu URL Set URL for repo’s upstream
h N/A Run Htop
i N/A Run Tig Git client
k N/A Make
kc N/A Make clean
km N/A Meson Setup Build
kn N/A Ninja -j4
m File name Open given file in MPV
mb N/A Mount Baby blue drive
md N/A Mount External SSD
mi File name Open given file in MPV, muted
mn Man page Man
mt File name Open given file in MPV, with sound sent to TV
n N/A Run Ncmpcpp
nb N/A Nix Build
ncr File name Encrypt given file with GNUPG
ne N/A Run Ncmpcpp with Ueberzug
nfi N/A Nix Flake Init
nfm N/A Nix Flake Metadata
npi Package name Nix Profile Install
npl N/A Nix Profile List
npr Package number Nix Profile Remove
o Process name Kill the given process
oa N/A Eww Active Windows
oc Eww window Eww Close Window
oi N/A Eww Inspector
ol N/A Eww List Windows
oo Eww window Eww Open Window
or N/A Eww Reload
p N/A Run Flowtop
po N/A Run Gotop
q File name Open given file in Swayimg
qg File name Open given file in GIMP
qw N/A Open current directory in Swayimg
r Directory Run Ranger on given or current directory
s N/A Log in to my website via SSH
sb N/A Restart Bluetooth Daemons
se N/A Restart Emacs Server
sf N/A Restart Waybar for Wayfire
skn N/A Log in to K’s new Mac
sko N/A Log in to K’s old Mac
sp N/A Restart Pipewire
spi N/A Log in to Raspberry Pi via SSH
sw N/A Restart Waybar for Sway
sy N/A Restart Waybar for Hyprland
sz N/A Kill wpasupplicant and restart with Ethernet
ta File name Extract given Tar archive
td Output file, files Compress files into given output Tar archive
ti N/A List Transmission torrents
tr Options Transmission-remote
ts N/A Transmission Information
tt N/A Transmission Statistics
u N/A Open Neomutt
ub N/A Unmount Baby blue drive
ud N/A Unmount External SSD
v File name Open given file in Vim
vm N/A Run Virt-Manager
wh Command/alias/function Which
x N/A Start Zsh as Root
xl N/A List installed packages
xu N/A Update system with XBPS
xx N/A Reboot system immediately
y File name Open given file in MuPDF
z N/A Start Bluetoothctl
# show weather in Denver today
alias ba="ansiweather -l '$CITY' -u imperial -H true -h false -p false -i false -s true"
# neofetch
alias bb="fastfetch -s 'Title:OS:Host:Kernel:Packages:Uptime:Break:WM:Shell:Terminal:Break:CPU:GPU:CPUUsage:Memory:Swap:Break:Display:Disk:Break:Colors' --packages-disabled 'nix' --color-keys 'red' --color-title 'cyan' --title-color-user 'green' --logo-color-1 'blue' --logo-color-2 'white'"
alias cb="cargo build --release"
alias co="btm"
alias c="bat" # like cat
alias ci="cargo init"
alias ct="cargo test --release"
alias df="duf -hide-mp \"/run/systemd,/boot/efi,/run,/run/user,/sys/fs/cgroup,/dev/shm\"" # like df
# fzf file picker with preview
alias f="fzf --preview=\"bat --color=always --style=plain {}\" --preview-window=\"border:rounded\" --border=rounded --prompt=\"$ \" --pointer=\"->\""
alias i="tig"
alias h="htop"
# encrypt file with GPG
alias ncr="gpg --encrypt --armor -r Tanner"
# decrypt file and output (use > direct)
alias dcr="gpg --decrypt"
alias g="ug -I --depth=4 --exclude-dir='node_modules' --exclude-dir='vendor' --exclude-dir='.git'"
alias gz="ug -I --depth=2 --exclude-dir='node_modules' --exclude-dir='vendor' --exclude-dir='.git'"
alias gh="ug -I --context=4 --depth=4 --exclude-dir='node_modules' --exclude-dir='vendor' --exclude-dir='.git'"
alias gb="onefetch --no-color-palette -d head dependencies --text-colors 7 9 1 10 1 4"
alias gp="gpg"
alias gs="git status -sb"
alias ga="git add"
alias ge="git fetch --all"
alias gf="git checkout HEAD --"
alias gcm="git commit -m"
alias gca="git commit --allow-empty-message -m ''"
alias gc="git checkout"
alias gcb="git checkout -b"
alias gd="git diff"
alias gdt="git diff-tree"
alias gdz="git diff HEAD^"
alias gdy="git diff HEAD^^"
# git log with special formatting
alias gl="git log --date=relative --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %C(yellow)(%cr) %C(bold blue) %an%Creset'"
alias gw="git show"
alias gr="git rm"
alias grc="git rm --cached"
alias gm="git mv"
alias gn="git clone"
alias gnn="git clone --depth 2"
alias ggo="git remote get-url origin"
alias gso="git remote set-url origin"
alias ggu="git remote get-url upstream"
alias gsu="git remote set-url upstream"
# use these if branch is 'master'
alias gpush="git push origin master"
alias gpull="git pull origin master"
# use these if branch is 'main'
alias gpusm="git push origin main"
alias gpulm="git pull origin main"
# push 'master' to multiple remotes
alias gpash="git push all master; git pull origin master; git pull upstream master"
# push 'main' to multiple remotes
alias gpasm="git push all main; git pull origin main; git pull upstream main"
alias v="vim -n -T alacritty"
alias vh="vim -n -T alacritty -o"
alias vv="vim -n -T alacritty -O"
alias vim="vim -n -T alacritty"
alias vm="virt-manager"
alias lb="lsblk --paths --fs --perms"
alias r="ranger"
alias m="mpv"
alias mb="mount /mnt/Baby; echo 'sdb Mounted'"
alias md="mount /mnt/drive; echo 'sdb Mounted'"
alias mi="mpv --mute=yes"
alias mt="mpv --audio-device=alsa/hdmi:CARD=PCH,DEV=1"
alias mn="man"
alias tl="tldr"
alias n="ncmpcpp"
alias ne="$HOME/.ncmpcpp/ncmpcpp-ueberzug/ncmpcpp-ueberzug"
alias npi="nix profile install"
alias npl="nix profile list"
alias npr="nix profile remove"
alias nb="nix build --extra-experimental-features nix-command --extra-experimental-features flakes"
alias nfi="nix flake --extra-experimental-features nix-command --extra-experimental-features flakes init"
alias nfm="nix flake --extra-experimental-features nix-command --extra-experimental-features flakes metadata"
alias nfc="nix show-config --extra-experimental-features nix-command"
alias nsh="nix-shell"
alias nr="nix repl"
alias o="pkill -x"
alias oa="eww active-windows"
alias oc="eww close"
alias of="eww open waymem; eww open waycalendar; eww open waypower; eww open wayfiles"
alias oi="eww inspector"
alias ol="eww list-windows"
alias oo="eww open"
alias or="eww reload"
alias ow="eww open mem; eww open calendar; eww open power; eww open files"
#alias oh="pgrep Hyprland | xargs kill 2> /dev/null ; pgrep mako | xargs kill 2> /dev/null"
alias u="neomutt -F '$HOME/.muttrc'"
alias spi="TERM=xterm-256color ssh -i '$HOME/.ssh/comp2pinew' pi@192.168.0.13"
alias sk="ssh -i '$HOME/.ssh/me2newmac' kristinowens@192.168.0.15"
alias po="gotop"
alias p="sudo flowtop -46UTDISs -t 2"
alias q="swayimg"
alias qw="swayimg -g -r -w 1920,1080 -p 0,0"
alias qi="identify"
alias qg="gimp"
alias s="ssh $WEBSITE_ADDRESS -p 2222 -i '$HOME/.ssh/tbcom_ssh'"
alias sb="sudo sv restart bluez-alsa; sudo sv restart bluetoothd"
alias se="pkill -x emacs; emacs --daemon"
alias sw="pkill -x waybar; waybar -c '$HOME/.config/waybar/sway.json' -s '$HOME/.config/waybar/sway.css' -l off &"
alias sf="pkill -x waybar; waybar -c '$HOME/.config/waybar/wayfire.json' -s '$HOME/.config/waybar/wayfire.css' -l off &"
alias so="pkill -x eww"
alias sy="pkill -x waybar; waybar -c '$HOME/.config/waybar/hyprland.json' -s '$HOME/.config/waybar/hyprland.css' -l off &"
alias sp="pkill -x pipewire; pkill -x pulseaudio; pkill -x pipewire; pipewire &"
alias sz="sudo pkill -x wpa_supplicant; sudo wpa_supplicant -B -Dwired -ienp0s31f6 -c/etc/wpa_supplicant/wpa_supplicant.conf"
alias ta="tar xvf"
alias td="tar czf"
alias ti="transmission-remote --auth='$TRANS_PASS' -l"
alias ts="transmission-remote --auth='$TRANS_PASS' -si"
alias tt="transmission-remote --auth='$TRANS_PASS' -st"
alias tr="transmission-remote --auth='$TRANS_PASS'"
alias ub="umount /mnt/Baby; echo Unmounted"
alias ud="umount /mnt/drive; echo Unmounted"
alias k="make"
alias kc="make clean"
alias ki="sudo make install"
alias km="meson setup build --buildtype=release --prefix=/usr"
alias kn="ninja -j4"
alias wh="which"
alias x="sudo zsh"
alias xxb="cd $VOIDPKG; ./xbps-src binary-bootstrap; cd $OLDPWD"
alias xz="cd $VOIDPKG; ./xbps-src zap; cd $OLDPWD"
alias xi="sudo xbps-install -S"
alias xl="sudo xbps-query -l"
alias xr="sudo xbps-remove"
alias xo="sudo xbps-query -O"
alias xu="sudo xbps-install -Su"
#alias xb="./xbps-src build -C -f -j 4"
#alias xp="./xbps-src pkg -C -f -Q -j 4"
#alias xxr="./xbps-src remove"
alias xxu="cd $VOIDPKG; ./xbps-src update-sys; cd $OLDPWD"
alias xxl="cd $VOIDPKG; ./xbps-src list; cd $OLDPWD"
#alias xs="./xbps-src show"
alias xlu="cd $VOIDPKG; ./xbps-src show-local-updates; cd $OLDPWD"
alias xsu="cd $VOIDPKG; ./xbps-src show-sys-updates; cd $OLDPWD"
alias yz="yazi"
alias z="bluetoothctl"

Plugins

I use the following shell plug-ins, which are loaded from the ~/.zsh directory.

fpath+=$HOME/.zsh/typewritten
fpath+=$HOME/.zsh/nix-zsh-completions
fpath+=$HOME/.zsh/zsh-completions/src
autoload -U compinit; compinit
autoload -U promptinit; promptinit
prompt typewritten

source $HOME/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source $HOME/.zsh/zsh-history-substring-search/zsh-history-substring-search.zsh
export HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND=""
export HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND=""
source $HOME/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
source $HOME/.zsh/zsh-autopair/autopair.zsh
source $HOME/.zsh/zsh-fzf-history-search/zsh-fzf-history-search.zsh
source $HOME/.zsh/zsh-nix-shell/nix-shell.plugin.zsh
source $HOME/.zsh/you-should-use/you-should-use.plugin.zsh
source $HOME/.zsh/completion.zsh
source $HOME/.zsh/nix-zsh-completions/nix-zsh-completions.plugin.zsh
source $HOME/.zsh/correction.zsh
source $HOME/.zsh/history.zsh
source $HOME/.zsh/colored-man-pages.plugin.zsh

Keybindings

Add more keybindings to the completion menu, history substring search on up and down arrows, and undo/redo functionality.

bindkey -M menuselect '^[[Z' reverse-menu-complete # Shift+Tab
bindkey -M menuselect '^@' reverse-menu-complete
bindkey -M menuselect '^[[27;2;13~' accept-and-hold # Shift+Enter
bindkey -M menuselect '^{' clear-screen # Escape
bindkey -M menuselect '^[[A' vi-up-line-or-history
bindkey -M menuselect '^[[B' vi-down-line-or-history
bindkey -M menuselect '^[[D' vi-backward-char
bindkey -M menuselect '^[[C' vi-forward-char
bindkey -M menuselect '^[[1;2D' beginning-of-buffer-or-history # Shift+Left Arrow
bindkey -M menuselect '^[[1;2C' end-of-buffer-or-history # Shift+Right Arrow
bindkey -M main '^[[A' history-substring-search-up
bindkey -M main '^[[B' history-substring-search-down
bindkey -M main '^Z' undo # Control+Z
bindkey -M main '^Y' redo # Control+Y

Environment Variables

These next lines accomplish a few things. They let me use directory-changers like nnn and Zoxide, and configure the programs bat, fzf, and wob.

export GPG_TTY=$(tty)
gpgconf --launch gpg-agent
export GREP_COLORS="fn=bh:ln=gh:mt=rh:cx=y"
export EDITOR=vim
export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#555555"
export NNN_FIFO=/tmp/nnn.fifo
export NNN_PLUG="p:-preview-tui;v:imgview;g:!tig*;v:!vim"
export NNN_COLORS="2365"
export BAT_STYLE="header,header-filesize,header-filename,changes"
export FZF_DEFAULT_OPTS="--border=horizontal --color=bg+:black,fg+:bright-green:italic,gutter:-1,hl:blue,hl+:bright-blue,query:bright-yellow,prompt:bright-yellow,pointer:black:dim,info:magenta,preview-bg:black,border:black:dim"
export WOBSOCK="$HOME/.wob.sock"

Tricks

prompt_nix_shell_setup "$@"

random=$(shuf -i 1-3 -n 1)
if [[ ${TERM} = "st-256color" || ${TERM} = "rxvt-unicode" || ${TERM} = "xterm-256color" || ${TERM} = "foot" || ${TERM} = "kitty" || ${TERM} = "alacritty" ]]; then
    if [[ "$random" == "1" ]]; then
        pokemon-colorscripts --no-title -r 1-3
    elif [[ "$random" == "2" ]]; then
        pokemon-colorscripts --no-title -s -r 1-3
    else
        colorscript -r
    fi
else
    colorscript -r
fi

>

Author: Tanner Babcock

Created: 2025-05-22 Thu 18:12