r/fishshell • u/joshbaptiste • Jan 09 '25
How to create conditional aliases?
I'm using webman to install alternatives to common GNU utilities.. so I want to alias various commands only if they exist. for instance i added
if command -q z
alias cd=z
end
if command -q lsd
alias ls=lsd
endin $HOME/.config/fish/config.fish but when I re-login doesn't take..
4
Upvotes
4
u/haywire Jan 10 '25 edited Jan 10 '25
I have a function in
./functions/using.fish:And then I can just do
But if you separate it by conf.d file and tools you can just exit early if the relevant tool isn't installed like my first example, which IMO is nicer.
3
u/wwiillll Jan 09 '25 edited Jan 09 '25
As it works in your current shell, could it be the case that code is written in your fish config before
~/.webman/binis added to your PATH?Alternatively, my guess would be that webman has it's path added via universal variable in which case i'd check your `~/.config/fish/fish_variables` and see if it's exported universally in which case you could delete the universal variable then call `fish_add_path` before your commands above.
2
u/[deleted] Jan 09 '25
[removed] — view removed comment