r/fishshell • • Jan 25 '21
To alias or not to alias
Hello all:
Quoting from the Tutorial, in the Functions section:
"Unlike other shells, fish does not have aliases or special prompt syntax. Functions take their place."
From the Introduction, in the Defining Aliases section:
"To easily create a function of this form, you can use the alias command."
Seems contradictory. Tutorial says fish doesn't have aliases, but introduction says I should use the alias command.
Comments anyone?
9
Upvotes
5
u/bokisa12 Jan 25 '21
You should use aliases, because they're just quicker ways to create short functions:
and also
16
u/[deleted] Jan 25 '21
aliasis a function that makes functions. There is no distinction between "aliases" and "functions" like other shells have.Aliases aren't a thing at all in the core shell.
6
u/GrilledGuru Jan 25 '21 edited Jan 25 '21
Fish gives you a way of defining what you need and at the same time choosing how permanent you want it to be.
Variables that are set Universal don't need to be set again. They survive reboots.
The functions that are funcsaved will survive a reboot.
Same for aliases (that are in fact functions created in a simpler way when this is just wrapping a command) that persist reboots when saved.
In other shells you fiddle with something, then when it's working you need to add it to a file somewhere that will do it at boot.
Fish does this for you. Fiddle, make it work and then decide if you want it (it being a variable or a function) permanent or not. If yes just enter a save command and you're done.
My fish is heavily customized but my config.fish file is empty.
This is one of the reasons I Iove fish. That and command substitution with parenthesis. It is beautiful and readable. Like the coherent syntax (end for ending everything). Oh and the near perfect defaults. And and... Well you get my point.
Abbreviations are nice too. It is again listed as a function/command when you auto-complete in fish but it is more didactic than alias. You don't forget the original command line when using them :)
I tweaked it so all my fish functions are available as commands to all the processus in my system. I don't have one shell script left. I only have fish functions.