💾 Archived View for tilde.club › ~crmsnbleyd › fish-just-works.gmi captured on 2024-08-31 at 12:34:11. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-03-21)

-=-=-=-=-=-=-

Title: Use the Friendly Interactive Shell today

Date: 2023-10-13 17:56

Disclaimer

I **might** call the tool in question today "Fish shell" in places for the sake of clarity, but that irks me since the `sh` in fish stands also stands for shell. I apologise if it irks you as well.

Completions

To me, this is the killer feature of fish. Fish automatically parses the man pages of installed tools in order to autocomplete when used interactively.

[image: Fish completion in action, showing multiple options on hitting TAB after ls -]

I find this really useful with new tools, and it even shows if the flag needs an argument afterwards or not. You can see some greyed out text to the right of `ls -`, which just shows one possible complete command invocation based on your recent history, which is great if you repeat yourself a lot.

A fun party trick: If you edit a file in a git repository, and go to any other directory in the repository, `git add` will TAB-complete to the changed files with the correct absolute paths.

Add stuff to PATH

No more mucking about with your `.bash_profile`s or `.zshenv`s, try a simple

fish_add_path <your-directory-here>

Which will add it to your PATH permanently :)

Set global variables and delete them

Fish calls them universal variables. If you set variables this way, they are immediately available to use, and persist across restarts of the shell.

set -U HELLO "world" #sets HELLO="world"

You can delete variables just as easily:

set --erase HELLO

Functions

Just pop them in a directory! Fish looks through directories listed in `$fish_function_path` for files ending with .fish. These files should have the same name as the function within.

This is useful as you always know which file the function was defined in. Functions are also the way to add aliases to fish, so there's no extra syntax to learn.

A function can look like this, note how simple it is to understand:

function la
    command ls -la --color=auto $argv
end

Web-based configuration

`fish_config` starts up a little server where you can interactively select and customise things like the prompt and theme. This is way friendlier to do than in other shells, where you have to configure through code and can't see the output until you source the file again.

What I don't really care about

Well, the scripting makes sense. It is not burdened by POSIX compatibility and so can make decisions that make more sense today, like not automatically splitting strings on whitespace, which is a source of constant surprise to newcomers to shell scripting.

automatically splitting strings on whitespace

Features like this are great to have, but why wouldn't you just use an actual programming language, like Python? The python-shshsh module is great for invoking shell commands from within Python, and you can use functions in the middle of pipelines!

python-shshsh

If I _do_ want to write a shell script for portability, I would use POSIX `sh` since you can't be sure the end-user has fish installed.

Back to index