Skip to content
All writing

Switching to Fish, Part 2: Functions Instead of Alias Soup

Aliases break the moment you need a conditional or an argument. Fish functions are first-class, readable, and take five minutes to learn.

#articlesdev-toolsworkflowfish

Part 1 covered the instant wins. Part 2 is where fish changes how you write tooling: real functions instead of aliases.

Bash pushes you toward alias for everything, and aliases fall apart the second you need a conditional or an argument. Fish gives you functions with a syntax that reads like what it does:

function ws --description 'jump to a project by name'
    if test (count $argv) -eq 0
        cd ~/WWorkspace
    else
        cd (find ~/WWorkspace/projects -maxdepth 2 -iname "$argv[1]" -type d | head -1)
    end
end

Save it as ~/.config/fish/functions/ws.fish and it autoloads. No sourcing, no reload step. The filename is the registration.

Try writing that conditional cd as a POSIX alias and see how far you get.

Missed the start? Read part 1. Next: part 3 on self-loading completions and the one real tradeoff.

Get new posts by email

New writing in your inbox. Unsubscribe anytime.