if status is-interactive ## Functions function _handle_colorls if command -sq colorls alias ls 'colorls -G -F' alias ll 'colorls -G -F -l' alias la 'colorls -G -F -a' alias lla 'colorls -G -F -l -a' else alias ls 'ls -F' alias la 'ls -F -a' alias ll 'ls -F -l' alias lla 'ls -F -l -a' end end function _handle_eza switch $TERM case 'xterm-256color' set -f icons 'yes' case 'xterm-ghostty' set -f icons 'yes' case 'xterm-kitty' set -f icons 'yes' case 'tmux-256color' set -f icons 'yes' case 'foot' set -f icons 'yes' case 'xterm' set -f icons 'no' case '*' set -f icons 'no' end if string match -q -e 'XTerm/OpenBSD' $XTERM_VERSION set -f icons 'no' end if string match -q -e 'yes' $icons alias ls 'eza --icons --group' alias la 'eza --icons --all' else alias ls 'eza --group' alias la 'eza --all' end alias ll 'eza --long --group' alias lt 'eza --tree' alias lta 'eza --all --tree' alias lla 'eza --all --long --group' alias llta 'eza --all --tree --long --group' end ### Linux function _handle_linux if command -sq dircolors; and test -f ~/.config/dircolors eval (dircolors -c ~/.config/dircolors) end alias ls 'ls --color=auto -F' alias la 'ls --color=auto -F -a' alias ll 'ls --color=auto -F -l' alias lla 'ls --color=auto -F -l -a' alias grep 'grep --color=auto' alias diff 'diff --color=auto' alias same 'diff --color=auto --old-line-format="" --new-line-format="" --unchanged-line-format="%L"' alias ff 'find . -type f -name' alias fd 'find . -type d -name' alias fbs 'find . -xtype l' alias who 'who -H -w -u' alias free 'free -h' alias df 'df -Th' alias ps 'ps -ejH' alias lsof 'lsfd' # If we have iproute2 if command -sq ip alias ip "ip -c" alias sockstat "ss -4 -6 -l -r -p" alias_if_not route ip route alias_if_not ifconfig ip link alias_if_not netstat ss -4 -6 -l -r -p end # If we have pacman if command -sq pacman alias lspkg 'pacman -Q --color=always | rawpager' alias lspkgi 'pacman -Qett --color=always | rawpager' alias lspkgo 'pacman -Qdt' alias pkginfo 'pacman -Qi' alias pkgsearch 'pacman -Ss' alias whatpkg 'pacman -Qo' if fish_is_root_user alias pkgadd 'pacman -S' alias pkgrm 'pacman -Rs' alias pkgupd 'pacman -Syyu' alias pkgclean 'paccache -k 0 -r' alias confnew 'find /etc -type f -name "*.pacnew"' else alias pkgadd 'sudo pacman -S' alias pkgrm 'sudo pacman -Rs' alias pkgupd 'sudo pacman -Syyu' alias pkgclean 'sudo paccache -k 0 -r' alias confnew 'sudo find /etc -type f -name "*.pacnew"' end function is-installed pacman -Qq $argv &>/dev/null end end # If we have apk if command -sq apk alias lspkg 'apk list -I' alias lspkgo 'apk list -O' alias pkginfo 'apk info' alias pkgsearch 'apk search' alias whatpkg 'apk info -W' if fish_is_root_user alias pkgadd 'apk add' alias pkgrm 'apk del' alias pkgupd 'apk update ; apk upgrade' alias confnew 'find /etc -type f -name "*.apk-new"' else alias pkgadd 'doas apk add' alias pkgrm 'doas apk del' alias pkgupd 'doas sh -c "apk update ; apk upgrade"' alias confnew 'doas find /etc/ -type f -name "*.apk-new"' end function is-installed apk info -e $argv &>/dev/null end end # If we have systemd if command -sq systemctl alias pss "systemd-cgls" alias ipconfig "networkctl -a status" if not fish_is_root_user alias showdnscache "sudo resolvectl show-cache" alias cleardnscache "sudo resolvectl flush-caches" else alias showdnscache "resolvectl show-cache" alias cleardnscache "resolvectl flush-caches" end alias_if_not nslookup systemd-resolve end end # _handle_linux ### macOS function _handle_macos if test -d '/opt/homebrew/bin' fish_add_path --prepend --global --path '/opt/homebrew/bin' end alias ff "find . -type f -name" alias fd "find . -type d -name" alias grep "grep --color=auto" alias nproc "sysctl -n hw.ncpu" alias lsblk "diskutil list" alias route "netstat -nr" # If we have Homebrew if command -sq brew alias lspkg 'brew list ; echo ; brew info' alias pkginfo 'brew info' alias pkgsearch 'brew search' alias pkgadd 'brew install' alias pkgrm 'brew uninstall' alias pkgupd 'brew update ; echo ; brew upgrade' function is-installed brew list -1 | grep -q "^$argv\$" end end # If we have MacPorts if command -sq port alias lspkg 'port installed' alias lspkgo 'port list rleaves' alias pkginfo 'port info' alias pkgsearch 'port search' if fish_is_root_user alias pkgadd 'port install' alias pkgrm 'port uninstall' alias pkgupd 'port upgrade outdated' else alias pkgadd 'sudo port install' alias pkgrm 'sudo port uninstall' alias pkgupd 'sudo port upgrade outdated' end end end # _handle_macos ### NetBSD function _handle_netbsd _handle_colorls alias nproc 'sysctl -n hw.ncpu' alias free 'vmstat' alias lsusb 'usbdevs' alias lspci 'pcictl pci0 list' alias lsbat 'envstat -d acpibat0' alias lspkg 'pkgin list' alias pkginfo 'pkgin pkg-descr' alias pkgsearch 'pkgin search' if fish_is_root_user alias pkgadd 'pkgin install' alias pkgrm 'pkgin remove' alias pkgupd 'pkgin upgrade' alias pkgclean 'pkgin clean' else alias pkgadd 'doas pkgin install' alias pkgrm 'doas pkgin remove' alias pkgupd 'doas pkgin upgrade' alias pkgclean 'doas pkgin clean' end end # _handle_netbsd ### OpenBSD function _handle_openbsd _handle_colorls alias nproc 'sysctl -n hw.ncpu' alias free 'vmstat' alias lsof 'fstat' alias lsblk 'sysctl hw.disknames' alias lspci 'pcidump' alias ff 'find . -type f -name' alias fd 'find . -type d -name' alias fbs 'find . -type l' alias route 'netstat -nr' alias lspkg 'pkg_info -A' alias lspkgo 'pkg_info -t' alias pkginfo 'pkg_info' alias pkgsearch 'pkg_info -Q' if fish_is_root_user alias pkgadd 'pkg_add' alias pkgrm 'pkg_delete' alias pkgupd 'pkg_add -u' alias poweroff 'shutdown -p now' else alias pkgadd 'doas pkg_add' alias pkgrm 'doas pkg_delete' alias pkgupd 'doas pkg_add -u' alias poweroff 'doas shutdown -p now' end function is-installed pkg_info -q -e "$argv->=0" end end # _handle_openbsd ### FreeBSD function _handle_freebsd alias ls 'ls -GF' alias la 'ls -GF -a' alias ll 'ls -GF -l' alias lla 'ls -GF -l -a' alias ff 'find . -type f -name' alias fd 'find . -type d -name' alias df 'df -Th' alias nproc "sysctl -n hw.ncpu" alias free "vmstat" alias lsusb "usbconfig list" alias lspci "pciconf -lv" alias lsmod "kldstat" alias insmod "kldload" alias pkginfo 'pkg info' alias pkgsearch 'pkg search' if fish_is_root_user alias pkgadd 'pkg install' alias pkgrm 'pkg remove' alias pkgupd 'pkg upgrade' alias pkgclean 'pkg clean -a' else alias pkgadd 'doas pkg install' alias pkgrm 'doas pkg remove' alias pkgupd 'doas pkg upgrade' alias pkgclean 'doas pkg clean -a' end end # _handle_freebsd switch (uname) case 'Linux' _handle_linux case 'Darwin' _handle_macos case 'OpenBSD' _handle_openbsd case 'NetBSD' _handle_netbsd case 'FreeBSD' _handle_freebsd end ## All platforms if command -sq 'eza' _handle_eza else if command -sq tree alias lta 'tree -a' alias llta 'tree -apugsh' end end alias l 'ls' alias lls '/bin/ls' alias md 'mkdir' alias rd 'rmdir' alias du 'du -h' alias_if doas sudo # Process viewer to look for by order of preference set topprg 'htop' 'btop' set found_topprg (find_prog $topprg) if test -n "$found_topprg" alias top "$found_topprg" end # Cleanup functions -e _handle_eza functions -e _handle_colorls functions -e _handle_linux functions -e _handle_macos functions -e _handle_openbsd functions -e _handle_netbsd functions -e _handle_freebsd end