Skip to main content
  1. Posts/

fish-shell: Tips and Tricks

·366 words·2 mins·

I’ll update this page with anything new 🆕 I find about fish-shell 🐟

Autosuggestions #

Bumped into this one here

Apparently, after you enable some new completions you can run fish_update_completions and fish parses man pages for possible commands and switches.

Setting an alias ’the right way’ without slowing down your shell #

Source

Aliases created with alias will not be available in new shell sessions. If you want them to persist, use

alias -s ...

which will save it to ~/.config/fish/functions/[alias-name].fish

Using alias inside ~/.config/fish/config.fish will slow down your shell start as each alias/function will be eagerly loaded.

To persist aliases across shell sessions, use alias -s, which will create a function and save it to ~/.config/fish/functions. This takes advantage of fish function lazy-loading / autoloading mechanism.

Fish shell cheatsheet #

https://devhints.io/fish-shell

Fish shell scripting manual #

https://developerlife.com/2021/01/19/fish-scripting-manual/

Running in ‘incognito’ mode (Private mode) #

fish calls it Private mode, it sorta works like an incognito/private browser tab by dropping all history. Some contexts when you could use this is decoding base64 Kubernetes secrets in the terminal or logging in while passing some credentials…

> ~ fish --private
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
fish is running in private mode, history will not be persisted.
> ~

You can find out more on the official docu

Inspect and or hack functions #

funced

funced fish_greeting
# opens function in $EDITOR

# hack, hack, hack and done; now you wanna save
funcsave fish_greeting

Manipulate history #

history - show and manipulate command history

Let’s say you fired a command that didn’t work out well and don’t even want to persist it in your history

# look for it
history search --contains "foo"

# delete it
history delete --prefix "foo"

# you can even be more precise if you know what you have to delete
history delete --case-sensitive --exact 'foo'

Check if variable is set #

Source

Test if an environment variable or a local variable from the script was set

if set -q FOOBAR
    echo its set
else
    echo its not set
end

Check if file exists #

Source
if test -e /bin/test
    echo its there
else
    echo its not there
end