-
Notifications
You must be signed in to change notification settings - Fork 14
Description
Because fish’s alias shorthand method of creating an alias function writes to the universal function database (loaded after config files), system aliases override user-defined functions even if those functions appear later in config.fish. It’d be more intuitive if system aliases lived in /etc/fish/functions/ so file-order works as expected.
I was attempting to define a couple aliases to redefine how ls and ll behaved. I have my own personal preference after all. I was not using the alias shorthand for this as I personally define all my aliases and functions as ~/.config/fish/functions/functions.fish and you cannot use the shorthand inside a file that resides in the functions folder. Fish expects only actual functions there.
After hours of troubleshooting I discovered that I could get it to work by using the alias shorthand in my ~/.config/fish/config.fish file. I then spent several more hours determining why that was, and why it broke the logical flow of a user defined thing not overriding a system defined thing.
It turns out that the file /usr/share/cachyos-fish-config/cachyos-config.fish contains the following lines:
...
## Useful aliases
# Replace ls with eza
alias ls='eza -al --color=always --group-directories-first --icons' # preferred listing
alias la='eza -a --color=always --group-directories-first --icons' # all files and dirs
alias ll='eza -l --color=always --group-directories-first --icons' # long format
alias lt='eza -aT --color=always --group-directories-first --icons' # tree listing
alias l.="eza -a | grep -e '^\.'" # show only dotfiles
# Common use
alias grubup="sudo grub-mkconfig -o /boot/grub/grub.cfg"
alias fixpacman="sudo rm /var/lib/pacman/db.lck"
alias tarnow='tar -acf '
alias untar='tar -zxvf '
alias wget='wget -c '
alias psmem='ps auxf | sort -nr -k 4'
alias psmem10='ps auxf | sort -nr -k 4 | head -10'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias ......='cd ../../../../..'
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias hw='hwinfo --short' # Hardware Info
alias big="expac -H M '%m\t%n' | sort -h | nl" # Sort installed packages according to size in MB
alias gitpkg='pacman -Q | grep -i "\-git" | wc -l' # List amount of -git packages
alias update='sudo pacman -Syu'
# Get fastest mirrors
alias mirror="sudo cachyos-rate-mirrors"
# Help people new to Arch
alias apt='man pacman'
alias apt-get='man pacman'
alias please='sudo'
alias tb='nc termbin.com 9999'
# Cleanup orphaned packages
alias cleanup='sudo pacman -Rns (pacman -Qtdq)'
# Get the error messages from journalctl
alias jctl="journalctl -p 3 -xb"
# Recent installed packages
alias rip="expac --timefmt='%Y-%m-%d %T' '%l\t%n %v' | sort | tail -200 | nl"
Because those are defined using the alias shorthand, they all actually end up being written as a universal function in my personal fish function database and get run after any file based definitions, thus it stomps on anything you put in ~/.config/fish/config.fish or ~/.config/fish/functions/. The only way to get around this is to define your overrides also using the alias shorthand, thus also adding them as a universal function and clobbering the ones defined in /usr/share/cachyos-fish-config/cachyos-config.fish.
If rather than using the alias shorthand, these aliases were properly defined as functions in /etc/fish/functions/, then the issue of user defined functions not being able to properly override the ones that shipped with the OS would not be an issue, and the logic of allowing the user to customize their shell environment without hard to find roadblocks could be maintained.
Thank you for your consideration.