Skip to content

Instantly share code, notes, and snippets.

@henri
Last active March 25, 2025 23:32
Show Gist options
  • Save henri/bfb800d047a910fe30fec6872c7ee63a to your computer and use it in GitHub Desktop.
Save henri/bfb800d047a910fe30fec6872c7ee63a to your computer and use it in GitHub Desktop.
fish_config_cheat_sheet
# Edits you can make to ~/.config/fish/config.fish
# do not compress the PWD readout
set fish_prompt_pwd_dir_length 0
# remove the fish greeting or set it to something else
set -U fish_greeting ""
# set fish greeting back to default
set -U fish_greeting "Welcome to fish, the friendly interactive shell
Type `help` for instructions on how to use fish"
# fish history manipulation
https://fishshell.com/docs/current/cmds/history.html
history delete --contains "xyz"
# fish start private session - control-d when done
fish --private
# either of these commands below will list your functions
functions --all
functions -a
# remove an alias stored as a function in session
functions --erase <alias-name>
# add an alias 'funcdelete' for removing alias and functions
alias --save funcdelete "functions --erase"
# remove an alias which is saved as a funtion from the config
rm .config/fish/functions/<function-name>.fish
# additional details on fish functions is availible from the link below :
https://fishshell.com/docs/current/cmds/functions.html
# ------------------------------------------------------
# Function to find things in my gist <https://gist.github.com/henri> quickly and open the results in firefox
# If you would like search under a different user name just replace with that name.
$ cat ~/.config/fish/functions/gist_search.fish
function gist_search
firefox "https://gist.github.com/search?q=user%3Ahenri+%22$argv%22&ref=searchresults" ;
end
# usage and example
gist_search <search-term>
gist_search "fish_functions"
# save this functions
funcsave gist_search
# ------------------------------------------------------
# Functions to add to fish for managing things
# these add and remove path functions were found : https://9to5answer.com/how-to-remove-a-path-from-path-variable-in-fish
# addpaths
function addpaths
contains -- $argv $fish_user_paths
or set -U fish_user_paths $fish_user_paths $argv
echo "Updated PATH: $PATH"
end
# removepath
function removepath
if set -l index (contains -i $argv[1] $PATH)
set --erase --universal fish_user_paths[$index]
echo "Updated PATH: $PATH"
else
echo "$argv[1] not found in PATH: $PATH"
end
end
# save these functions
funcsave addpaths; funcsave removepath
# ------------------------------------------------------
# fish function to read input in a loop - one liner
function run-cmd ; while read input ; echo "$input" ; end ; end
# fish function read input (custom prompt) in a loop - one liner
function run-cmd-custom-prompt ; while read --prompt-str "URL > " input ; echo "$input" ; end ; end
# fish function read input (custom prompt) in loop with monitor for jobs command - one liner
function run-cmd-custom-pormpt-plus-jobs-check ; while read --prompt-str "URL > " input ; if [ "$input" = "jobs" ] ; jobs ; else ; echo "$input" ; end ; end ; end
# ------------------------------------------------------
# fish job management functions and tips on job managment
# function to start a background job and accept single argument - with no stdout - one liner
function run-cmd-background ; echo "$argv[1]" 1>/dev/null & ; end
funcsave run-cmd-background
# general job control stuff similar to most shells
jobs # list jobs
fg <job_id> # bring job to the forground
bg <job_id> # background a stopped job
ctrl-z # stop current job
# links to various offical fish documentation relating to job managment
https://fishshell.com/docs/current/language.html#job-control
# specific fish commands for job control links
jobs : https://fishshell.com/docs/current/cmds/jobs.html
fg : https://fishshell.com/docs/current/cmds/fg.html
bg : https://fishshell.com/docs/current/cmds/bg.html
# github source link
https://github.com/fish-shell/fish-shell
##################
## All About !! ##
##################
# fequntly asked fish questions (why bang bang - aka 'bash event designators' not in fish out of the box)
https://fishshell.com/docs/current/faq.html#faq-history
# what are bash event designators
https://www.gnu.org/software/bash/manual/html_node/Event-Designators.html
# apend sudo the start of the command similar to sudo !! in many other shells.
alt-s
# append sudo to the start of a command futher up in the history (up arrow) to find then
alt-s
# if you want an alias
alias !!="eval (history --max=1 | head -n 1)"
# if your hankering for more bang functionality
fisher install oh-my-fish/plugin-bang-bang
# or a more mild version which is bundled with some other nice features
fisher install nickeb96/puffer-fish
# if you don't alrteady have fisher installed
https://github.com/jorgebucaran/fisher
# (C)2023 Henri Shustak
# Released under the GNU GPL v3
# https://gist.github.com/henri/bfb800d047a910fe30fec6872c7ee63a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment