6 ms·
As a long-time power user of fish for 6+ years, I cannot live without it. It's easily in my top 5 most game-changing upgrades to my dev environment. (up there w
by nikisweeting 6y ago
As a long-time power user of fish for 6+ years, I cannot live without it. It's easily in my top 5 most game-changing upgrades to my dev environment. (up there with a clipboard history manager and TabNine for code autocompletion)
Over the years I've amassed hundreds of fish functions for common tasks on my machines, https://github.com/pirate/fish-functions https://github.com/pirate/fish-functions. I loved it so much I started using it to write devops/deployment scripts instead of bash. That was a mistake.
It has some serious limitations as a scripting language, namely lack of proper subshell support and background process control. The relevant issues have been open for years with no clear resolution in sight. (which is fair, these are very hard problems and it's an open-source project with finite resources)
That's fine though, it's still my favorite interactive shell for use in a Terminal. I just make sure to write any script longer than a few lines in Bash. https://github.com/pirate/bash-utils https://github.com/pirate/bash-utils
- Osiris 6y agoI've been using fish for longer than I can remember, but I almost never write fish functions. The out of the box experience is already much better than bash/zsh (out of the box, not including plugins/etc). I also prefer the basic syntax for things like for and while looks on the command line, the way they get formatted. With bash I always had to look up the syntax because I didn't use it much. Fish, I barely have to look up things because they are pretty intuitive, for the most part. Also, no adding `export X=Y` to your .bashrc because you can just `set -U` and it automatically saves it between sessions.
- mattgreenrocks 6y agoThe best part about fish is you don't have to configure it much to be productive in it. It is really nice that the fish maintainers think hard about what should be configurable, and what sane defaults should be. This is not as common as it should be in OSS. Contrast with zsh, which has a billion knobs to tweak, and the consensus is that everyone should install a huge "community dotfile framework" (whatever that means) consisting of tons of opaque aliases and settings, some of which might make your shell startup lag. More to a specific point: I haven't had much of an issue with fish's subshell/backgrounding control. That doesn't mean that there aren't issues, just that my interactive use doesn't trip into them. I will note that you can write an async git prompt using nothing but fish itself, which I consider an advanced use case for a shell. Check it out: https://github.com/mattgreen/lucid.fish https://github.com/mattgreen/lucid.fish
- nikisweeting 6y agoI ended up implementing my own background process management for fish here, it uses bash to fork a subshell with fish inside of it, which seems to solve all the problems I encountered. https://github.com/pirate/fish-functions/blob/master/background.fish https://github.com/pirate/fish-functions/blob/master/backgro... https://github.com/pirate/fish-functions/blob/master/progress_await.fish https://github.com/pirate/fish-functions/blob/master/progres... https://github.com/pirate/fish-functions/blob/master/signal.fish https://github.com/pirate/fish-functions/blob/master/signal.... https://github.com/pirate/fish-functions/blob/master/fork https://github.com/pirate/fish-functions/blob/master/fork Usage: background progress_await compiling_task_finished g++ ... some slow command signal compiling_task_finished This allows the progress bar to truly run at the same time as the g++ command and receive a signal from the fg process when it's time to complete, something a simple & does not let you do in fish. I've collected more details on Fish's issues here for anyone interested: https://github.com/pirate/fish-functions#issues-with-fish https://github.com/pirate/fish-functions#issues-with-fish
- mattgreenrocks 6y agoI like your semaphore idea a lot! Might be a good primitive to put in fish.
- Barrin92 6y agoand if you need to configure something, it actually has a really pleasant ui that can be called with `fish_config`.
- santa_boy 6y agoVery true. I have been using fish for the last five years without really learning the shell. The auto-complete itself feels so good and makes me productive. Confession: I haven't taken pains to learn any shell after that. Almost similar to why I never took to try out VSCode after getting used to Sublime Text. So many demos, videos etc. quite tempt me to try out VSCode but still haven't ever got to it) The only thing that I took note was to install https://github.com/oh-my-fish/oh-my-fish https://github.com/oh-my-fish/oh-my-fish every time I setup a machine. Would be great to know of any quick to learn fish-hacks or fish-for-dummies resources
- OhSoHumble 6y agoThe lack of associative arrays is what does it for me.
- kstrauser 6y agoFish functions are just gorgeous, and what made me drop Zsh like a hot potato. Suppose you want to make an automatically loaded (that is, not defined in the shell's rc file) function called foo. Here's how you do it: - Make a file named ~/.config/fish/functions/foo.fish - Inside it, define a function named "foo" That's it. Now when you open a new shell and try to run the command "foo", Fish will look for the file named foo.fish in that directory, load and execute it, then call the foo function from in it. Now, create an autoloaded function in Zsh or Bash without looking at a man page. There are a million little niceties like that where I'd assumed that a certain task had to be complicated because every shell I'd used before had made it complicated, but then Fish came up with a nice convention for making it simple. Want to make a function to dynamically set your shell's prompt? Create a function named "fish_prompt" in the file ~/.config/fish/functions/fish_prompt.fish. Ta-da - turns out it doesn't have to be a pain in the neck to do that. I completely agree about using it as a scripting language, though. It's great for making functions for your interactive shell, but stick with sh or bash (or Python) for writing more sophisticated stuff.
- moonchild 6y agofor fname in $(ls ~/.config/zsh/functions); do source $fname; done :)
- skizziepop 6y agofor fname in ~/.config/zsh/functions/*; do source $fname; done will prevent issues with special chars and spaces in filenames
- OJFord 6y agoWhen are you going to run that? GP is talking about JIT loaded functions: 'that is, not defined in your shell's rc file'.
- lilyball 6y agoThat’s the exact opposite. That’s eagerly loading all defined functions. autoloading means the function isn’t loaded until it’s used.
- hnlmorg 6y ago> It has some serious limitations as a scripting language, namely lack of proper subshell support and background process control. The relevant issues have been open for years with no clear resolution in sight. (which is fair, these are very hard problems and it's an open-source project with finite resources) You say that but I'd been writing a shell in my spare time and I solved those problems over the course of a few weeks. For me though, they were important problems to solve because few other lesser mainstream / alternative shells addressed those problems and thus they became all the more tantalising problems to solve. In Fish's case, they might be lower priority jobs. Unfortunately though, I also broke job control support again earlier this year and haven't had the spare time during the pandemic (my kids have been understandably more demanding of my time now that I'm working from home) to fix it. So I can't demo that particular feature as working. As an aside, this is also a good lesson to everyone to write robust tests....
- nikisweeting 6y agoIn particular I think Fish struggles with backgrounding of functions (backgrounding of non-fish commands seems to work fine). # these behave the same in bash but differently in fish some_command & # this works some_function & # this does not The relevant issues are listed here if you're curious about why it's difficult to implement this in Fish: https://github.com/pirate/fish-functions#issues-with-fish https://github.com/pirate/fish-functions#issues-with-fish
- hnlmorg 6y agoThanks for the link. Makes sense that if Fish doesn't fork itself and isn't multi-threaded then that would be a difficult feature to implement. I had the same consideration right at the conception of my project: fork or multi-thread? I went with the latter. But my shell diverges quite a bit from the typical design a shell would take so there's a lot of reasons it's sub-optimal compared to the excellent work the Fish guys have done with their shell.
- koverda 6y agoThis is off topic, but I'm curious about your top 5 most game-changing upgrades to your dev environment. Just set up TabNine, what are the other 3?
- nikisweeting 6y agoClipboard history manager (I use Alfred's on macOS), TabNine, Fish Shell, ripgrep/ag, and SublimeText's jump to definition & "show usages" for all symbols in the current project.
- StavrosK 6y agoI will add fzf with the fish plug in, entr, z...
- nikisweeting 6y agoI personally use autojump but fzf is excellent as well.
- dmos62 6y agoI've a similar collection of "functions", but I implemented them just as plain bash/sh scripts in my ~/bin. I think putting your functions into regular executables on the path would have been more portable. That way you wouldn't need to call them from a fish shell to run them (you can still use fish scripting language if you like).
- nikisweeting 6y agoAgreed, I've been gradually migrating all the big ones to https://github.com/pirate/bash-utils https://github.com/pirate/bash-utils for the past few years.
- esseti 6y agowhat are the most used functions in fish? i'm quite new, i find `z` very useful to move in folders