Zsh & Fish Shell Config Cheat Sheet
Quick reference guide for Zsh & Fish Shell: Configuration files, aliases, custom prompts, functions, and environment variables.
CLI & Shell
zsh
fish
shell
Zsh (Z Shell) and Fish (Friendly Interactive Shell) are advanced interactive command-line shells offering auto-suggestions, tab completion, and customizable prompts.
Configuration Files Location
Table
| Shell | User Config File | Global System Config |
|---|---|---|
| Zsh | ~/.zshrc | /etc/zshrc |
| Fish | ~/.config/fish/config.fish | /etc/fish/config.fish |
Syntax Comparison (Zsh vs Fish)
Table
| Task | Zsh Syntax (.zshrc) | Fish Syntax (config.fish) |
|---|---|---|
| Set Env Var | export PATH="$HOME/bin:$PATH" | fish_add_path $HOME/bin |
| Create Alias | alias gs="git status" | alias gs="git status" |
| Define Function | mkcd() { mkdir -p "$1" && cd "$1"; } | function mkcd; mkdir -p $argv[1]; and cd $argv[1]; end |
| If Condition | if [ -d "$DIR" ]; then ... fi | if test -d $DIR; ...; end |
Custom Functions Examples
bash
# Zsh function (~/.zshrc)
extract() {
if [ -f $1 ]; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*) echo "'$1' cannot be extracted" ;;
esac
fi
}
fish
# Fish function (~/.config/fish/functions/extract.fish)
function extract
switch $argv[1]
case '*.tar.gz'
tar xzf $argv[1]
case '*.zip'
unzip $argv[1]
case '*'
echo "'$argv[1]' cannot be extracted"
end
end
Common Pitfalls & Tips
[!WARNING] Fish shell is not POSIX compliant! Standard Bash/Zsh scripts using
export VAR=valorfor i in {1..5}will fail when pasted directly into Fish shell.
[!TIP] Use
Oh My ZshorStarshipprompt (starship init zsh) to instantly add Git branch status and execution timers to your shell prompt.