Skip to content

Instantly share code, notes, and snippets.

@idleberg
Last active March 27, 2024 22:37
Show Gist options
  • Save idleberg/9c7aaa3abedc58694df5 to your computer and use it in GitHub Desktop.
Save idleberg/9c7aaa3abedc58694df5 to your computer and use it in GitHub Desktop.
Instructions on how to install Fish shell on Mac OS X, including Oh My Fish!. Also includes several useful functions.

Installation

  1. Install fish via Brew
  2. Optionally install Oh My Fish!
  3. Add fish to known shells
  4. Set default shell to fish
brew install fish  
curl -L https://get.oh-my.fish | fish
sudo bash -c 'echo $(which fish) >> /etc/shells'
chsh -s $(which fish)

Aliases

# shortcuts
alias .. "cd .."
alias cd.. "cd .."
alias ll "ls -la"

# modern tooling (see https://github.com/ibraheemdev/modern-unix)
alias ls exa
alias cat bat

# typos
alias gti git

Functions

Add any the following functions to ~/.config/fish/config.fish

sudo bang bang

Repeat previous command with administrator rights

function sudo
    if test "$argv" = !!
        eval command sudo $history[1]
    else
        command sudo $argv
    end
end

dropbox

Quickly access your DropBox folder

function db
    set user $HOME
    cd "$HOME/Dropbox"
end

icloud drive

Quickly access your iCloud Drive folder

function icd
    set user $HOME
    cd "$HOME/Library/Mobile\ Documents/com\~apple\~CloudDocs"
end

docs

Quickly access your documents folder

function docs    
	switch (uname -s)
    case Darwin Linux FreeBSD NetBSD DragonFly
		set documents $HOME/Documents
	case '*'
		set cygwin (eval uname -o)  
    		if test $cygwin = "Cygwin"
    			set documents (eval cygpath -O)
    		end    
    		return
    	end    
    	cd $documents
    end
end

os

Return platform name

function os
    switch (uname -s)
    case Darwin Linux FreeBSD NetBSD DragonFly
        eval command uname -s
    case "*"`
        switch (uname -s)
        case Cygwin
            eval command uname -s
        case "*"
            eval echo "undefined"
        end
    end
end

git tag

Simplify the creation and deletion of Git tags

function tag
    if count $argv > /dev/null
        if test $argv[1] = "-d"
            # delete tag if provided
            if test $argv[2]
                eval command git tag -d $argv[2]
                command git push origin :refs/tags/$argv[2]
            end
        else
            # create new tag and push
            eval command git tag -a $argv[1] -m $argv[1]
            command git push --tags
        end
    else
    	# list tags
        command git tag
    end
end

nvm

There are plenty of guides on how to get nvm running in Fish. This is the one that works for me.

  1. Install bass
  2. Add the following to config.fish
# This is what you often find online...
function nvm
    bass source (brew --prefix nvm)/nvm.sh --no-use ';' nvm $argv
end

# ...however, for me it doesn't work without the following line
set -Ux NVM_DIR ~/.nvm
@BryanJBryce
Copy link

echo /usr/local/bin/fish >> /etc/shells gives me a:

-bash: /etc/shells: Permission denied

@imodium
Copy link

imodium commented Dec 12, 2018

echo /usr/local/bin/fish >> /etc/shells gives me a:

-bash: /etc/shells: Permission denied

not in administrator ? -> sudo su and echo /usr/local/bin/fish >> /etc/shells

@kepi0809
Copy link

kepi0809 commented Jan 8, 2020

wanted to make the same in the VS Code terminal, in that case you have to add to your settings.json (cmd + shift + p then user settings) the following line: "terminal.integrated.shell.osx": "/usr/local/bin/fish".
If it still doesn't work write which fish to the terminal and adjust your path accordingly.

Thanks for these instructions 👍

@jindalAnuj
Copy link

Hi, Sorry but new to command line tools. Last time i changes my terminal to zsh my few commands stop working. Will it be the case for fish also. If yes then is there any workaround for that?

@Andrewg1263
Copy link

Andrewg1263 commented Feb 17, 2022

For Mac M1, my fish installation path is: /opt/homebrew/bin/fish
Replaced the path in 3 and 4 works for me.

@jadnhm
Copy link

jadnhm commented Feb 23, 2022

I had the same issue @Andrewg1263

I did `sudo bash -c 'echo '(which fish)' >> /etc/shells'

$ sudo bash -c 'echo '(which fish)' >> /etc/shells'
$ cat /etc/shells
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.

/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
/opt/homebrew/bin/fish

@ar4s-eth
Copy link

ar4s-eth commented Apr 6, 2022

cd..? Just try to type ..

oh em gee... apparently just "~" works the same.

@dpeachpeach
Copy link

I also had the same issue as @Andrewg1263 and @jadnhm.
It seems as if this gist hasn't been updated to support instructions for ARM architecture.
I forked the gist and revised it to include a quick fix for the issue, if you want to update yours accordingly.

https://gist.github.com/dpeachpeach/07444779df15cadc87ef88d8b381c4c8

@Nilpo
Copy link

Nilpo commented Oct 9, 2022

I also had the same issue as @Andrewg1263 and @jadnhm. It seems as if this gist hasn't been updated to support instructions for ARM architecture. I forked the gist and revised it to include a quick fix for the issue, if you want to update yours accordingly.

https://gist.github.com/dpeachpeach/07444779df15cadc87ef88d8b381c4c8

This is no longer required. The above instructions have been updated to work on any architecture.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment