fish shell
After eleven years of zsh, I have switched to fish as my default shell. I dig its friendliness; this one just feels alive at the prompt. Everything is a function, and it seems elegant. The abbr
feature of fish works for me like alias
from traditional shells, except abbr
auto-expands, which can be startling — I’m still getting used to.
Some caveats: (a) fish shell does not seem to play well for type-setting via LaTeX. I can get by fine on macOS, but not on Ubuntu via WSL; (b) same for running any shell commands from within Vim. If you use these two extensively, then fish may not yet be ready for you.
Below are a few lines from my config.fish
as simple examples:
if status is-interactive
# abbreviations
abbr ds 'date +"%Y-%m-%d %H:%M" | pbcopy'
abbr df 'df -h'
abbr du 'du -h'
abbr fl 'rg --files | fzf'
abbr hk 'make --file=~/scripts/hkp/hkp.make'
abbr mv 'mv -i'
abbr rm 'rm -i'
abbr sp 'make --file=~/Sites/sp.make'
abbr week 'date +%V'
# functions
function subl
/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl $argv
end
function smerge
/Applications/Sublime\ Merge.app/Contents/SharedSupport/bin/smerge $argv
end
function spm
if test -z "$argv[1]"
echo "Please provide a search term."
return 1
end
set result (grep -A 3 "$argv[1]" /Volumes/spm/spm.md)
if test -z "$result"
echo "No matching results found."
return 1
end
grep -A 3 "$argv[1]" /Volumes/spm/spm.md
end
end
The script below automates the transition from zsh to fish in macOS.
#!/usr/bin/env zsh
# 2023 ckunte
# install fish shell (check for brew; install if not)
if test ! $(which brew); then
echo "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
else
echo "Installing fish shell..."
brew install fish
fi
# add fish shell to /etc/shells
echo -n "Adding fish shell path to /etc/shells..."
sudo sh -c 'echo $(which fish) >> /etc/shells'
echo "done."
# restart terminal
echo -n "Restart terminal..."
exec zsh
echo "done."
# make fish shell default
echo -n "Making fish shell default..."
chsh -s 'echo $(which fish)'
echo "done."
# restart terminal
exec fish
# add brew binaries in fish path
# ref: https://fishshell.com/docs/current/cmds/fish_add_path.html
fish_add_path /opt/homebrew/bin
# collect command completions for all commands
fish_update_completions