Is fish amazing or is it just that bash is so primitive that we are are easily impressed by simple features?
Fish’s slogan is “finally, a command line shell for the 90s” for a reason
I love it. This kind of attitude actually makes me more inclined to try it.
It’s a bit optimistic, given that fish is still not as good as the transcript panel in Smalltalk-80, running on an Alto in 1980s. There’s a similar reason that I’ve used ‘dragging the computing industry kicking and screaming into the 1980s’ as a subtitle for a lot of talks I’ve given in the last few years.
for me, the #1 fish feature is the fact that I can get a nice shell with all these features out of the box! I’m sure you can get something similar with oh-my-zsh or another package, but on my machines I just apt install fish and I’m done.
apt install fish
Another useful feature are abbreviations: https://fishshell.com/docs/current/cmds/abbr.html. These are like aliases, except that they expanded in place. That is, you type sw but what you get is git switch. That’s pretty useful to keep the cognitive load low, as what you read are full commands. Also helpful when you want to edit command slightly.
This looks nice as a replacement for some of my Fish functions. Thanks for sharing!
I never know such a thing. I might move some alias to abbrev. To keep the cognitive load low.
I’ve been using Fish since 2015, and it’s been great. Fish not being POSIX compatible hasn’t been an issue in practice, though I don’t do a lot of shell scripting to begin with. If somebody is curious about my Fish configuration, you can find it here.
For me the lack of sh-compatible syntax has been a real problem, to the point where I switched to bash at work. Fish does have the best user experience I’ve seen, but the need for specific Fish scripts is a problem, in particular with Nix or any tool that you need to load from your profile. There are wrappersz like bass, but they don’t always work and have overhead.
Just because fish is your interactive shell doesn’t mean that you need to start shell scripts with !/usr/bin/env fish.
I never understood what people is doing all day in their prompt that needs POSIX compatibility. The syntax to call commands is the same.
I think it is mostly a meme or a simple matter of running copy pasted scripts from the web and not understanding how interpreter resolution works or that you can manually define it.
Not necessarily whole scripts. Sometimes you want to paste just a couple commands into the interactive prompt.
But for stuff like Nix, don’t you have to run the setup scripts in your interactive shell with source or equivalent, so they can set environment variables and such?
In Unix, all child processes of a process will inherit the parent’s environment. You should be able to write all your scripts as POSIX compliant (or bash compliant) and run them from inside fish without an issue, as long as you specify the interpreter like so: bash myscript.sh
The problem, if I understood it right (I’ve never used things like Nix) is that these are not things you’re supposed to run, but things you’re supposed to source. I.e. you source whatever.sh so that you get the right environment to do everything else. Sort of like the decade-old env.sh hack for closed-source toolchains and the like, which you source so that you can get all the PATH and LD_LIBRARY_PATH hacks only for this interactive session instead of polluting your .profile with them.
I usually just switch to bash when I need to run a command this way. And honesty I’m more annoyed at commands like these that modify your shell environment and thus force you to use a POSIX-compatible shell, than I am at fish for deliberately trying something different that isn’t POSIX.
Fortunately some commands are designed to output a shell snippet to be used with eval
eval $(foo) # foo prints 'export VAR=bar'
In that case you can pipe output of foo to Fish’s source
foo | source
No, that’s exactly what you can’t do, the code won’t be valid for source-ing (unless those commands specifically output csh-style rather than posix-style script)
Though apparently these days fish does support the most common POSIX-isms…
I mean only the case where you set env variables (like luarocks path)
I also had problems with bass. It was too slow to run in my config.fish. However, I switched to https://github.com/oh-my-fish/plugin-foreign-env and it’s worked perfectly for me. And you don’t need oh-my-fish to use it — I installed it with the plugin manager https://github.com/jorgebucaran/fisher.
Ah, I hadn’t seen this one, if it succeeds to setup Nix then it’s party time!
Not a fish user, but since you’re a Nix user I would also recommend checking out direnv which has fish support. For nix in direnv specifically I would also recommend something like nix-direnv (and several others) which caches and also gcroots environments so overheads are next to negligible when things remain unchanged.
That looks good enough to make me want to try fish again. I had not seen it last time I tried fish. Thanks for pointing it out.
If I were to add something:
and sudo make install
for i in nonexisting/*
The autocompletion is the killer feature for me as well. I used Bash for years without knowing about Ctrl+R history search, and I never learned how to search backwards with it. Fish just searches the history, so you don’t have to decide that before starting to type, and you don’t need to learn how to use the arrow keys to iterate the results. Fish made me instantly more productive than I ever was with Bash.
I would wager that fish style autocomplete is an objective indisputable advantage. Being able to look at the man pages documentation as you type is practically non intrusive and adds value that you don’t have in other shells.
Fish history and bash’ i-search history always felt limited to me. My problem with them is that I can only look at a result a once. Peeking through history never felt smooth to me. Until I found this:
This is the one thing that makes me maintain a fishconfig rather than just using fish as is out of the box. I have also written this https://github.com/plainas/icl to keep frequently used commands neatly organised and documented.
I think fish’s strength is its lack of compatibility, because it can get rid of at least a few of the really bad parts of shell scripting. Unfortunately, its lack of compatibility is also its weakness.
I used fish for a couple months before switching back to bash. For people who like the interactive bits of fish, but for whatever reason would rather use bash, I recommend trying out ble.sh:
I love Fish.
ZSH is very configurable, and with a deep enough pile of plugins and configuration you can achieve much of what Fish does out of the box. The advantage of Fish is, you get all that seamlessly out of the box.
The only two plugins I’ve installed are the tide prompt (reimplementation of powerlevel10k) and fzf for fuzzy history search.
Broken POSIX compat isn’t a huge issue for me. I always had to look up documentation when using those features in bash/zsh, and I can always start a bash subshell if some build script is acting picky.
Reading the comments here, lack of POSIX compat really does seem to be the third rail of acceptance criteria for shells. I think it reflects larger attitudes in software engineering where only a certain amount of “conceptual disruption” is collectively tolerated.
“But BigCorp has gigabytes of POSIX shell scripts!”
Okay, nobody said you have to set your login shell to fish though.
I switched a while ago, and it’s great. I really don’t miss zsh, and I was never a bash user (switched from ksh to zsh in the 1990s). I understand the path dependence that means that we are going to have POSIX shells until the heat death of the universe, but I am so happy to have extricated myself from it.
The last time I tried fish (in ~2012 mind you), I enjoyed the out of the box experience, but I never managed to make its completion menu 2-dimensional. When completing most things, my ZSH config will print out suggestions in enough columns to span my screen, and I can navigate to the option I want quite easily with all directions on the arrow keys. In fish, it would just print a 1-dimensional list, with only up-down navigation. This sounds like a small thing, but my ZSH config already did all the fish stuff like “busted syntax or unknown command is red” and “it completed all the commands I use intelligently”, so I didn’t stick with it.
I think it’s a good option if you are fine with dropping POSIX compliance (eg, copy pasting shell examples from your company’s wiki) and don’t want to invest in setting ZSH up well (many people use oh-my-zsh which is SO slow in my experience).
Check UPDATE 1 to my blog post about ZSH shell setup here:
You can actually make zsh(1) to behave like fish(1) shell.
I like fish(1) shell bit I often use POSIX syntax for loops for various things and it really breaks my way of work.
The first time I used fish, I hated it so much I’ve never given it a second chance.
I just hated how different it was from POSIX shells for interactive use (I’ve never scripted with it). But I think that’s it’s selling point to some people.
To each their own I suppose.
The POSIX incompatibility is less annoying than it used to be. For me, the most annoying things was && and || not working — that’s been fixed since fish 3. I also recently discovered that VAR=foo cmd ... works now, whereas before you had to do env VAR=foo cmd ....
VAR=foo cmd ...
env VAR=foo cmd ...
export VAR=foo works as well
I just installed fish and git sw<Tab> completed slower than zsh.
I also highly recommend checking out xonsh
I think people overestimate how much configuration zsh needs to do “fish things”. You don’t need oh-my-zsh, you don’t need “zsh package managers”, all you really need is zsh-history-substring-search and zsh-syntax-highlighting.
I used mostly-not-configured fish for many years. Fish is nice; I really liked it. A minor con is that if a tool requires a line or two of .rc, you might have to adapt it from a bash example.
A few years back I switched to mostly-not-configured zsh in order to stay somewhat more immersed in POSIX. Looking back, I do value having spent more time with standard syntax for pipelines and subshells and so on. But if you feel like you’ve got all that internalized, go fish.