Skip to content

Instantly share code, notes, and snippets.

@wilhelm-murdoch
Last active September 30, 2016 21:29
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save wilhelm-murdoch/6162503 to your computer and use it in GitHub Desktop.
Save wilhelm-murdoch/6162503 to your computer and use it in GitHub Desktop.
My personal fish shell setup for iTerm 2 ...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Ansi 0 Color</key>
<dict>
<key>Blue Component</key>
<real>0.16470588743686676</real>
<key>Green Component</key>
<real>0.20784313976764679</real>
<key>Red Component</key>
<real>0.23921568691730499</real>
</dict>
<key>Ansi 1 Color</key>
<dict>
<key>Blue Component</key>
<real>0.36078432202339172</real>
<key>Green Component</key>
<real>0.36078432202339172</real>
<key>Red Component</key>
<real>0.80392158031463623</real>
</dict>
<key>Ansi 10 Color</key>
<dict>
<key>Blue Component</key>
<real>0.13333334028720856</real>
<key>Green Component</key>
<real>0.66666668653488159</real>
<key>Red Component</key>
<real>0.53333336114883423</real>
</dict>
<key>Ansi 11 Color</key>
<dict>
<key>Blue Component</key>
<real>0.364705890417099</real>
<key>Green Component</key>
<real>0.65490198135375977</real>
<key>Red Component</key>
<real>1</real>
</dict>
<key>Ansi 12 Color</key>
<dict>
<key>Blue Component</key>
<real>0.92156863212585449</real>
<key>Green Component</key>
<real>0.80784314870834351</real>
<key>Red Component</key>
<real>0.52941179275512695</real>
</dict>
<key>Ansi 13 Color</key>
<dict>
<key>Blue Component</key>
<real>0.0</real>
<key>Green Component</key>
<real>0.40000000596046448</real>
<key>Red Component</key>
<real>0.60000002384185791</real>
</dict>
<key>Ansi 14 Color</key>
<dict>
<key>Blue Component</key>
<real>0.87058824300765991</real>
<key>Green Component</key>
<real>0.76862746477127075</real>
<key>Red Component</key>
<real>0.69019609689712524</real>
</dict>
<key>Ansi 15 Color</key>
<dict>
<key>Blue Component</key>
<real>0.73333334922790527</real>
<key>Green Component</key>
<real>0.80000001192092896</real>
<key>Red Component</key>
<real>0.86666667461395264</real>
</dict>
<key>Ansi 2 Color</key>
<dict>
<key>Blue Component</key>
<real>0.50196081399917603</real>
<key>Green Component</key>
<real>0.68627452850341797</real>
<key>Red Component</key>
<real>0.52549022436141968</real>
</dict>
<key>Ansi 3 Color</key>
<dict>
<key>Blue Component</key>
<real>0.35686275362968445</real>
<key>Green Component</key>
<real>0.68235296010971069</real>
<key>Red Component</key>
<real>0.90980392694473267</real>
</dict>
<key>Ansi 4 Color</key>
<dict>
<key>Blue Component</key>
<real>0.92941176891326904</real>
<key>Green Component</key>
<real>0.58431375026702881</real>
<key>Red Component</key>
<real>0.39215686917304993</real>
</dict>
<key>Ansi 5 Color</key>
<dict>
<key>Blue Component</key>
<real>0.52941179275512695</real>
<key>Green Component</key>
<real>0.72156864404678345</real>
<key>Red Component</key>
<real>0.87058824300765991</real>
</dict>
<key>Ansi 6 Color</key>
<dict>
<key>Blue Component</key>
<real>0.87058824300765991</real>
<key>Green Component</key>
<real>0.76862746477127075</real>
<key>Red Component</key>
<real>0.69019609689712524</real>
</dict>
<key>Ansi 7 Color</key>
<dict>
<key>Blue Component</key>
<real>0.60000002384185791</real>
<key>Green Component</key>
<real>0.66666668653488159</real>
<key>Red Component</key>
<real>0.73333334922790527</real>
</dict>
<key>Ansi 8 Color</key>
<dict>
<key>Blue Component</key>
<real>0.26666668057441711</real>
<key>Green Component</key>
<real>0.26666668057441711</real>
<key>Red Component</key>
<real>0.3333333432674408</real>
</dict>
<key>Ansi 9 Color</key>
<dict>
<key>Blue Component</key>
<real>0.20000000298023224</real>
<key>Green Component</key>
<real>0.3333333432674408</real>
<key>Red Component</key>
<real>0.80000001192092896</real>
</dict>
<key>Background Color</key>
<dict>
<key>Blue Component</key>
<real>0.10980392247438431</real>
<key>Green Component</key>
<real>0.10980392247438431</real>
<key>Red Component</key>
<real>0.10980392247438431</real>
</dict>
<key>Bold Color</key>
<dict>
<key>Blue Component</key>
<real>1</real>
<key>Green Component</key>
<real>1</real>
<key>Red Component</key>
<real>1</real>
</dict>
<key>Cursor Color</key>
<dict>
<key>Blue Component</key>
<real>0.93725490570068359</real>
<key>Green Component</key>
<real>0.73333334922790527</real>
<key>Red Component</key>
<real>0.88627451658248901</real>
</dict>
<key>Cursor Text Color</key>
<dict>
<key>Blue Component</key>
<real>0.0</real>
<key>Green Component</key>
<real>0.0</real>
<key>Red Component</key>
<real>0.0</real>
</dict>
<key>Foreground Color</key>
<dict>
<key>Blue Component</key>
<real>0.86666667461395264</real>
<key>Green Component</key>
<real>0.93333333730697632</real>
<key>Red Component</key>
<real>0.86666667461395264</real>
</dict>
<key>Selected Text Color</key>
<dict>
<key>Blue Component</key>
<real>1</real>
<key>Green Component</key>
<real>1</real>
<key>Red Component</key>
<real>1</real>
</dict>
<key>Selection Color</key>
<dict>
<key>Blue Component</key>
<real>0.30241936445236206</real>
<key>Green Component</key>
<real>0.30241936445236206</real>
<key>Red Component</key>
<real>0.30241936445236206</real>
</dict>
</dict>
</plist>
cd $HOME
set PATH /usr/bin
set PATH /bin $PATH
set PATH /usr/sbin $PATH
set PATH /sbin $PATH
set PATH /usr/local/bin $PATH
set PATH /usr/local/sbin $PATH
set PATH $HOME/.rbenv/shims $PATH
set PATH $HOME/bin $PATH
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/sub
set -g VIRTUALFISH_HOME $HOME/Sites/venvs
set -g VIRTUALFISH_COMPAT_ALIASES workon
set fish_git_dirty_color red
set fish_git_not_dirty_color magenta
. $HOME/.config/fish/virtual.fish
. $HOME/.config/fish/prompt.fish
function parse_git_branch
if test -d .git
set -l branch (git branch 2> /dev/null | grep -e '\* ' | sed 's/^..\(.*\)/\1/')
set -l git_diff (git diff)
if test -n "$git_diff"
printf ' (%s%s%s)' (set_color $fish_git_dirty_color) $branch (set_color normal)
else
printf ' (%s%s%s)' (set_color $fish_git_not_dirty_color) $branch (set_color normal)
end
end
end
function fish_prompt
if [ -z $VIRTUAL_ENV ]
printf '%s%s%s%s\nλ: ' (set_color $fish_color_cwd) (pwd) (set_color normal) (parse_git_branch)
else
printf '%s(%s)%s %s%s%s%s%s\nλ: ' (set_color -b blue black) (basename "$VIRTUAL_ENV") (set_color normal) (set_color $fish_color_cwd) (pwd) (set_color normal) (parse_git_branch)
end
end
# VirtualFish
# A Virtualenv wrapper for the Fish Shell based on Doug Hellman's virtualenvwrapper
if not set -q VIRTUALFISH_HOME
set -g VIRTUALFISH_HOME $HOME/.virtualenvs
end
if not set -q VIRTUALFISH_ACTIVATION_FILE
set -g VIRTUALFISH_ACTIVATION_FILE .venv
end
if set -q VIRTUALFISH_COMPAT_ALIASES
function workon
vf activate $argv[1]
end
function deactivate
vf deactivate
end
end
function vf --description "VirtualFish: fish plugin to manage virtualenvs"
# copy all but the first argument to $scargs
set -l sc $argv[1]
set -l funcname "__vf_$sc"
set -l scargs
if test (count $argv) -gt 1
set scargs $argv[2..-1]
end
if functions -q $funcname
eval $funcname $scargs
else
echo "The subcommand $sc is not defined"
end
end
function __vf_activate --description "Activate a virtualenv"
# check arguments
if [ (count $argv) -lt 1 ]
echo "You need to specify a virtualenv."
return 1
end
if not [ -d $VIRTUALFISH_HOME/$argv[1] ]
echo "The virtualenv $argv[1] does not exist."
echo "You can create it with mkvirtualenv."
return 2
end
#Check if a different env is being used
if set -q VIRTUAL_ENV
vf deactivate
end
emit virtualenv_will_activate
emit virtualenv_will_activate:$argv[1]
set -gx VIRTUAL_ENV $VIRTUALFISH_HOME/$argv[1]
set -g _VF_EXTRA_PATH $VIRTUAL_ENV/bin
set -gx PATH $_VF_EXTRA_PATH $PATH
# hide PYTHONHOME
if set -q PYTHONHOME
set -g _VF_OLD_PYTHONHOME $PYTHONHOME
set -e PYTHONHOME
end
emit virtualenv_did_activate
emit virtualenv_did_activate:(basename $VIRTUAL_ENV)
end
function __vf_deactivate --description "Deactivate the currently-activated virtualenv"
emit virtualenv_will_deactivate
emit virtualenv_will_deactivate:(basename $VIRTUAL_ENV)
# find elements to remove from PATH
set to_remove
for i in (seq (count $PATH))
if contains $PATH[$i] $_VF_EXTRA_PATH
set to_remove $to_remove $i
end
end
# remove them
for i in $to_remove
set -e PATH[$i]
end
# restore PYTHONHOME
if set -q _VF_OLD_PYTHONHOME
set -gx PYTHONHOME $_VF_OLD_PYTHONHOME
set -e _VF_OLD_PYTHONHOME
end
# remove autoactivated flag
if set -q VF_AUTO_ACTIVATED
set -e VF_AUTO_ACTIVATED
end
emit virtualenv_did_deactivate
emit virtualenv_did_deactivate:(basename $VIRTUAL_ENV)
set -e VIRTUAL_ENV
end
function __vf_new --description "Create a new virtualenv"
set envname $argv[-1]
set -e argv[-1]
virtualenv $argv $VIRTUALFISH_HOME/$envname
set vestatus $status
if [ $vestatus -eq 0 ]; and [ -d $VIRTUALFISH_HOME/$envname ]
vf activate $envname
if test -f $VIRTUALFISH_HOME/global_requirements.txt
pip install --download-cache $VIRTUALFISH_HOME/_pip_cache -r $VIRTUALFISH_HOME/global_requirements.txt
end
else
echo "Error: The virtualenv wasn't created properly."
echo "virtualenv returned status $vestatus."
return 1
end
end
function __vf_rm --description "Delete a virtualenv"
if not [ (count $argv) -eq 1 ]
echo "You need to specify exactly one virtualenv."
return 1
end
if set -q VIRTUAL_ENV; and [ $argv[1] = $VIRTUAL_ENV ]
echo "You can't delete a virtualenv you're currently using."
return 1
end
echo "Removing $VIRTUALFISH_HOME/$argv[1]"
rm -rf $VIRTUALFISH_HOME/$argv[1]
end
function __vf_ls --description "List all of the available virtualenvs"
pushd $VIRTUALFISH_HOME
for i in */bin/python
echo $i
end | sed "s|/bin/python||"
popd
end
function __vf_cd --description "Change directory to currently-activated virtualenv"
if set -q VIRTUAL_ENV
cd $VIRTUAL_ENV
else
echo "Cannot locate an active virtualenv."
end
end
function __vf_connect --description "Connect this virtualenv to the current directory"
if set -q VIRTUAL_ENV
basename $VIRTUAL_ENV > $VIRTUALFISH_ACTIVATION_FILE
else
echo "No virtualenv is active."
end
end
function __vf_requirements --description "Edit the global requirements file for all virtualenvs"
eval $EDITOR $VIRTUALFISH_HOME/global_requirements.txt
pushd $VIRTUALFISH_HOME
for i in */bin/pip
eval $i install --download-cache $VIRTUALFISH_HOME/_pip_cache -r $VIRTUALFISH_HOME/global_requirements.txt
end
end
################
# Autocomplete
# Based on https://github.com/zmalltalker/fish-nuggets/blob/master/completions/git.fish
begin
function __vfcompletion_needs_command
set cmd (commandline -opc)
if test (count $cmd) -eq 1 -a $cmd[1] = 'vf'
return 0
end
return 1
end
function __vfcompletion_using_command
set cmd (commandline -opc)
if test (count $cmd) -gt 1
if test $argv[1] = $cmd[2]
return 0
end
end
return 1
end
# add completion for subcommands
for sc in (functions -a | sed -n '/__vf_/{s///g;p;}')
set -l helptext (functions "__vf_$sc" | head -n 1 | sed -E "s|.*'(.*)'.*|\1|")
complete -x -c vf -n '__vfcompletion_needs_command' -a $sc -d $helptext
end
complete -x -c vf -n '__vfcompletion_using_command activate' -a "(vf ls)"
complete -x -c vf -n '__vfcompletion_using_command rm' -a "(vf ls)"
end
################
# Automatic activation
function __vfsupport_auto_activate --on-variable PWD
if status --is-command-substitution # doesn't work with 'or', inexplicably
return
end
# find an auto-activation file
set -l vfeloc $PWD
while test ! "$vfeloc" = "" -a ! -f "$vfeloc/$VIRTUALFISH_ACTIVATION_FILE"
# this strips the last path component from the path.
set vfeloc (echo "$vfeloc" | sed 's|/[^/]*$||')
end
set -l newve
if [ -f "$vfeloc/$VIRTUALFISH_ACTIVATION_FILE" ]
set newve (cat "$vfeloc/$VIRTUALFISH_ACTIVATION_FILE")
end
# apply new venv if changed
set -l currentve
if set -q VIRTUAL_ENV
set currentve (basename "$VIRTUAL_ENV")
end
if [ "$newve" != "" -a "$newve" != "$currentve" ]
vf activate $newve
set -g VF_AUTO_ACTIVATED yes
end
# deactivate venv if it was autoactivated before and we've moved out of it
if [ "$newve" = "" -a "$VF_AUTO_ACTIVATED" = "yes" ]
vf deactivate
end
end
#automatically activate if started in a directory with a virtualenv in it
__vfsupport_auto_activate
@wilhelm-murdoch
Copy link
Author

About


Started using this awesome new terminal shell a short while ago. I customised the prompt to tell me which Git branch I'm currently on and its state. Also, added virtualenv wrapper commands so you can easily switch among different projects.

Preview


Prompt Preview

Instructions


  1. Install Fish
  2. Place all the following files in $HOME/.config/fish/
  3. Get a nice tiled background. I got mine from Subtlepatterns
  4. Load the Arthur colour preset for iTerm2.

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