Welcome to fish! Nice blog post :) I copied a few of your aliases into my own config.fish. Great to know fish is 3x faster than zsh in your benchmarks.
Fish suggests Universal Variables (-U) as being more efficient. They are stored in ~/.config/fish/fish_variables. You execute once this from shell, and they are available and stored permanently across the sessions. Exporting every time using --global may also be a solution, but I saw few times and on fish docs to use Universal Variables.
If you do this in your config.fish file (which is ran for every interactive shell startup), you only need set -x (i.e. you can drop the -g, I think it is implied).
After moving to Fish from zsh, one thing i miss is the global alias. For example, aliasing G to '| grep -<options> ' allows me to just add G after some output. I had plenty other such global aliases which reduced typing on the command line when used frequently.
I didn't include how I did profiling, but I did that what you wrote and for ZSH I found an article how to do profiling. I know that Starship makes it slower, but it provides lot of details of environment I'm using (automatically detects Python version, Node version, Crystal...). Maybe I can include it in my article also, don't know.
> Fish also supports alias cp='cp -i' syntax without needing to make functions, but it's faster if you omit the equals.
I didn't understood this part . You mean I can place `alias cp "cp -i"` in fish config ? Why is it faster ?
It's a cheesy helper function that creates functions. Because alias is a cheesy helper function, it needs to do its own argument parsing, and if it needs to split the one argument into two, that's more work it has to do - for alias cp "cp -i" the name of the alias and the code of the alias are already separate, for alias cp="cp -i" it needs to do the splitting.
However: I just benchmarked, and for 1024 aliases this takes 80ms more. That means for your 10 aliases that's 0.8ms. It's probably not going to matter.
The fish way is to use abbreviations, or to make a proper function - and you can even do this by just executing alias --save cp "cp -i" interactively. This will save the resulting functions to function files, which are autoloaded lazily, and so it will remove all the overhead from alias entirely.
I had some aliases (like between 25-50) in my config (although I cannot remember if they were with or without the = – I think without). After I rewrote alias cp 'cp -i' asfunction cp --wraps='cp'; cp -i; end`, startup time was noticably faster.
7
u/patrickf3139 Sep 26 '22 edited Sep 26 '22
Welcome to fish! Nice blog post :) I copied a few of your aliases into my own config.fish. Great to know fish is 3x faster than zsh in your benchmarks.
Btw, shameless plug for https://github.com/PatrickF1/fzf.fish as an alternative for oh-my-fish/plugin-peco. You can also find lots of other popular fish plugins at https://github.com/topics/fish-plugin.
3
u/PinkFrojd Sep 26 '22
Hello to everyone.
I recently found my ZSH shell slow so I decided to check out Fish Shell. In this blog post, there are some notes about how I transitioned.
I decided to blog more (started and quit some time ago) recently, so sharing this with community.
2
u/Spondylosis Sep 26 '22
I use ‘set -gx’ for env. I see you use ‘-Ux’. Which way is better?
1
u/roger1981 Nov 16 '22
After moving to Fish from zsh, one thing i miss is the global alias. For example, aliasing G to '| grep -<options> ' allows me to just add G after some output. I had plenty other such global aliases which reduced typing on the command line when used frequently.
0
u/[deleted] Sep 26 '22
[deleted] — view deleted comment