#!/bin/zsh # Resets missing pagkages on load MISSING_PACKAGES='' if (( $+commands[xbps-install] )); then export OS_DETECTION="void" elif (( $+commands[emerge] )); then export OS_DETECTION="gentoo" elif (( $+commands[pacman] )); then export OS_DETECTION="arch" elif (( $+commands[apt-get] )); then export OS_DETECTION="debian" elif (( $+commands[apk] )); then export OS_DETECTION=alpine elif [[ "$OSTYPE" == "darwin"* ]]; then export OS_DETECTION="mac" else; export OS_DETECTION="" fi if [ "$OS_DETECTION" = "arch" ]; then ## Package Manager - pacman/yay if (( $+commands[yay] )); then alias pi='yay -S' alias pr='yay -R' alias psearch='yay -Slq | fzf --multi --preview 'yay -Si {1}' | xargs -ro yay -S' alias pu='yay -Syu --devel --timeupdate' alias oneshot='yay -S --asdeps' alias orphans="yay -Qtdq | yay -Rns -" else export XDG_CONFIG_HOME="${HOME}/.config" MISSING_PACKAGES+=('yay') alias pi='sudo pacman -S' alias pr='sudo pacman -R' alias psearch='pacman -Slq | fzf --multi --preview 'sudo pacman -Si {1}' | xargs -ro sudo pacman -S' alias pu='sudo pacman -Syu' alias oneshot='sudo pacman -S --asdeps' alias orphans="pacman -Qtdq | sudo pacman -Rns -" fi alias mirrorupdate="sudo pacman-mirrors --geoip && sudo pacman -Syyu" alias etc-update="sudo pacdiff" alias asdep="sudo pacman -D --asdeps" alias explicit="sudo pacman -D --asexplicit" elif [ "$OS_DETECTION" = "debian" ]; then ## Package Manager - apt alias pi='sudo apt install' alias pr='sudo apt remove' alias psearch='apt search' alias pu='sudo apt update && sudo apt upgrade' alias orphans='apt autoremove' elif [ "$OS_DETECTION" = "gentoo" ]; then ## Package Manager - portage/emerge alias gsync='sudo emerge --sync' alias pi='sudo emerge -av --autounmask' alias oneshot='sudo emerge -av --oneshot' alias pu='sudo emerge --update --deep --with-bdeps=y --newuse --keep-going @world --ask' alias pr='sudo emerge --depclean -a' alias psearch='eix -r' alias howlong='sudo watch --color genlop -uic' alias etcupdate='sudo -E etc-update --automode -3' elif [ "$OS_DETECTION" = "alpine" ]; then ## Package Manager - apk alias pi='sudo apk add' alias pr='sudo apk del' alias psearch='sudo apk search' alias pu='sudo apk update && sudo apk upgrade' elif [ "$OS_DETECTION" = "void" ]; then ## Package Manager - void/xpbs alias pi='sudo xbps-install -S' alias prr='sudo xbps-remove -R' alias pr='sudo xbps-remove' alias psearch='sudo xbps-query -Rs' alias pu='sudo xbps-install -Su' alias orphans='sudo xpbs-remove -o' elif [ "$OS_DETECTION" = "mac" ]; then ## Package Manager - brew function pi { brew install "${@:1}" brew bundle dump --force --file=$HOMEBREW_BREWFILE } function pic { brew install --cask "${@:1}" brew bundle dump --force --file=$HOMEBREW_BREWFILE } function pr { brew uninstall "${@:1}" brew bundle dump --force --file=$HOMEBREW_BREWFILE } function prc { brew uninstall cask "${@:1}" brew bundle dump --force --file=$HOMEBREW_BREWFILE } alias psearch='brew search' alias pu='brew update && brew upgrade' alias orphans='brew autoremove' elif [ "$OS_DETECTION" = "bsd" ]; then ## Package Manager - freebsd alias pi='sudo pkg install' alias pr='sudo pkg remove' alias psearch='sudo pkg search' alias pu='sudo pkg update && sudo pkg upgrade' elif (( $+commands[nixos-rebuild] )); then ## Package Manager - nix alias psearch='nix search nixpkgs' alias pclean='nix-collect-garbage --delete-older-than 7d' fi if (( $+commands[home-manager] )); then ## Package Manager - nix alias npsearch='nix search nixpkgs' alias hmc='home-manager expire-generations -7days' alias hm='home-manager ' alias hsearch='nix search nixpkgs' alias nso='nix-store --optimise' fi # Docker shortcuts if (( $+commands[docker] )); then alias dc='docker compose ' alias dcu='docker compose up ' alias dcud='docker compose up -d ' alias dcd='docker compose down ' alias dcl='docker compose logs -f ' alias dprune='docker system prune -a ' alias dps='docker ps ' alias dstart='docker start ' alias dstop=' docker stop ' alias dupd='docker compose pull && docker compose up --force-recreate -d' fi function prune () { if (( $+commands[home-manager] )); then nix-collect-garbage --delete-older-than 7d nix-store --optimise fi if (( $+commands[nixos-rebuild] )); then sudo nix-collect-garbage -d sudo nix-store --optimise fi if command -v docker &> /dev/null; then docker system prune -a --volumes fi if [ "$OS_DETECTION" = "mac" ]; then brew cleanup fi if [ "$OS_DETECTION" = "alpine" ]; then sudo apk cache clean fi if [ "$OS_DETECTION" = "void" ]; then sudo xbps-remote -O fi if [ "$OS_DETECTION" = "gentoo" ]; then sudo eclean packages sudo eclean distfiles sudo eclean-kernel fi if [ "$OS_DETECTION" = "arch" ]; then if (( $+commands[yay] )); then yay -Sc yay -Yc else sudo pacman -Sc fi fi if [ "$OS_DETECTION" = "debian" ]; then sudo apt autoclean fi } # Alias alternatives for commands if they exist if (( $+commands[colordiff] )); then alias diff="colordiff -Nuar" alias youtube-dl="noglob youtube-dl" else MISSING_PACKAGES+=('colordiff') alias diff="diff -Nuar" fi if (( !$+commands[tldr] )); then MISSING_PACKAGES+=('tealdeer') fi if (( $+commands[sd] )); then alias sed="sd": else MISSING_PACKAGES+=('sd') fi if (( $+commands[bandwhich] )); then alias bmon="bandwhich": else MISSING_PACKAGES+=('bandwhich') fi if (( $+commands[rg] )); then alias grep="rg" else MISSING_PACKAGES+=('ripgrep') alias grep='command grep -E --colour=auto' fi if (( $+commands[bat] )); then alias cat='bat -p' else MISSING_PACKAGES+=('bat') fi if (( $+commands[eza] )); then alias ls='eza --icons' alias l='eza -al --icons' else MISSING_PACKAGES+=('eza') alias l='ls -al' fi if (( $+commands[nvim] )); then alias vim='nvim' fi if (( $+commands[gping] )); then alias ping='gping' else MISSING_PACKAGES+=('gping') fi if (( $+commands[btm] )); then alias top='btm' elif (( $+commands[htop] )); then MISSING_PACKAGES+=('btm') alias top='htop' else MISSING_PACKAGES+=('btm htop') fi if (( $+commands[dust] )); then alias du='dust -r' else MISSING_PACKAGES+=('dust') alias du='du -h -s' fi if (( $+commands[grim] )); then alias scrot='grim "desktop-$(date +"%Y%m%d%H%M").png"' alias sscrot='grim -g "$(slurp)" "desktop-$(date +"%Y%m%d%H%M").png"' elif (( $+commands[scrot] )); then alias scrot='scrot desktop-%Y%m%d%H%M.png -q 100 -cd 3' fi #if (( $+commands[cargo] )); then #alias cargo-update="cargo install $(cargo install --list | command grep -E '^[a-z0-9_-]+ v[0-9.]+:$' | cut -f1 -d' ')" #fi if [ "$OS_DETECTION" = "mac" ]; then alias xclip='pbcopy' alias ding="osascript -e 'display notification \"command done\"'" else if (( $+commands[wl-copy] )); then alias xclip='tee >(wl-copy) | wl-copy -p' fi alias ding='notify-send "command done"' fi if (( $+commands[yt-dlp] )); then alias yoink='yt-dlp --audio-format best -x ' else MISSING_PACKAGES+=('yt-dlp') fi # Stop using etc-update if (( $+commands[dispatch-conf ] )); then alias etc-update='dispatch-conf ' fi # Linux aliases if [[ "$OSTYPE" == "linux"* ]]; then #alias sway='dbus-launch --sh-syntax --exit-with-session /usr/bin/sway' alias minecraft='QT_QPA_PLATFORM= multimc' fi alias zplug-install='curl -sL --proto-redir -all,https https://raw.githubusercontent.com/zplug/installer/master/installer.zsh | zsh' # Sprunge replacement alias -g sprunge=" curl -F 'f:1=<-' ix.io" # Changing dirs with just dots. alias .='cd ../' alias ..='cd ../../' alias ...='cd ../../../' alias ....='cd ../../../../' # Default flags alias cp='cp -R -i -v' alias mv='mv -i -v' alias mkdir='mkdir -p -v' alias df='df -h' alias dd='dd status=progress bs=4M conv=fdatasync ' alias ncdu='ncdu -x' # Don't cross filesystem boundries alias sudo='sudo env "PATH=$PATH" ' # Makes sudo work with aliases and saves path # Shortcuts to edit common files alias reload='source ${HOME}/.zshrc' alias zshrc="$EDITOR ${HOME}/.zshrc" alias zshenv="$EDITOR ${HOME}/.zshenv" alias zshaliases="$EDITOR ${HOME}/.zsh_aliases" alias vimrc="$EDITOR ${HOME}/.vimrc" alias bootstrap="$EDITOR ${HOME}/.config/yadm/bootstrap" if [ "$OS_DETECTION" = "alpine" ]; then alias worldedit="sudo $EDITOR /etc/apk/world" elif [ "$OS_DETECTION" = "gentoo" ]; then alias worldedit="sudo $EDITOR /var/lib/portage/world" else alias worldedit="$EDITOR ${HOME}/.config/worldedit/$(hostname)" fi # Git remote manipulation and pushing multiple remotes alias grf='git remote set-url origin ssh://git@morbo.far:222/$(whoami)/$(basename $(pwd))' alias grh='git remote set-url origin ssh://git@morbo.home:222/$(whoami)/$(basename $(pwd))' alias grg='git remote set-url origin ssh://git@github.com:/$(whoami)/$(basename $(pwd))' alias gpa='git push && git push github' alias gp='git pull' alias gpu='git push' alias gpf='git push --force' # Misc alieses I use often alias rmd='rm -rf' alias mine='sudo chown -R $(whoami):users' alias nmap-qsp='sudo nmap -sV -T4 -O -F --version-light' alias benchmark='hyperfine --warmup 3 ' alias kestimate='klipper_estimator --config_file ${HOME}/vzbot.json estimate ' # Other alias zsnaplatest='zfs list -t snapshot -H -S creation -o name -d 1' alias wavogg='for f in *.wav; do ffmpeg -i "$f" -c:a libvorbis -q:a 4 "${f/%wav/ogg}"; done' alias ytp='mpv --ytdl-raw-options="cookies=${HOME}./youtube.com_cookies.txt" --ytdl-raw-options="yes-playlist=" --no-video' alias yt='mpv --ytdl-raw-options="cookies=${HOME}./youtube.com_cookies.txt" --ytdl-raw-options="yes-playlist="' alias mountfat='sudo mount -t vfat -o rw,uid=$(id -u),gid=$(id -g)' alias mountiso="sudo mount -t iso9660 -o loop" alias zinit="zoxide init zsh > ${HOME}/.zoxide" alias plugins="$EDITOR $HOME/.zpackages.zsh" alias docker-update="docker images --format \"{{.Repository}}:{{.Tag}}\" | grep --invert-match '' | xargs -L1 docker pull" alias emacsnw="emacs -nw" alias install-doom="git clone --depth 1 https://github.com/doomemacs/doomemacs ~/.emacs.d && ~/.emacs.d/bin/doom install" #alias sd='cd $(find . -type d -print | fzf)' alias fhinit='nix run "https://flakehub.com/f/DeterminateSystems/fh/*.tar.gz" -- init' # doctor function zsh-doctor () { [[ -n "$MISSING_PACKAGES" ]] && echo "Missing pagkages: ${MISSING_PACKAGES}" [[ ! -n "$OS_DETECTION" ]] && echo "OS/Distro not detected" } # Easy extract extract () { if [ -f $1 ] ; then case $1 in *.tar.bz2) tar xvjf $1 ;; *.tar.gz) tar xvzf $1 ;; *.tar.xz) tar xvJf $1 ;; *.bz2) bunzip2 $1 ;; *.rar) unrar x $1 ;; *.gz) gunzip $1 ;; *.tar) tar xvf $1 ;; *.tbz2) tar xvjf $1 ;; *.tgz) tar xvzf $1 ;; *.txz) tar xvJf $1 ;; *.rar) unrar $1 ;; *.zip) unzip $1 ;; *.Z) uncompress $1 ;; *.7z) 7z x $1 ;; *) echo "don't know how to extract '$1'..." ;; esac else echo "'$1' is not a valid file!" fi } # Makes directory then moves into it function mkcdr { mkdir -p -v $1 cd $1 } # Creates an archive from given directory mktar() { tar cvf "${1%%/}.tar" "${1%%/}/"; } mktgz() { tar cvzf "${1%%/}.tar.gz" "${1%%/}/"; } mktbz() { tar cvjf "${1%%/}.tar.bz2" "${1%%/}/"; } mkzip() { 7z a -r "${1%%/}.zip" "${1%%/}/"; } mk7zip() { 7z a -r "${1%%/}.7z" "${1%%/}/"; } nixify() { if [ ! -e ./.envrc ]; then echo "use nix" > .envrc direnv allow fi if [[ ! -e shell.nix ]] && [[ ! -e default.nix ]]; then cat > default.nix <<'EOF' with import {}; mkShell { nativeBuildInputs = [ bashInteractive ]; } EOF ${EDITOR:-vim} default.nix fi } flakify() { if [ ! -e flake.nix ]; then nix flake new -t github:nix-community/nix-direnv . elif [ ! -e .envrc ]; then echo "use flake" > .envrc direnv allow fi ${EDITOR:-vim} flake.nix }