function fry-install --description 'Install rubies (requires ruby-build)'
  if not test (which ruby-build)
    echo 'fatal: This feature requires ruby-build'
    return 1
  end

  if test (count $argv) -eq 0
    echo 'usage: fry install <ruby>'
    echo
    echo 'Available rubies:'
    ruby-build --definitions
    return
  end

  set -l name $argv[1]

  switch $name
    case (ruby-build --definitions)
    case '*'
      echo "error: unknown ruby `$name'"
      echo 'usage: fry install <ruby>'
      echo
      echo 'Available rubies:'
      ruby-build --definitions
      return 1
  end

  ruby-build $name $fry_rubies/$name
end

Use contains instead of switch

function fry-install --description 'Install rubies (requires ruby-build)'
  if not test (which ruby-build)
    echo 'fatal: This feature requires ruby-build'
    return 1
  end

  if test (count $argv) -eq 0
    echo 'usage: fry install <ruby>'
    echo
    echo 'Available rubies:'
    ruby-build --definitions
    return
  end

  set -l name $argv[1]

  if not contains -- $name (ruby-build --definitions)
    echo "error: unknown ruby `$name'"
    echo 'usage: fry install <ruby>'
    echo
    echo 'Available rubies:'
    ruby-build --definitions
    return 1
  end

  ruby-build $name $fry_rubies/$name
end


function increase-tmp
  set_color --bold brmagenta
  echo "Running command: sudo mount -o remount,size=7G,noatime /tmp"
  set_color normal
  echo "Current size: "
  df --human-readable --output='size,target' --block-size=M | grep /tmp
  sudo mount -o remount,size=7G,noatime /tmp
  echo "New size: "
  df --human-readable --output='size,target' --block-size=M | grep /tmp
end


#!/usr/bin/env fish

# PATH

if test -d /usr/local/sbin
  set PATH /usr/local/sbin $PATH
end

if test -x /usr/local/bin/cargo
  set PATH ~/.cargo/bin $PATH
end

if test -x /usr/local/bin/yarn
  set PATH ~/.yarn/bin ~/.config/yarn/global/node_modules/.bin $PATH
end

set EDITOR nvim
set VISUAL nvim

if test -n "$NVIM_LISTEN_ADDRESS"
  set EDITOR nvr
  set VISUAL nvr
  if test -x /usr/local/bin/page
    set PAGER /usr/local/bin/page
  end
end

if not functions -q fisher
  set -q XDG_CONFIG_HOME; or set XDG_CONFIG_HOME ~/.config
  curl https://git.io/fisher --create-dirs -sLo $XDG_CONFIG_HOME/fish/functions/fisher.fish
  fish -c fisher
end

Fix EDITOR variable inside neovim session

#!/usr/bin/env fish

# PATH

if test -d /usr/local/sbin
  set PATH /usr/local/sbin $PATH
end

if test -x /usr/local/bin/cargo
  set PATH ~/.cargo/bin $PATH
end

if test -x /usr/local/bin/yarn
  set PATH ~/.yarn/bin ~/.config/yarn/global/node_modules/.bin $PATH
end

if test -z "$NVIM_LISTEN_ADDRESS"
  set EDITOR nvim
  set VISUAL nvim
end

if test -n "$NVIM_LISTEN_ADDRESS"
  if test -x /usr/local/bin/page
    set PAGER /usr/local/bin/page
  end
end

if not functions -q fisher
  set -q XDG_CONFIG_HOME; or set XDG_CONFIG_HOME ~/.config
  curl https://git.io/fisher --create-dirs -sLo $XDG_CONFIG_HOME/fish/functions/fisher.fish
  fish -c fisher
end


if [ (uname -s) = 'Darwin' -a -f '/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl' ]
    set --global --export EDITOR 'subl -w'
else
    set --global --export EDITOR vim
end

Use full parameter name for clarity

if [ (uname -s) = 'Darwin' -a -f '/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl' ]
    set --global --export EDITOR 'subl --wait'
else
    set --global --export EDITOR vim
end


# Language
set -gx LANGUAGE en_US.UTF-8
set -gx LANG $LANGUAGE
set -gx LC_ALL $LANGUAGE
set -gx LC_CTYPE $LANGUAGE

# Editor
set -gx EDITOR vim
set -gx CVSEDITOR $EDITOR
set -gx SVN_EDITOR $EDITOR
set -gx GIT_EDITOR $EDITOR

# Pager
set -gx PAGER less

# XDG
set -gx XDG_CACHE_HOME $HOME/.cache
set -gx XDG_CONFIG_HOME $HOME/.config
set -gx XDG_DATA_HOME $HOME/.local/share

# Golang
set -gx GOPATH $HOME/work
set -gx PATH $PATH $GOPATH/bin

# fzf
set -gx FZF_DEFAULT_OPTS --reverse
set -gx FZF_LEGACY_KEYBINDINGS 0

# ghq
set -gx GHQ_SELECTOR fzf

# rbenv
rbenv init - | source

# pyenv
status --is-interactive; and source (pyenv init -|psub)

# direnv
eval (direnv hook fish)

# Aliases
alias ag "ag --stats -S"
alias be "bundle exec"
alias bi "bundle install"
alias bo "bundle open"
alias bu "bundle update"
alias du "du -h"
alias g git
alias r rails
alias vi vim

Set tmux-friendly version of fzf

# Language
set -gx LANGUAGE en_US.UTF-8
set -gx LANG $LANGUAGE
set -gx LC_ALL $LANGUAGE
set -gx LC_CTYPE $LANGUAGE

# Editor
set -gx EDITOR vim
set -gx CVSEDITOR $EDITOR
set -gx SVN_EDITOR $EDITOR
set -gx GIT_EDITOR $EDITOR

# Pager
set -gx PAGER less

# XDG
set -gx XDG_CACHE_HOME $HOME/.cache
set -gx XDG_CONFIG_HOME $HOME/.config
set -gx XDG_DATA_HOME $HOME/.local/share

# Golang
set -gx GOPATH $HOME/work
set -gx PATH $PATH $GOPATH/bin

# fzf
set -gx FZF_DEFAULT_OPTS --reverse
set -gx FZF_LEGACY_KEYBINDINGS 0
set -gx FZF_TMUX 1

# ghq
set -gx GHQ_SELECTOR fzf

# rbenv
rbenv init - | source

# pyenv
status --is-interactive; and source (pyenv init -|psub)

# direnv
eval (direnv hook fish)

# Aliases
alias ag "ag --stats -S"
alias be "bundle exec"
alias bi "bundle install"
alias bo "bundle open"
alias bu "bundle update"
alias du "du -h"
alias g git
alias r rails
alias vi vim


function pd --description 'Change to a project directory'
  set -l paths $HOME/Projects/{2014,2013,2014}
  cd (find $paths -type d -maxdepth 2 | ack -i $argv[1] | ack -v Pods --max-count=1)
end

Add 2012 to searching project directories

function pd --description 'Change to a project directory'
  set -l paths $HOME/Projects/{2014,2013,2012}
  cd (find $paths -type d -maxdepth 2 | ack -i $argv[1] | ack -v Pods --max-count=1)
end


function list-users-in-group --argument-names group
    print-status iam/list-users-in-group $group
    test -f iam/group/$group.list
    and cat iam/group/$group.list
end


# Here is the configuration for the fish shell

source ~/deoxys314_dotfiles/fish/aliases.fish

source ~/deoxys314_dotfiles/fish/functions.fish

# important environmental variables
# set -g -x TERM screen-256color-bce

Add ~/bin to PATH to install personal executables.

# Here is the configuration for the fish shell

source ~/deoxys314_dotfiles/fish/aliases.fish

source ~/deoxys314_dotfiles/fish/functions.fish

set PATH $PATH ~/bin

# important environmental variables
# set -g -x TERM screen-256color-bce


# Path to your oh-my-fish.
set fish_path $HOME/.oh-my-fish

# Theme
set fish_theme bobthefish

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-fish/plugins/*)
# Custom plugins may be added to ~/.oh-my-fish/custom/plugins/
# Example format: set fish_plugins autojump bundler
set fish_plugins rvm git rails emoji-clock extract vi-mode

# Path to your custom folder (default path is $FISH/custom)
#set fish_custom $HOME/dotfiles/oh-my-fish

# Load aliases
. ~/.fish_aliases

# Load oh-my-fish configuration.
. $fish_path/oh-my-fish.fish

# OSX only items
if uname | grep "Darwin"
  # Add Postgres.app directory to PATH (Mac only)
  set PATH "/Applications/Postgres93.app/Contents/MacOS/bin/" $PATH

  # Make brew VIM higher priority
  set PATH "/usr/local/Cellar" $PATH
end

# Add Heroku to PATH (Linux)
#set PATH "/usr/local/heroku/bin" $PATH

# Set editor to VIM
set EDITOR vim
set NODE_ENV development

# GOPATH
set GOPATH /Users/jonathan/.gocode

# NVM path
test -s /Users/jonathan/.nvm-fish/nvm.fish; and source /Users/jonathan/.nvm-fish/nvm.fish

if type nvm > /dev/null
  nvm use 0.10
end

Remove uname on fish start

# Path to your oh-my-fish.
set fish_path $HOME/.oh-my-fish

# Theme
set fish_theme bobthefish

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-fish/plugins/*)
# Custom plugins may be added to ~/.oh-my-fish/custom/plugins/
# Example format: set fish_plugins autojump bundler
set fish_plugins rvm git rails emoji-clock extract vi-mode

# Path to your custom folder (default path is $FISH/custom)
#set fish_custom $HOME/dotfiles/oh-my-fish

# Load aliases
. ~/.fish_aliases

# Load oh-my-fish configuration.
. $fish_path/oh-my-fish.fish

# OSX only items
if uname | grep "Darwin" > /dev/null
  # Add Postgres.app directory to PATH (Mac only)
  set PATH "/Applications/Postgres93.app/Contents/MacOS/bin/" $PATH

  # Make brew VIM higher priority
  set PATH "/usr/local/Cellar" $PATH
end

# Add Heroku to PATH (Linux)
#set PATH "/usr/local/heroku/bin" $PATH

# Set editor to VIM
set EDITOR vim
set NODE_ENV development

# GOPATH
set GOPATH /Users/jonathan/.gocode

# NVM path
test -s /Users/jonathan/.nvm-fish/nvm.fish; and source /Users/jonathan/.nvm-fish/nvm.fish

if type nvm > /dev/null
  nvm use 0.10
end


function __z_add -d "Add PATH to .z file"
  set -l path (dirname (status -f))

  for i in $Z_EXCLUDE
    if contains -- $PWD $i
      return 0 #Path excluded
    end
  end

  set -l tmpfile (mktemp $Z_DATA.XXXXXX)

  if test -f $tmpfile
    awk -v path="$PWD" -v now=(date +%s) -F "|" -f $path/zadd.awk $Z_DATA ^ /dev/null > $tmpfile
    mv -f $tmpfile $Z_DATA
  end

  source $path/../completions/z.fish
end

Update completions for `zo` on dir change

function __z_add -d "Add PATH to .z file"
  set -l path (dirname (status -f))

  for i in $Z_EXCLUDE
    if contains -- $PWD $i
      return 0 #Path excluded
    end
  end

  set -l tmpfile (mktemp $Z_DATA.XXXXXX)

  if test -f $tmpfile
    awk -v path="$PWD" -v now=(date +%s) -F "|" -f $path/zadd.awk $Z_DATA ^ /dev/null > $tmpfile
    mv -f $tmpfile $Z_DATA
  end

  source $path/../completions/z.fish
  source $path/../completions/zo.fish
end


Implement a function to set a Shift-like color scheme

function shift_scheme
  set fish_color_autosuggestion 3a3a3a brblack
  set fish_color_cancel -r
  set fish_color_command ffbf00
  set fish_color_comment 7f7f7f
  # These colors are not used in the prompt
  set fish_color_cwd normal
  set fish_color_cwd_root normal
  set fish_color_end --bold ff7f00
  set fish_color_error ff0000
  set fish_color_escape 00bf00
  set fish_color_history_current normal
  # This color is not used
  set fish_color_host normal
  # TODO: Setting this didn't seem to have any effect?
  set fish_color_match normal
  set fish_color_normal normal
  set fish_color_operator d5d500
  set fish_color_param bfff00
  set fish_color_quote --bold ffffff
  set fish_color_redirection d5d500
  # TODO: What does this do again
  set fish_color_search_match ffff00
  set fish_color_selection c0c0c0
  set fish_color_status red
  set fish_color_user normal
  set fish_color_valid_path --underline
end


# Make sure ssh-agent can be reached
set -xg SSH_AUTH_SOCK "$XDG_RUNTIME_DIR/ssh-agent.socket"

# Use vim for git
set -xg VISUAL "vim"

set -xg PATH ~/.local/bin $PATH

# T(he )tmux session
alias ttmux "tmux attach-session; or tmux"

Make starting/attaching tmux default behaviour

# Make sure ssh-agent can be reached
set -xg SSH_AUTH_SOCK "$XDG_RUNTIME_DIR/ssh-agent.socket"

# Use vim for git
set -xg VISUAL "vim"

set -xg PATH ~/.local/bin $PATH

# T(he )tmux session

if not tmux has -t "default" 2>&1 > /dev/null
  tmux new -d -s "default"
end
if test -z "$TMUX"
  set default_is_attached (string split ' ' (tmux ls -F '#{session_name} #{session_attached}' | grep "default"))[2]
  if test "$default_is_attached" = "0"
    exec tmux attach -t "default"
  end
end


set normal (set_color normal)
set magenta (set_color magenta)
set yellow (set_color yellow)
set green (set_color green)
set red (set_color red)
set gray (set_color -o black)

# Interactive/login shells {{{

set fish_plugins brew rvm
# rvm default

if status --is-login
  source ~/.config/fish/env.fish
end

# }}}

abbr -a gs git status
abbr -a gc git commit
abbr -a gpom git push origin master
abbr -a gcm git checkout master
abbr -a be bundle exec
abbr -a ber bundle exec rake
abbr -a gd 'git diff --color | sed "s/^\([^-+ ]*\)[-+ ]/\\1/" | less -r'

Load environment file (if exists)

set normal (set_color normal)
set magenta (set_color magenta)
set yellow (set_color yellow)
set green (set_color green)
set red (set_color red)
set gray (set_color -o black)

# Interactive/login shells {{{

set fish_plugins brew rvm
# rvm default

if status --is-login
  source ~/.config/fish/env.fish

  # Load TCS file, if applicable/available
  if test -e ~/.config/fish/tcs.env
    source ~/.config/fish/tcs.env
  end
end

# }}}

abbr -a gs git status
abbr -a gc git commit
abbr -a gpom git push origin master
abbr -a gcm git checkout master
abbr -a be bundle exec
abbr -a ber bundle exec rake
abbr -a gd 'git diff --color | sed "s/^\([^-+ ]*\)[-+ ]/\\1/" | less -r'


function show_archive --description "List contents of compressed files"
  for file in $argv
    if test -f $file
      echo -s "Listing: " (set_color --bold blue) $file (set_color normal)
      switch $file
        case *.tar
          tar -tf $file
        case *.tar.bz2 *.tbz2
          bunzip2 -c $file | tar -tf - --
        case *.tar.gz *.tgz
          tar -ztf $file
        case *.zip *.ZIP
          unzip -l $file
        case *.bz2
          bunzip2 $file
          # Can also use: bzip2 -d $file
        case *.gz
          gunzip $file
        case *.rar
          unrar x $file
        case *.pax
          pax -r < $file
        case '*'
          echo "Extension not recognized, cannot list contents of $file"
      end
    else
      echo "$file is not a valid file"
    end
  end
end

Remove some incorrect case statements, that extract instead of list

function show_archive --description "List contents of compressed files"
  for file in $argv
    if test -f $file
      echo -s "Listing: " (set_color --bold blue) $file (set_color normal)
      switch $file
        case *.tar
          tar -tf $file
        case *.tar.bz2 *.tbz2
          bunzip2 -c $file | tar -tf - --
        case *.tar.gz *.tgz
          tar -ztf $file
        case *.zip *.ZIP
          unzip -l $file
        case '*'
          echo "Extension not recognized, cannot list contents of $file"
      end
    else
      echo "$file is not a valid file"
    end
  end
end


function fish_prompt --description 'Write out the prompt'
	set -l last_status $status

  # User
  set_color $fish_color_user
  echo -n (whoami)
  set_color normal

  echo -n ' in '

  # PWD
  set_color $fish_color_cwd
  # echo -n (prompt_pwd)
  echo -n (pwd | sed -e "s|$HOME|~|")
  set_color normal

  # __terlar_git_prompt
  __fish_git_prompt
  echo

  if not test $last_status -eq 0
    set_color $fish_color_error
  else
    set_color $fish_color_host
  end

  echo -n '∫ '
  set_color normal
end

Update fish prompt colors to prevent set_color errors

function fish_prompt --description 'Write out the prompt'
	set -l last_status $status

  # User
  set_color $fish_color_quote
  echo -n (whoami)
  set_color normal

  echo -n ' in '

  # PWD
  set_color $fish_color_cwd
  # echo -n (prompt_pwd)
  echo -n (pwd | sed -e "s|$HOME|~|")
  set_color normal

  # __terlar_git_prompt
  __fish_git_prompt
  echo

  if not test $last_status -eq 0
    set_color $fish_color_error
  else
    set_color blue
  end

  echo -n '∫ '
  set_color normal
end


function init -a path --on-event init_proxy
    if set -q proxy_host
       __proxy.set "http://$proxy_host"
    end
end

Initialize immediately, rather than waiting for an event.


function fish_prompt
  if test -e "$NVIM_LISTEN_ADDRESS"
    echo "» "
  else
    echo "\$ "
  end
end

Add tail of path to fish prompt

function fish_prompt
  if test -e "$NVIM_LISTEN_ADDRESS"
    echo (basename (pwd))"» "
  else
    echo (basename (pwd))"\$ "
  end
end


function weather.fetch -d "Fetches data from a URL backed by a cache"
  set md5 (echo $argv[1] | md5sum | cut -d " " -f 1)

  if not find /tmp/$md5.url -mmin +30 ^ /dev/null
    curl -s $argv[1] > /tmp/$md5.url
      or return 1
  end

  cat /tmp/$md5.url
end

Add GET parameters and more md5 providers

function weather.fetch -d "Fetches data from a URL backed by a cache"
  set md5 (__md5 "$argv")

  if test (count $argv) -gt 1
    for param in $argv[2..-1]
      set flags $flags --data-urlencode $param
    end
  end

  if not find /tmp/$md5.url -mmin +$weather_cache_age > /dev/null ^ /dev/null
    curl -Gs $flags $argv[1] > /tmp/$md5.url
      or return 1
  end

  cat /tmp/$md5.url
end

function __md5
  if available md5sum
    echo $argv[1] | md5sum | cut -d " " -f 1
    return 0
  end

  if available md5
    echo $argv[1] | md5 | cut -d " " -f 2
    return 0
  end

  if available openssl
    echo $argv[1] | openssl md5 | cut -d " " -f 2
    return 0
  end

  return 1
end


set -x COLOR_THEME dark
set -x EDITOR vim
set -x GOPATH $HOME/Projects/go
set -x LANG en_US.UTF-8
set -x LC_ALL en_US.UTF-8
set fish_greeting
set fish_key_bindings fish_vi_key_bindings

set -x PATH .git/safe/../../bin $HOME/.bin $GOPATH/bin $HOME/.rbenv/bin $PATH

rbenv init - | source

alias b="bundle"
alias be="bundle exec"
alias e="$EDITOR"
alias g='git'
alias gs='git status'
alias h="heroku"
alias hrc="heroku run console"
alias ln="ln -v"
alias lock="/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend"
alias migrate="rake db:migrate; and db:rollback; and rake db:migrate"
alias mkdir="mkdir -p"
alias s="bundle exec rspec"

function path --description "List all paths"
  for p in $PATH
    echo $p
  end
end

function mcd --description "Mkdir and cd"
  mkdir -p "$argv[1]"; and cd "$argv[1]"
end

function ip --description "What is my IP?"
  dig +short myip.opendns.com @resolver1.opendns.com
end

Update path, add bin before shim/bin

set -x COLOR_THEME dark
set -x EDITOR vim
set -x GOPATH $HOME/Projects/go
set -x LANG en_US.UTF-8
set -x LC_ALL en_US.UTF-8
set fish_greeting
set fish_key_bindings fish_vi_key_bindings

set -x PATH $HOME/.cargo/bin $GOPATH/bin $HOME/.rbenv/bin $PATH
rbenv init - | source
set -x PATH .git/safe/../../bin $HOME/.bin $PATH

alias b="bundle"
alias be="bundle exec"
alias e="$EDITOR"
alias g='git'
alias gs='git status'
alias h="heroku"
alias hrc="heroku run console"
alias ln="ln -v"
alias lock="/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend"
alias migrate="rake db:migrate; and db:rollback; and rake db:migrate"
alias mkdir="mkdir -p"
alias s="bundle exec rspec"

function path --description "List all paths"
  for p in $PATH
    echo $p
  end
end

function mcd --description "Mkdir and cd"
  mkdir -p "$argv[1]"; and cd "$argv[1]"
end

function ip --description "What is my IP?"
  dig +short myip.opendns.com @resolver1.opendns.com
end


# fisher
set fisher_home ~/.local/share/fisherman
set fisher_config ~/.config/fisherman

# ENV
set -x EDITOR "/usr/local/bin/nvim"
set -x GOPATH "$HOME/go"
set -x GOROOT "/usr/local/opt/go/libexec"
set -x COMPOSER_HOME "$HOME/.composer"
#set -x RBENV_ROOT "/usr/local/var/rbenv"
#set -x PYENV_ROOT "/usr/local/var/pyenv"

# PATH
set -x PATH "/usr/local/sbin" $PATH
set -x PATH "$HOME/bin" $PATH
set -x PATH $PATH "$GOROOT/bin"
set -x PATH $PATH "$GOPATH/bin"
set -x PATH $PATH "$COMPOSER_HOME/vendor/bin"
set -x PATH $PATH "/usr/local/share/dotnet"

# vim-devicons
set -x guifont "Droid Sans Mono for Powerline Nerd Font Complete"

# pyenv and pyenv-virtualenv
status --is-interactive; and . (pyenv init -|psub)
status --is-interactive; and . (pyenv virtualenv-init -|psub)

# rbenv
status --is-interactive; and . (rbenv init -|psub)

# eval
source "$HOME/perl5/perlbrew/etc/perlbrew.fish"
source "$HOME/.homesick/repos/homeshick/homeshick.fish"

Change vim dev font, Add google cloud-sdk

# fisher
set fisher_home ~/.local/share/fisherman
set fisher_config ~/.config/fisherman

# ENV
set -x EDITOR "/usr/local/bin/nvim"
set -x GOPATH "$HOME/go"
set -x GOROOT "/usr/local/opt/go/libexec"
set -x COMPOSER_HOME "$HOME/.composer"
#set -x RBENV_ROOT "/usr/local/var/rbenv"
#set -x PYENV_ROOT "/usr/local/var/pyenv"

# PATH
set -x PATH "/usr/local/sbin" $PATH
set -x PATH "$HOME/bin" $PATH
set -x PATH $PATH "$GOROOT/bin"
set -x PATH $PATH "$GOPATH/bin"
set -x PATH $PATH "$COMPOSER_HOME/vendor/bin"
set -x PATH $PATH "/usr/local/share/dotnet"
set -x PATH $PATH "$HOME/opt/google-cloud-sdk/bin"

# vim-devicons
set -x guifont "Droid Sans Mono for Powerline Nerd Font Complete"

# pyenv and pyenv-virtualenv
status --is-interactive; and . (pyenv init -|psub)
status --is-interactive; and . (pyenv virtualenv-init -|psub)

# rbenv
status --is-interactive; and . (rbenv init -|psub)

# eval
source "$HOME/perl5/perlbrew/etc/perlbrew.fish"
source "$HOME/.homesick/repos/homeshick/homeshick.fish"


set -x PATH $PATH $HOME/.dotfiles/scripts

# aliases
alias vim 'nvim'
alias tmux-reload 'tmux source-file ~/.tmux.conf'
alias git 'hub'
alias bnode 'babel-node'
alias em 'emacs'
alias psp 'psc-package'

# settings
set -x EDITOR nvim
set -x TERM xterm-256color
set -e fish_greeting
set -x LESS '-R'
set -x EMACS_TRUE_COLOR_SEPARATOR ';'

# path
set -x PATH /usr/local/bin $PATH
set -x PATH $HOME/.pyenv/shims $PATH
set -x PATH $PATH $HOME/bin
set -x PATH $PATH $HOME/.local/bin
set -x PATH $PATH $HOME/.stack/programs/x86_64-osx/ghc-8.0.2/bin
set -x PATH $PATH ./node_modules/.bin
set -x PATH $PATH $HOME/.cargo/bin

# fnm
status --is-interactive; and fnm 6

# lang
set -x LC_ALL en_US.UTF-8
set -x LC_CTYPE en_US.UTF-8

# tmux
function tm
  tmux-status
  if test $status -eq 0
    tmux
  end
end

# psci
set psci_env $HOME/Works/env/psci
function psci
  set prev (pwd)
  cd $psci_env
  psc-package repl
  cd $prev
end

Use Node.js 8 by default

set -x PATH $PATH $HOME/.dotfiles/scripts

# aliases
alias vim 'nvim'
alias tmux-reload 'tmux source-file ~/.tmux.conf'
alias git 'hub'
alias bnode 'babel-node'
alias em 'emacs'
alias psp 'psc-package'

# settings
set -x EDITOR nvim
set -x TERM xterm-256color
set -e fish_greeting
set -x LESS '-R'
set -x EMACS_TRUE_COLOR_SEPARATOR ';'

# path
set -x PATH /usr/local/bin $PATH
set -x PATH $HOME/.pyenv/shims $PATH
set -x PATH $PATH $HOME/bin
set -x PATH $PATH $HOME/.local/bin
set -x PATH $PATH $HOME/.stack/programs/x86_64-osx/ghc-8.0.2/bin
set -x PATH $PATH ./node_modules/.bin
set -x PATH $PATH $HOME/.cargo/bin

# fnm
status --is-interactive; and fnm 8

# lang
set -x LC_ALL en_US.UTF-8
set -x LC_CTYPE en_US.UTF-8

# tmux
function tm
  tmux-status
  if test $status -eq 0
    tmux
  end
end

# psci
set psci_env $HOME/Works/env/psci
function psci
  set prev (pwd)
  cd $psci_env
  psc-package repl
  cd $prev
end


function fry-find --description 'Find ruby by name'
  set -l name $argv[1]
  set -l rubyless_name (echo $name | sed 's/^ruby-//')

  for i in (fry-ls | sed '1!G;h;$!d')
    switch $i
      case "$name*" "$rubyless_name*" "ruby-$name*"
        echo $i
        return
    end
  end

  return 1
end

Sort instead of reversing ls

function fry-find --description 'Find ruby by name'
  set -l name $argv[1]
  set -l rubyless_name (echo $name | sed 's/^ruby-//')

  for i in (fry-ls | sort -r -n)
    switch $i
      case "$name*" "$rubyless_name*" "ruby-$name*"
        echo $i
        return
    end
  end

  return 1
end


set -x PATH ~/.local/bin $PATH

alias vim nvim
alias vi nvim

alias ghc 'stack exec -- ghc'
alias ghci 'stack exec -- ghci'

alias treea 'tree -a -I .git'

alias :q exit

# source local config
. ~/.config/fish/config.fish.local

Add ruby gems to my path

set -x PATH ~/.local/bin $PATH
set -x PATH ~/.gem/ruby $PATH

alias vim nvim
alias vi nvim

alias ghc 'stack exec -- ghc'
alias ghci 'stack exec -- ghci'

alias treea 'tree -a -I .git'

alias :q exit

# source local config
. ~/.config/fish/config.fish.local


set -g -x fish_greeting ''

# Depending on systems, locale can be en_US.UTF8 or en_US.UTF-8
set -x LANG (locale -a | grep -i "en_US.*utf")
set -e LC_CTYPE

set -x CLICOLOR true

if type -p brew > /dev/null ^&1
    set PATH (brew --prefix coreutils)"/libexec/gnubin" $PATH
    set -x MANPATH (brew --prefix coreutils)"/libexec/gnuman" $MANPATH
end

set -x PATH $HOME/.local/bin $PATH

set -x EDITOR nvim
set -x P4DIFF 'colordiff -u'

. ~/.bash_aliases
if test -f ~/.bash_aliases.after
    . ~/.bash_aliases.after
end

eval sh "$HOME/.dotfiles/subrepos/base16-shell/base16-flat.dark.sh"

alias vim=nvim

Add brew path when it does exist.

set -g -x fish_greeting ''

# Depending on systems, locale can be en_US.UTF8 or en_US.UTF-8
set -x LANG (locale -a | grep -i "en_US.*utf")
set -e LC_CTYPE

set -x CLICOLOR true

if test -f ~/brew/bin/brew
    set PATH $HOME/brew/bin $PATH
    set PATH (brew --prefix coreutils)"/libexec/gnubin" $PATH
    set -x MANPATH (brew --prefix coreutils)"/libexec/gnuman" $MANPATH
end

set -x PATH $HOME/.local/bin $PATH

set -x EDITOR nvim
set -x P4DIFF 'colordiff -u'

. ~/.bash_aliases
if test -f ~/.bash_aliases.after
    . ~/.bash_aliases.after
end

eval sh "$HOME/.dotfiles/subrepos/base16-shell/base16-flat.dark.sh"

alias vim=nvim


alias pingtest 'ping google.com'
alias f 'find -L . -name'
alias p 'ps -ef'
alias pf 'ps -ef | grep'
alias disk-space 'df -h'
alias ipinfo 'curl ipinfo.io/ip'
function download-config
  pushd ~/repos/server-setup/
  git pull
  popd
  update-config
end
function update-config
  . ~/.config/fish/config.fish
end
function find-string -d 'Find string in files'
  grep -rnw . -H -e $argv
end
function does-exist
  return (type $argv > /dev/null)
end
function last-of -d "Find the latest matching file"
  ls -tr | grep $argv | tail -1
end
function check-last -d "Run less on the latest matching file"
  set file (last-of $argv)
  log info 'Checking file:'$file
  less $file
end
function e -d 'Start the vim with proper permission'
  if test -f $argv
    if test -w $argv
      vim $argv
    else
      sudo vim $argv
    end
  else
    vim $argv
  end
end

Add 'v' command to view file with color

alias pingtest 'ping google.com'
alias f 'find -L . -name'
alias p 'ps -ef'
alias pf 'ps -ef | grep'
alias disk-space 'df -h'
alias ipinfo 'curl ipinfo.io/ip'
function download-config
  pushd ~/repos/server-setup/
  git pull
  popd
  update-config
end
function update-config
  . ~/.config/fish/config.fish
end
function find-string -d 'Find string in files'
  grep -rnw . -H -e $argv
end
function does-exist
  return (type $argv > /dev/null)
end
function last-of -d "Find the latest matching file"
  ls -tr | grep $argv | tail -1
end
function check-last -d "Run less on the latest matching file"
  set file (last-of $argv)
  log info 'Checking file:'$file
  less $file
end
function e -d 'Start the vim with proper permission'
  if test -f $argv
    if test -w $argv
      vim $argv
    else
      sudo vim $argv
    end
  else
    vim $argv
  end
end
function v -d 'View the files'
  less -R $argv
end


function fish_prompt
    set -l current_k8s_context (kubectl config current-context)
    set -l gcp_project (cat ~/.config/gcloud/active_config)
    #    set -l gcp_project (cat ~/.config/gcloud/configurations/config_(cat ~/.config/gcloud/active_config) | grep project | cut -f 3 -d " ")

    set -x envs
    if contains $current_k8s_context $FISH_PROMPT_K8S_CONTEXT_NAMES
        set envs $envs (printf 'k8s:%s' $current_k8s_context)
    end
    if contains $gcp_project $FISH_PROMPT_GCP_CONFIG_NAMES
        set envs $envs (printf 'GCP:%s' $gcp_project)
    end
    if [ (count $envs) -gt 0 ]
        set_color red
        printf '(%s) ' (string join ',' $envs)
        set_color normal
    end
    printf '> '
end

Update prompt to make them minimize

function fish_prompt
    set -l current_k8s_context (kubectl config current-context)
    set -l gcp_project (cat ~/.config/gcloud/active_config)
    #    set -l gcp_project (cat ~/.config/gcloud/configurations/config_(cat ~/.config/gcloud/active_config) | grep project | cut -f 3 -d " ")

    set -x envs
    if contains $current_k8s_context $FISH_PROMPT_K8S_CONTEXT_NAMES
        set envs $envs (printf '⎈ %s' $current_k8s_context)
    end
    if contains $gcp_project $FISH_PROMPT_GCP_CONFIG_NAMES
        set envs $envs (printf 'GCP:%s' $gcp_project)
    end
    if [ (count $envs) -gt 0 ]
        set_color red
        printf '%s ' (string join ',' $envs)
        set_color normal
    end
    printf '> '
end


function fish_prompt
  # Start ohmyfish-batman theme default prompt
  test $status -ne 0;
    and set --local colors 600 900 c00
    or set --local colors 333 666 aaa

  set --local pwd (prompt_pwd)
  set --local base (basename "$pwd")

  set --local expr "s|~|"(fst)"^^"(off)"|g; \
                   s|/|"(snd)"/"(off)"|g;  \
                   s|"$base"|"(fst)$base(off)" |g"

  echo -n (echo "$pwd" | sed --expression $expr)(off)

  for color in $colors
    echo -n (set_color $color)">"
  end

  echo -n " "
  # End ohmyfish-batman theme default prompt

  if set --query VIRTUAL_ENV
    echo -n -s (set_color --background blue white) "(" (basename "$VIRTUAL_ENV") ")" (set_color normal) " "
  end
  end
end

Move helper functions from fish_greeting

function fish_prompt
  # Start ohmyfish-batman theme default prompt
  test $status -ne 0;
    and set --local colors 600 900 c00
    or set --local colors 333 666 aaa

  set --local pwd (prompt_pwd)
  set --local base (basename "$pwd")

  function fst; set_color --bold fa0; end
  function snd; set_color --bold 36f; end
  function trd; set_color --bold f06; end
  function dim; set_color 666; end
  function off; set_color normal; end

  set --local expr "s|~|"(fst)"^^"(off)"|g; \
                   s|/|"(snd)"/"(off)"|g;  \
                   s|"$base"|"(fst)$base(off)" |g"

  echo -n (echo "$pwd" | sed --expression $expr)(off)

  for color in $colors
    echo -n (set_color $color)">"
  end

  echo -n " "
  # End ohmyfish-batman theme default prompt

  if set --query VIRTUAL_ENV
    echo -n -s (set_color --background blue white) "(" (basename "$VIRTUAL_ENV") ")" (set_color normal) " "
  end
  end
end


function _git_rev_name --description "print a representation of the currently checked-out revision"

	set _rev_name (git symbolic-ref -q HEAD ^/dev/null)
	if echo "$_rev_name" | grep -q -E 'refs/(heads|tags)/*'
		set _rev_name (echo "$_rev_name" | sed -n "s/refs\/\(heads\|tags\)\/\(.*\)/\2/p")
	else
		set _rev_name (git name-rev --name-only --always --no-undefined HEAD ^/dev/null | sed -e "s/[\^\~]0//g")
	end
	echo $_rev_name
end

Add timeout to git commands

function _git_rev_name --description "print a representation of the currently checked-out revision"

	set _rev_name (timeout --preserve_status 0.1s git symbolic-ref -q HEAD ^/dev/null)
	if echo "$_rev_name" | grep -q -E 'refs/(heads|tags)/*'
		set _rev_name (echo "$_rev_name" | sed -n "s/refs\/\(heads\|tags\)\/\(.*\)/\2/p")
	else
		set _rev_name (timeout --preserve-status 0.1s git name-rev --name-only --always --no-undefined HEAD ^/dev/null | sed -e "s/[\^\~]0//g")
	end
	echo $_rev_name
end


Add function to ssh into an account's bastion

function ssh-bastion
    ssh (env AWS_PROFILE=$argv AWS_REGION=eu-west-1 ~/src/bitbucket.org/theasi/infra-deploy-aws/scripts/get-bastion-ip.sh);
end


set -gx LANGUAGE en_US.UTF-8
set -gx LANG $LANGUAGE
set -gx LC_ALL $LANGUAGE
set -gx LC_CTYPE $LANGUAGE
set -gx PATH $HOME/bin $PATH $GOPATH/bin
set -gx EDITOR vim
set -gx PAGER less
set -gx GOPATH $HOME/work
set -gx PATH $PATH $GOPATH/bin
set -gx FZF_DEFAULT_OPTS --reverse
set -gx XDG_CONFIG_HOME $HOME/.config

alias ag "ag --stats -S"
alias be "bundle exec"
alias bi="bundle install"
alias bo="bundle open"
alias bu="bundle update"
alias emacs nvim
alias g git
alias r rails

rbenv init - | source
eval (direnv hook fish)

Use new keybindings of fzf plugin

set -gx LANGUAGE en_US.UTF-8
set -gx LANG $LANGUAGE
set -gx LC_ALL $LANGUAGE
set -gx LC_CTYPE $LANGUAGE
set -gx PATH $HOME/bin $PATH $GOPATH/bin
set -gx EDITOR vim
set -gx PAGER less
set -gx GOPATH $HOME/work
set -gx PATH $PATH $GOPATH/bin
set -gx FZF_DEFAULT_OPTS --reverse
set -gx XDG_CONFIG_HOME $HOME/.config

set -U FZF_LEGACY_KEYBINDINGS 0

alias ag "ag --stats -S"
alias be "bundle exec"
alias bi="bundle install"
alias bo="bundle open"
alias bu="bundle update"
alias emacs nvim
alias g git
alias r rails

rbenv init - | source
eval (direnv hook fish)


Add a command to print out all terminal palette colors for testing

function color_test -d "Prints colors in there color for test purpose"
    printf "%sblack\t %s bold\t %sbright\t %sbrbold%s\n" (set_color black) (set_color -o black) (set_color normal)
    printf "%sred\t %s bold\t %sbright\t %sbrbold%s\n" (set_color red) (set_color -o red) (set_color brred) (set_color -o brred) (set_color normal)
    printf "%sgreen\t %s bold\t %sbright\t %sbrbold%s\n" (set_color green) (set_color -o green) (set_color brgreen) (set_color -o brgreen) (set_color normal)
    printf "%syellow\t %s bold\t %sbright\t %sbrbold%s\n" (set_color yellow) (set_color -o yellow) (set_color bryellow) (set_color -o bryellow) (set_color normal)
    printf "%sblue\t %s bold\t %sbright\t %sbrbold%s\n" (set_color blue) (set_color -o blue) (set_color brblue) (set_color -o brblue) (set_color normal)
    printf "%spurple\t %s bold\t %sbright\t %sbrbold%s\n" (set_color purple) (set_color -o purple) (set_color brpurple) (set_color -o brpurple) (set_color normal)
    printf "%scyan\t %s bold\t %sbright\t %sbrbold%s\n" (set_color cyan) (set_color -o cyan) (set_color brcyan) (set_color -o brcyan) (set_color normal)
    printf "%sgrey\t %s bold\t %sbright\t %sbrbold%s\n" (set_color grey) (set_color -o grey) (set_color brgrey) (set_color -o brgrey) (set_color normal)
    printf "%white\t %s bold\n" (set_color white) (set_color -o white) (set_color normal)
    printf "%snormal\t %s bold%s\n" (set_color normal) (set_color normal) (set_color normal)
end


Add function to look up a resource by tag

function lookup --argument-names resource
    set --local key
    set --local value

    switch (count $argv)
        case 2
            set key Name
            set value $argv[2]
        case 3
            set key $argv[2]
            set value $argv[3]
        case '*'
            print-status usage 'lookup <resource> (<name> | [key] <value>)'
            return -1
    end

    aws ec2 describe-tags --filters Name=resource-type,Values=$resource Name=tag:$key,Values=$value | jq --raw-output .Tags[].ResourceId | sort -u
end


export NNN_TMPFILE="/tmp/nnn"

function n --description 'support nnn quit and change directory'
        nnn $argv

        if test -e $NNN_TMPFILE
                . $NNN_TMPFILE
                rm $NNN_TMPFILE
        end
end

Replace single dot with source for fish shell

export NNN_TMPFILE="/tmp/nnn"

function n --description 'support nnn quit and change directory'
        nnn $argv

        if test -e $NNN_TMPFILE
                source $NNN_TMPFILE
                rm $NNN_TMPFILE
        end
end


# Neovim
set --local neovim_guis \
	/Applications/FVim.app/Contents/MacOS/FVim \
	/Applications/goneovim.app/Contents/MacOS/goneovim
set --export EDITOR $neovim_guis[(random 1 2)]

# Nix
set NIX_LINK $HOME/.nix-profile
set --export NIX_PATH nixpkgs=$HOME/.nix-defexpr/channels/nixpkgs
set --export SSL_CERT_FILE $NIX_LINK/etc/ssl/certs/ca-bundle.crt

# XDG
if test -z $XDG_CONFIG_HOME
	set --export XDG_CONFIG_HOME $HOME/.config
	set --export XDG_DATA_HOME $HOME/.local/share
	set --export XDG_CACHE_HOME $HOME/.cache
end

# NPM
set --export NPM_CONFIG_USERCONFIG $XDG_CONFIG_HOME/npm/config

# Postgres
set --export PSQLRC $XDG_CONFIG_HOME/psqlrc

set PATH $NIX_LINK/bin $NIX_LINK/sbin $PATH
set PATH ~/.local/bin $PATH
set PATH ~/.luarocks/bin $PATH
set PATH node_modules/.bin $XDG_DATA_HOME/node_modules $PATH
set --export PATH $PATH

Set locale to British English

# Locale
set --export LANG en_GB.UTF-8
set --export LC_ALL $LANG

# Neovim
set --local neovim_guis \
	/Applications/FVim.app/Contents/MacOS/FVim \
	/Applications/goneovim.app/Contents/MacOS/goneovim

set --export EDITOR $neovim_guis[(random 1 2)]

# Nix
set NIX_LINK $HOME/.nix-profile
set --export NIX_PATH nixpkgs=$HOME/.nix-defexpr/channels/nixpkgs
set --export SSL_CERT_FILE $NIX_LINK/etc/ssl/certs/ca-bundle.crt

# XDG
if test -z $XDG_CONFIG_HOME
	set --export XDG_CONFIG_HOME $HOME/.config
	set --export XDG_DATA_HOME $HOME/.local/share
	set --export XDG_CACHE_HOME $HOME/.cache
end

# NPM
set --export NPM_CONFIG_USERCONFIG $XDG_CONFIG_HOME/npm/config

# Postgres
set --export PSQLRC $XDG_CONFIG_HOME/psqlrc

set PATH $NIX_LINK/bin $NIX_LINK/sbin $PATH
set PATH ~/.local/bin $PATH
set PATH ~/.luarocks/bin $PATH
set PATH node_modules/.bin $XDG_DATA_HOME/node_modules $PATH
set --export PATH $PATH


test -e /opt/homebrew/bin/brew && eval (/opt/homebrew/bin/brew shellenv)

Support Homebrew on non-Apple Silicon

test -e /opt/homebrew/bin/brew && eval (/opt/homebrew/bin/brew shellenv)
test -e /usr/local/bin/brew && eval (/usr/local/bin/brew shellenv)


function fish_prompt
	test $SSH_TTY
    and printf (set_color red)$USER(set_color brwhite)'@'(set_color yellow)(prompt_hostname)' '
    test "$USER" = 'root'
    and echo (set_color red)"#"

    # Main
    echo -n (set_color cyan)(prompt_pwd) (set_color red)'❯'(set_color yellow)'❯'(set_color green)'❯ '
end

Update prompt to show vcs info

function fish_prompt
	test $SSH_TTY
    and printf (set_color red)$USER(set_color brwhite)'@'(set_color yellow)(prompt_hostname)' '
    test "$USER" = 'root'
    and echo (set_color red)"#"

    # Main
    echo -n (set_color cyan)(prompt_pwd)(__fish_vcs_prompt) (set_color red)'❯'(set_color yellow)'❯'(set_color green)'❯ '
end


function _prompt_dir_component
  _prompt_wrap_text (abbreviated-working-directory) brblue
end

function _prompt_err_component --argument-names {error_code}
  if [ $error_code -ne 0 ]
    _prompt_wrap_text $error_code brred
  end
end

function _prompt_git_component
  if git rev-parse --git-dir >/dev/null ^&1
    set --local sha (git rev-parse HEAD)
    set --local ref (git show-ref --tags --heads | grep $sha; or echo '')

    set --local parts ''
    if [ -n $ref ]
      set parts (string split / -- $ref)
    else
      set parts null detached $sha
    end

    switch $parts[2]
    case heads
      _prompt_wrap_text $parts[3] green
    case tags
      _prompt_wrap_text $parts[3] yellow
    case detached
      _prompt_wrap_text (git rev-parse --short $sha) brred
    end
  end
end

function _prompt_wrap_text --argument-names {text,color}
  set_color normal
  echo -n "["
  set_color --bold $color
  echo -n $text
  set_color normal
  echo -n "]"
end

function fish_prompt
  set --local error_code $status
  set --local err (_prompt_err_component $error_code)
  set --local git (_prompt_git_component)
  set --local dir (_prompt_dir_component)
  echo "$git$dir$err "
end

Use easier way to check if variable is set

function _prompt_dir_component
  _prompt_wrap_text (abbreviated-working-directory) brblue
end

function _prompt_err_component --argument-names {error_code}
  if [ $error_code -ne 0 ]
    _prompt_wrap_text $error_code brred
  end
end

function _prompt_git_component
  if git rev-parse --git-dir >/dev/null ^&1
    set --local sha (git rev-parse HEAD)
    set --local ref (git show-ref --tags --heads | grep $sha)

    set --local parts ''
    if set -q ref
      set parts (string split / -- $ref)
    else
      set parts null detached $sha
    end

    switch $parts[2]
    case heads
      _prompt_wrap_text $parts[3] green
    case tags
      _prompt_wrap_text $parts[3] yellow
    case detached
      _prompt_wrap_text (git rev-parse --short $sha) brred
    end
  end
end

function _prompt_wrap_text --argument-names {text,color}
  set_color normal
  echo -n "["
  set_color --bold $color
  echo -n $text
  set_color normal
  echo -n "]"
end

function fish_prompt
  set --local error_code $status
  set --local err (_prompt_err_component $error_code)
  set --local git (_prompt_git_component)
  set --local dir (_prompt_dir_component)
  echo "$git$dir$err "
end


function upgrade-aur
  set_color --bold brmagenta
  echo "Running command: pikaur --sync --refresh --sysupgrade --devel"
  set_color normal
  command pikaur --sync --refresh --sysupgrade --devel
end

Add cli option to skip non-new packages

function upgrade-aur
  set_color --bold brmagenta
  echo "Running command: pikaur --sync --refresh --sysupgrade --devel"
  set_color normal
  command pikaur --sync --refresh --sysupgrade --devel --needed
end


. ~/.config/fish/aliases.fish
. ~/.config/fish/abbr.fish

set fish_greeting ""

eval (python -m virtualfish compat_aliases)
eval (thefuck --alias | tr '\n' ';')

if type hub > /dev/null
	eval (hub alias -s)
else
    echo "WARNING: hub not installed"
end

set -x PATH /usr/local/bin $PATH
set -x EDITOR vim

# GIT PROMPT CONFIG
set -g __fish_git_prompt_show_informative_status 1
set -g __fish_git_prompt_char_dirtystate "+"
set -g __fish_git_prompt_char_untrackedfiles "."
set -g __fish_git_prompt_color_branch magenta
set -g __fish_git_prompt_color_dirtystate blue
set -g __fish_git_prompt_color_stagedstate yellow
set -g __fish_git_prompt_color_invalidstate red
set -g __fish_git_prompt_color_untrackedfiles $fish_color_normal
set -g __fish_git_prompt_color_cleanstate green

Update path statements in fish config

. ~/.config/fish/aliases.fish
. ~/.config/fish/abbr.fish

set -x PATH /usr/local/bin $PATH
set -x PATH ~/.local/bin $PATH

set fish_greeting ""

eval (python -m virtualfish compat_aliases)
eval (thefuck --alias | tr '\n' ';')

if type hub > /dev/null
	eval (hub alias -s)
else
    echo "WARNING: hub not installed"
end

set -x EDITOR vim

# GIT PROMPT CONFIG
set -g __fish_git_prompt_show_informative_status 1
set -g __fish_git_prompt_char_dirtystate "+"
set -g __fish_git_prompt_char_untrackedfiles "."
set -g __fish_git_prompt_color_branch magenta
set -g __fish_git_prompt_color_dirtystate blue
set -g __fish_git_prompt_color_stagedstate yellow
set -g __fish_git_prompt_color_invalidstate red
set -g __fish_git_prompt_color_untrackedfiles $fish_color_normal
set -g __fish_git_prompt_color_cleanstate green


function move_all_workspaces --description="Move all workspaces to the currently focused output."
  set current_output (swaymsg -t get_outputs | jq '.[] | select(.focused==true) | .name')
  for ws in (swaymsg --raw --type get_workspaces | jq --raw-output '.[].name')
    swaymsg [workspace="$ws"] move workspace to output $current_output
  end
end

Allow from output to be specified, also fix case when output is empty

function move_all_workspaces --description="Move all workspaces to the currently focused output."
 function print_help
    echo "Usage: move_all_workspaces [options]"
    echo "Options:"
    echo (set_color green)"--from"(set_color $fish_color_normal)": Specify output name from which workspaces are to be moved (defaults to all)."
  end

  argparse --name move_all_workspaces 'f/from=' 'h/help' -- $argv
  or return 1  #error

  if set -lq _flag_help
    print_help
    return
  end

  if set -lq _flag_from
    set from_output $_flag_from
  end

  set current_output (swaymsg -t get_outputs | jq '.[] | select(.focused==true) | .name')

  if set --query from_output
    set workspaces (swaymsg --raw --type get_workspaces | jq --raw-output ".[] | select(.representation != null and .output == \"$from_output\") | .name")
  else
    set workspaces (swaymsg --raw --type get_workspaces | jq --raw-output '.[] | select(.representation != null) | .name')
  end
  for ws in $workspaces
    swaymsg [workspace="$ws"] move workspace to output $current_output
  end
end


function powerline
	if test -z "$POWERLINE_COMMAND"
		if which powerline-client >/dev/null
			set -g -x POWERLINE_COMMAND powerline-client
		else
			set -g -x POWERLINE_COMMAND powerline
		end
	end
	function --on-variable POWERLINE_COMMAND _powerline_update
		eval "
		function fish_prompt
			$POWERLINE_COMMAND shell left --last_exit_code=\$status --last_pipe_status=\$status
		end
		function fish_right_prompt
			$POWERLINE_COMMAND shell right --last_exit_code=\$status --last_pipe_status=\$status
		end
		"
	end
	_powerline_update
	function _powerline_tmux_setenv
		if test -n "$TMUX"
			tmux setenv -g TMUX_$argv[1]_(tmux display -p "#D" | tr -d "%") "$argv[2]"
			tmux refresh -S
		end
	end
	function --on-variable PWD _powerline_tmux_set_pwd
		_powerline_tmux_setenv PWD "$PWD"
	end
	function --on-signal WINCH _powerline_tmux_set_columns
		_powerline_tmux_setenv COLUMNS "$COLUMNS"
	end
	_powerline_tmux_set_columns
	_powerline_tmux_set_pwd
end
powerline

Add support for number of jobs to fish bindings

function powerline
	if test -z "$POWERLINE_COMMAND"
		if which powerline-client >/dev/null
			set -g -x POWERLINE_COMMAND powerline-client
		else
			set -g -x POWERLINE_COMMAND powerline
		end
	end
	function --on-variable POWERLINE_COMMAND _powerline_update
		set -l addargs "--last_exit_code=\$status --last_pipe_status=\$status --jobnum=(jobs -p | wc -l)"
		eval "
		function fish_prompt
			$POWERLINE_COMMAND shell left $addargs
		end
		function fish_right_prompt
			$POWERLINE_COMMAND shell right $addargs
		end
		"
	end
	_powerline_update
	function _powerline_tmux_setenv
		if test -n "$TMUX"
			tmux setenv -g TMUX_$argv[1]_(tmux display -p "#D" | tr -d "%") "$argv[2]"
			tmux refresh -S
		end
	end
	function --on-variable PWD _powerline_tmux_set_pwd
		_powerline_tmux_setenv PWD "$PWD"
	end
	function --on-signal WINCH _powerline_tmux_set_columns
		_powerline_tmux_setenv COLUMNS "$COLUMNS"
	end
	_powerline_tmux_set_columns
	_powerline_tmux_set_pwd
end
powerline


function expand:revert
  # Replace the entire buffer with the original contents before any expansion was performed.
  commandline -r $__expand_last_string
end

Fix backspace in completions as well

function expand:revert
  # Since we can't conditionally switch key bind modes, we need to pass through command completion requests again even
  # though we are already in expand mode.
  if not set -q __expand_replacements[1]
    commandline -f backward-delete-char
    return
  end

  # Replace the entire buffer with the original contents before any expansion was performed.
  commandline -r $__expand_last_string
end


function fish_right_prompt
    echo -n -s (set_color $fish_color_autosuggestion) (date +"%Y-%m-%d %I:%M:%S%P") (set_color reset)
end

Fix am/pm in right prompt on macos

function fish_right_prompt
    echo -n -s (set_color $fish_color_autosuggestion) (date +"%Y-%m-%d %I:%M:%S%p") (set_color reset)
end


set -x PATH /apollo/env/SDETools/bin $PATH
function bb
  brazil-build
end

function bbap
  bb
  brazil-build apollo-pkg
end

function bbc
  brazil-build clean
end

function bbg
  brazil-build gdb
end

function bbt
  brazil-build test
end

function bbs
  brazil-build server
end

function bba
  bbc
  bb
  bbt
end

function bbr
  brazil-build release
end

function bbtia
  brazil-build test-integration-assert
end

function bbptc
  brazil-build print-testrun-classpath
end

function sb
  ssh badamson.desktop.amazon.com
end

function btpt
  /apollo/env/BrazilThirdPartyTool/bin/brazil-third-party-tool
end

function kp
  kinit -f
end

Add alias for brazil ws --sync --md

set -x PATH /apollo/env/SDETools/bin $PATH
function bb
  brazil-build
end

function bbap
  bb
  brazil-build apollo-pkg
end

function bbc
  brazil-build clean
end

function bbg
  brazil-build gdb
end

function bbt
  brazil-build test
end

function bbs
  brazil-build server
end

function bba
  bbc
  bb
  bbt
end

function bbr
  brazil-build release
end

function bws
  brazil ws --sync --md
end

function bbtia
  brazil-build test-integration-assert
end

function bbptc
  brazil-build print-testrun-classpath
end

function sb
  ssh badamson.desktop.amazon.com
end

function btpt
  /apollo/env/BrazilThirdPartyTool/bin/brazil-third-party-tool
end

function kp
  kinit -f
end


function getsxg -w curl -d "Attempt to retrieve SXG for URL"
  curl -sS --output - -H 'accept: application/signed-exchange;v=b3' -H 'amp-cache-transform: google;v="1"' $argv
end

Make work with more versions

function getsxg -w curl -d "Attempt to retrieve SXG for URL"
  curl -sS --output - -H 'accept: application/signed-exchange;v=b3' -H 'amp-cache-transform: google;v="1..100"' $argv
end


function fish_prompt
  # Start ohmyfish-batman theme default prompt
  test $status -ne 0;
    and set --local colors 600 900 c00
    or set --local colors 333 666 aaa

  set --local pwd (prompt_pwd)
  set --local base (basename "$pwd")

  function fst; set_color --bold fa0; end
  function snd; set_color --bold 36f; end
  function trd; set_color --bold f06; end
  function dim; set_color 666; end
  function off; set_color normal; end

  set --local expr "s|~|"(fst)"^^"(off)"|g; \
                   s|/|"(snd)"/"(off)"|g;  \
                   s|"$base"|"(fst)$base(off)" |g"

  echo -n (echo "$pwd" | sed --expression $expr)(off)

  for color in $colors
    echo -n (set_color $color)">"
  end

  echo -n " "
  # End ohmyfish-batman theme default prompt

  if set --query VIRTUAL_ENV
    echo -n -s (set_color --background blue white) "(" (basename "$VIRTUAL_ENV") ")" (set_color normal) " "
  end

  # could or may also need to check SSH_TTY or SSH_CONNECTION
  if set --query SSH_CLIENT
    echo -n -s (set_color --background red white) "(SSH: " (hostname) ")" (set_color normal) " "
  end

end

Add out-of-date kernel warning to prompt

function fish_prompt
  # Start ohmyfish-batman theme default prompt
  test $status -ne 0;
    and set --local colors 600 900 c00
    or set --local colors 333 666 aaa

  set --local pwd (prompt_pwd)
  set --local base (basename "$pwd")

  function fst; set_color --bold fa0; end
  function snd; set_color --bold 36f; end
  function trd; set_color --bold f06; end
  function dim; set_color 666; end
  function off; set_color normal; end

  set --local expr "s|~|"(fst)"^^"(off)"|g; \
                   s|/|"(snd)"/"(off)"|g;  \
                   s|"$base"|"(fst)$base(off)" |g"

  echo -n (echo "$pwd" | sed --expression $expr)(off)

  for color in $colors
    echo -n (set_color $color)">"
  end

  echo -n " "
  # End ohmyfish-batman theme default prompt

  if set --query VIRTUAL_ENV
    echo -n -s (set_color --background blue white) "(" (basename "$VIRTUAL_ENV") ")" (set_color normal) " "
  end

  # could or may also need to check SSH_TTY or SSH_CONNECTION
  if set --query SSH_CLIENT
    echo -n -s (set_color --background red white) "(SSH: " (hostname) ")" (set_color normal) " "
  end

  if test ! check_kernel
    echo -n -s (set_color --background red blue) "RESTART FOR NEW KERNEL!" (set_color normal) " "
  end
end


if not set --query GH_BASE_DIR
  set GH_BASE_DIR $HOME/src
end

function __gh_user_completion
  ls $GH_BASE_DIR/github.com
end

function __gh_repo_completion
  set --local cmd (commandline --tokenize --cut-at-cursor)
  set --local user $cmd[2]
  ls $GH_BASE_DIR/github.com/$user
end

complete --command gh --short h --long help --description 'Show help and usage information'
complete --command gh --condition '__fish_is_token_n 2' --arguments '(__gh_user_completion)' --no-files
complete --command gh --condition '__fish_is_token_n 3' --arguments '(__gh_repo_completion)' --no-files

Fix default GH_BASE_DIR value for completions

if not set --query GH_BASE_DIR
  set GH_BASE_DIR $HOME
end

function __gh_user_completion
  ls $GH_BASE_DIR/github.com
end

function __gh_repo_completion
  set --local cmd (commandline --tokenize --cut-at-cursor)
  set --local user $cmd[2]
  ls $GH_BASE_DIR/github.com/$user
end

complete --command gh --short h --long help --description 'Show help and usage information'
complete --command gh --condition '__fish_is_token_n 2' --arguments '(__gh_user_completion)' --no-files
complete --command gh --condition '__fish_is_token_n 3' --arguments '(__gh_repo_completion)' --no-files


# this is super clowny but it coerces new tmux panes that are in fbcode to use the
# nicer symlinked path rather than the real path on disk
function fbcode_cd --on-variable PWD
  switch (pwd)
  case "/data/users/vmagro/fbsource/fbcode*"
    set -l path (string replace "/data/users/vmagro/fbsource/fbcode" "$HOME/fbcode" (pwd))
    cd $path
  case "/data/users/vmagro/configerator-hg*"
    set -l path (string replace "/data/users/vmagro/configerator-hg" "$HOME/configerator" (pwd))
    cd $path
  case "/data/users/vmagro/www-hg*"
    set -l path (string replace "/data/users/vmagro/www-hg" "$HOME/www" (pwd))
    cd $path
  case "/data/users/vmagro/linux*"
    set -l path (string replace "/data/users/vmagro/linux" "$HOME/linux" (pwd))
    cd $path
  end
end

Work for generic directories under ~

# this is super clowny but it coerces new tmux panes that are in fbcode to use the
# nicer symlinked path rather than the real path on disk
function fbcode_cd --on-variable PWD
  switch (pwd)
  case "/data/users/vmagro/fbsource/fbcode*"
    set -l path (string replace "/data/users/vmagro/fbsource/fbcode" "$HOME/fbcode" (pwd))
    cd $path
  case "/data/users/vmagro/configerator-hg*"
    set -l path (string replace "/data/users/vmagro/configerator-hg" "$HOME/configerator" (pwd))
    cd $path
  case "/data/users/vmagro/www-hg*"
    set -l path (string replace "/data/users/vmagro/www-hg" "$HOME/www" (pwd))
    cd $path
  case "/data/users/vmagro/*"
    set -l path (string replace "/data/users/vmagro" "$HOME" (pwd))
    cd $path
  end
end


# The MIT License (MIT)

# Copyright (c) 2015 Derek Willian Stavis

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

function fenv.apply
    set VARIABLES $argv

    for variable in $VARIABLES
        set KEY (echo $variable | sed -e 's/=.*//')
        set VALUE (echo $variable | sed -e 's/.*=//')
        set COMMAND "set -g -x $KEY $VALUE"

        eval "$COMMAND" > /dev/null 2>&1
    end
end

Convert bash PATH format into fish's

# The MIT License (MIT)

# Copyright (c) 2015 Derek Willian Stavis

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

function fenv.apply
    set VARIABLES $argv

    for variable in $VARIABLES
        set KEY (echo $variable | sed -e 's/=.*//')
        set VALUE (echo $variable | sed -e 's/.*=//')

        if [ $KEY = 'PATH' ]
          set VALUE (echo $variable | sed -e 's/:/ /')
        end

        set COMMAND "set -g -x $KEY $VALUE"

        eval "$COMMAND" > /dev/null 2>&1
    end
end


function update-roles
    for role in (get iam/roles)
        role-exists $role
        or create-role $role
        and for policy in (get iam/roles/$role/policies)
            apply-policy iam/roles/$role/policies/$policy
        end
    end
end


Add fish shell function to change directiories using fzf

# From https://gist.github.com/rumpelsepp/b1b416f52d6790de1aee
function fcd --description "Fuzzy change directory"
    if set -q argv[1]
        set searchdir $argv[1]
    else
        set searchdir $HOME
    end

    # https://github.com/fish-shell/fish-shell/issues/1362
    set -l tmpfile (mktemp)
    find $searchdir \( ! -regex '.*/\..*' \) ! -name __pycache__ -type d | fzf > $tmpfile
    set -l destdir (cat $tmpfile)
    rm -f $tmpfile

    if test -z "$destdir"
        return 1
    end

    cd $destdir
end


Add function to check if a policy is an inline policy

function inline-policy --argument document
    if test -z "$document"
        stderr "usage: inline-policy <document>"
        return (false)
    end

    echo $document | grep -q '\.json$'
end


function weather.fetch -d "Fetches data from a URL backed by a cache"
  set md5 (__md5 "$argv")
  set cache_age (config weather -g cache-age)

  if test (count $argv) -gt 1
    for param in $argv[2..-1]
      set flags $flags --data-urlencode $param
    end
  end

  if not find /tmp/$md5.url -mmin +$cache_age > /dev/null ^ /dev/null
    curl -Gs $flags $argv[1] > /tmp/$md5.url
      or return 1
  end

  cat /tmp/$md5.url
end

function __md5
  # Use GNU coreutils if available.
  if type -q md5sum
    echo $argv[1] | md5sum | cut -d ' ' -f 1
    return 0
  end

  # Use BSD md5 utility if available.
  if type -q md5
    md5 -q -s "$argv[1]"
    return 0
  end

  # Try using openssl.
  if type -q openssl
    echo $argv[1] | openssl md5 -r | cut -d ' ' -f 1
    return 0
  end

  return 1
end

Make stderr redirection compatible with Fish 3.0.

function weather.fetch -d "Fetches data from a URL backed by a cache"
  set md5 (__md5 "$argv")
  set cache_age (config weather -g cache-age)

  if test (count $argv) -gt 1
    for param in $argv[2..-1]
      set flags $flags --data-urlencode $param
    end
  end

  if not find /tmp/$md5.url -mmin +$cache_age > /dev/null 2> /dev/null
    curl -Gs $flags $argv[1] > /tmp/$md5.url
      or return 1
  end

  cat /tmp/$md5.url
end

function __md5
  # Use GNU coreutils if available.
  if type -q md5sum
    echo $argv[1] | md5sum | cut -d ' ' -f 1
    return 0
  end

  # Use BSD md5 utility if available.
  if type -q md5
    md5 -q -s "$argv[1]"
    return 0
  end

  # Try using openssl.
  if type -q openssl
    echo $argv[1] | openssl md5 -r | cut -d ' ' -f 1
    return 0
  end

  return 1
end


# name: RobbyRussel
function _git_branch_name
  echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
end

function _is_git_dirty
  echo (command git status -s --ignore-submodules=dirty ^/dev/null)
end

function fish_prompt
  set -l last_status $status
  set -l cyan (set_color -o cyan)
  set -l yellow (set_color -o yellow)
  set -l red (set_color -o red)
  set -l blue (set_color -o blue)
  set -l green (set_color -o green)
  set -l normal (set_color normal)

  if test $last_status = 0
      set arrow "$green➜ "
  else
      set arrow "$red➜ "
  end
  set -l cwd $cyan(basename (prompt_pwd))

  if [ (_git_branch_name) ]
    set -l git_branch $red(_git_branch_name)
    set git_info "$blue git:($git_branch$blue)"

    if [ (_is_git_dirty) ]
      set -l dirty "$yellow ✗"
      set git_info "$git_info$dirty"
    end
  end

  echo -n -s $arrow $cwd $git_info $normal ' '
end

Add space between the arrow and current directory name in robbyrussell theme

# name: RobbyRussel
function _git_branch_name
  echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
end

function _is_git_dirty
  echo (command git status -s --ignore-submodules=dirty ^/dev/null)
end

function fish_prompt
  set -l last_status $status
  set -l cyan (set_color -o cyan)
  set -l yellow (set_color -o yellow)
  set -l red (set_color -o red)
  set -l blue (set_color -o blue)
  set -l green (set_color -o green)
  set -l normal (set_color normal)

  if test $last_status = 0
      set arrow "$green➜ "
  else
      set arrow "$red➜ "
  end
  set -l cwd $cyan(basename (prompt_pwd))

  if [ (_git_branch_name) ]
    set -l git_branch $red(_git_branch_name)
    set git_info "$blue git:($git_branch$blue)"

    if [ (_is_git_dirty) ]
      set -l dirty "$yellow ✗"
      set git_info "$git_info$dirty"
    end
  end

  echo -n -s $arrow ' ' $cwd $git_info $normal ' '
end


function bb
    set machine (scutil --get LocalHostName)

    if [ -d $DOTFILES/machines/$machine ]
        set brewfile_path $DOTFILES/machines/$machine/Brewfile
        echo "-> Bundling Brewfile located at $brewfile_path"
        sleep 2
        brew bundle --file $brewfile_path
    else if [ -e $HOME/Brewfile ]
        echo "-> Bundling Brewfile located at $HOME/Brewfile"
        sleep 2
        brew bundle --no-lock --file $HOME/Brewfile
    else
        echo "Brewfile not found."
    end
end

Use HostName instead of LocalHostName.

function bb
    set machine (scutil --get HostName)

    if [ -d $DOTFILES/machines/$machine ]
        set brewfile_path $DOTFILES/machines/$machine/Brewfile
        echo "-> Bundling Brewfile located at $brewfile_path"
        sleep 2
        brew bundle --file $brewfile_path
    else if [ -e $HOME/Brewfile ]
        echo "-> Bundling Brewfile located at $HOME/Brewfile"
        sleep 2
        brew bundle --no-lock --file $HOME/Brewfile
    else
        echo "Brewfile not found."
    end
end


fortune sadserver_tweets | cowsay
set -gx EDITOR /usr/local/bin/vim
set -gx BUNDLER_EDITOR $EDITOR
set -gx TERM "screen-256color"

# Manpage settings {{{
set -gx MANPAGER "less -X"
# }}}

set -gx COPYFILE_DISABLE true

# PATH {{{
append-to-path ~/bin
prepend-to-path /usr/local/sbin
append-to-path /Applications/Postgres.app/Contents/Versions/9.6/bin
# }}}

set JDK jdk1.8.0_92.jdk
set -gx JAVA_HOME /Library/Java/JavaVirtualMachines/$JDK/Contents/Home

# Go {{{
set -gx GOPATH ~/go
append-to-path $GOPATH
# }}}

# Set locale
set -gx LC_ALL en_US.UTF-8
set -gx LANG en_US.UTF-8

Add Oracle libs to PATH

fortune sadserver_tweets | cowsay
set -gx EDITOR /usr/local/bin/vim
set -gx BUNDLER_EDITOR $EDITOR
set -gx TERM "screen-256color"

# Manpage settings {{{
set -gx MANPAGER "less -X"
# }}}

set -gx COPYFILE_DISABLE true

# PATH {{{
append-to-path ~/bin
prepend-to-path /usr/local/sbin
append-to-path /Applications/Postgres.app/Contents/Versions/9.6/bin
# }}}

set JDK jdk1.8.0_92.jdk
set -gx JAVA_HOME /Library/Java/JavaVirtualMachines/$JDK/Contents/Home

# Go {{{
set -gx GOPATH ~/go
append-to-path $GOPATH
# }}}

# Oracle {{{
append-to-path ~/instantclient_12_1
# }}}

# Set locale
set -gx LC_ALL en_US.UTF-8
set -gx LANG en_US.UTF-8


# thefuck
if which thefuck > /dev/null
  thefuck --alias | source
end

# allows sudo to use aliases
function sudo
  command sudo -sE $argv
end

# better ls
function ls
  switch (uname)
  case Darwin
    command ls -lhFG $argv
  case Linux
    command ls -lhF --color=auto $argv
  end
end

function la
  switch (uname)
  case Darwin
    command ls -lhFGA $argv
  case Linux
    command ls -lhFA --color=auto $argv
  end
end

# because I like pain
function yay
  command yay --noconfirm $argv
end

# symlink by default
function ln
  command ln -s $argv
end

# work on directories
function cp
  command cp -r $argv
end

function rm
  command rm -rf $argv
end

function mkdir
  command mkdir -p $argv
end

# typed racket
function racket
  command racket -I typed/racket $argv
end

# nvim
function vim
  command nvim $argv
end

# rsync options
function rcp
  command rsync -avzHE --progress -h $argv
end

# mkdir and cd into it
function mkcd
  command mkdir -p $argv
  cd $argv
end

# cd .. repeatedly
function up
  cd (eval printf ../%.0s (seq 1 $argv))
end

# make CLI ripgrep match fzf
function ag
  command ag --hidden --ignore .git --smart-case $argv
end

Define la in terms of ls alias

# thefuck
if which thefuck > /dev/null
  thefuck --alias | source
end

# allows sudo to use aliases
function sudo
  command sudo -sE $argv
end

# better ls
function ls
  switch (uname)
  case Darwin
    command ls -lhFG $argv
  case Linux
    command ls -lhF --color=auto $argv
  end
end

function la
  ls -A $argv
end

# because I like pain
function yay
  command yay --noconfirm $argv
end

# symlink by default
function ln
  command ln -s $argv
end

# work on directories
function cp
  command cp -r $argv
end

function rm
  command rm -rf $argv
end

function mkdir
  command mkdir -p $argv
end

# typed racket
function racket
  command racket -I typed/racket $argv
end

# nvim
function vim
  command nvim $argv
end

# rsync options
function rcp
  command rsync -avzHE --progress -h $argv
end

# mkdir and cd into it
function mkcd
  command mkdir -p $argv
  cd $argv
end

# cd .. repeatedly
function up
  cd (eval printf ../%.0s (seq 1 $argv))
end

# make CLI ag match fzf
function ag
  command ag --hidden --ignore .git --smart-case $argv
end


function update-groups
    for group in (get iam/groups)
        group-exists $group
        or create-group $group
        and begin
            for policy in (get iam/groups/$group/policies)
                apply-policy iam/groups/$group/policies/$policy
            end
            for user in (get iam/groups/$group/users)
                add-user-to-group $user $group
            end
        end
    end
end


function _pure_prompt_host
    set --local hostname (hostname -s) # current host name
    set --local hostname_color "$pure_host_color"

    echo "$hostname_color$hostname"
end

Change hostname variable name to avoid scope error

function _pure_prompt_host
    set -qg hostname
    or set --local hostname (hostname -s) # current host name
    set --local hostname_color "$pure_host_color"

    echo "$hostname_color$hostname"
end


function __z_add -d "Add PATH to .z file"
  set -l path (command dirname (status -f))

  for i in $Z_EXCLUDE
    if contains -- $PWD $i
      return 0 #Path excluded
    end
  end

  set -l tmpfile (mktemp $Z_DATA.XXXXXX)

  if test -f $tmpfile
    command awk -v path="$PWD" -v now=(date +%s) -F "|" -f $path/zadd.awk $Z_DATA ^ /dev/null > $tmpfile
    cat $tmpfile > $Z_DATA
    rm $tmpfile
  end

  __z_complete
end

Use base `rm` for removing tempfile

function __z_add -d "Add PATH to .z file"
  set -l path (command dirname (status -f))

  for i in $Z_EXCLUDE
    if contains -- $PWD $i
      return 0 #Path excluded
    end
  end

  set -l tmpfile (mktemp $Z_DATA.XXXXXX)

  if test -f $tmpfile
    command awk -v path="$PWD" -v now=(date +%s) -F "|" -f $path/zadd.awk $Z_DATA ^ /dev/null > $tmpfile
    cat $tmpfile > $Z_DATA
    command rm $tmpfile
  end

  __z_complete
end


function missing --argument subject
    if empty "$subject"
        usage missing '<subject>'
        return (false)
    end

    if not functions --query real-$subject
        echo "No real-$subject function defined" >& 2
        return (false)
    end

    comm -13 (eval real-$subject | psub) (get $subject | psub)
end

Sort results before sending to comm

function missing --argument subject
    if empty "$subject"
        usage missing '<subject>'
        return (false)
    end

    if not functions --query real-$subject
        echo "No real-$subject function defined" >& 2
        return (false)
    end

    comm -13 (eval real-$subject | sort | psub) (get $subject | sort | psub)
end


function add_to_path -d "Add the given directory to user's path"
	if test -d $argv
		set -gx fish_user_paths $fish_user_paths $argv
	end
end
add_to_path $GOROOT/bin
add_to_path $GOPATH/bin
add_to_path ~/.local/bin
add_to_path /usr/bin/core_perl
add_to_path ~/sh

Create matlab branch and add matlab bin to $PATH

function add_to_path -d "Add the given directory to user's path"
	if test -d $argv
		set -gx fish_user_paths $fish_user_paths $argv
	end
end
add_to_path $GOROOT/bin
add_to_path $GOPATH/bin
add_to_path ~/.local/bin
add_to_path /usr/bin/core_perl
add_to_path ~/sh
add_to_path /home/_/nummen/matlab/bin


function __combineimgs_help
  printf "Usage: combineimgs [OPTIONS] INPUT OUTPUT\n\n"
  printf "OPTIONS:\n\n"
  printf "    -h --help     Show usage and examples\n"
  printf "    --horizontal  Stack images left to right\n"
  printf "    --vertical    Stack images top to bottom (default)\n\n"
  printf "Examples:\n\n"
  printf "    combineimgs photo-1.png photo-2.png memories.png\n"
  printf "    combineimgs drawing-*.jpg comic.jpg --horizontal\n"
end

function combineimgs --description "Combine images"
  set --local options 'h/help' 'horizontal' 'vertical'

  argparse --exclusive="horizontal,vertical" $options -- $argv

  if set --query _flag_help
    __combineimgs_help
    return 0
  end

  set --local argc (count $argv)

  if test $argc -lt 3
    echo "Error: Expected at least 3 args, got $argc" >&2
    return 1
  end

  set --local input $argv[1..-2]
  set --local output $argv[-1]

  if set --query _flag_horizontal
    convert +append $input $output
  else
    convert -append $input $output
  end
end

Print help when wrong number of args passed

function __combineimgs_help
  printf "Usage: combineimgs [OPTIONS] INPUT OUTPUT\n\n"
  printf "OPTIONS:\n\n"
  printf "    -h --help     Show usage and examples\n"
  printf "    --horizontal  Stack images left to right\n"
  printf "    --vertical    Stack images top to bottom (default)\n\n"
  printf "Examples:\n\n"
  printf "    combineimgs photo-1.png photo-2.png memories.png\n"
  printf "    combineimgs drawing-*.jpg comic.jpg --horizontal\n"
end

function combineimgs --description "Combine images"
  set --local options 'h/help' 'horizontal' 'vertical'

  argparse --exclusive="horizontal,vertical" $options -- $argv

  if set --query _flag_help
    __combineimgs_help
    return 0
  end

  set --local argc (count $argv)

  if test $argc -lt 3
    echo "Error: Expected at least 3 args, got $argc" >&2
    __combineimgs_help
    return 1
  end

  set --local input $argv[1..-2]
  set --local output $argv[-1]

  if set --query _flag_horizontal
    convert +append $input $output
  else
    convert -append $input $output
  end
end


mkdir -p ~/bin ~/npm/bin ~/.cargo/bin ~/.gem/ruby/2.5.0/bin
set -gx PATH ~/bin ~/npm/bin ~/.cargo/bin ~/.gem/ruby/2.5.0/bin $PATH

set -gx fish_greeting ""
set -gx LANG en_GB.UTF-8
set -gx BROWSER firefox
set -gx EDITOR nvim
set -gx VISUAL nvim

set -gx FZF_DEFAULT_COMMAND "rg --files --hidden --follow -g \"!.git/\" 2> /dev/null"
set -gx FZF_CTRL_T_COMMAND $FZF_DEFAULT_COMMAND

# Kill all running containers.
alias dockerkill='docker kill (docker ps -q)'

# Delete all docker images and containers.
alias dockernuke='docker rm (docker ps -a -q); docker rmi -f (docker images -q)'

# Other git aliases are in git config
alias g="git"

# Some software still uses vimdiff
alias vimdiff="nvim -d"

# Start an SSH agent if required, if not, connect to it.
initialise_ssh_agent

# Prevent funky output inside emacs terminals.
if test "$TERM" = "eterm-color"
  function fish_title; end
end

# Local config.
if [ -f ~/.local.fish ]
  source ~/.local.fish
end

Add another dumb fish binding

mkdir -p ~/bin ~/npm/bin ~/.cargo/bin ~/.gem/ruby/2.5.0/bin
set -gx PATH ~/bin ~/npm/bin ~/.cargo/bin ~/.gem/ruby/2.5.0/bin $PATH

set -gx fish_greeting ""
set -gx LANG en_GB.UTF-8
set -gx BROWSER firefox
set -gx EDITOR nvim
set -gx VISUAL nvim

set -gx FZF_DEFAULT_COMMAND "rg --files --hidden --follow -g \"!.git/\" 2> /dev/null"
set -gx FZF_CTRL_T_COMMAND $FZF_DEFAULT_COMMAND

# Kill all running containers.
alias dockerkill='docker kill (docker ps -q)'

# Delete all docker images and containers.
alias dockernuke='docker rm (docker ps -a -q); docker rmi -f (docker images -q)'

# Other git aliases are in git config
alias g="git"
alias gg="g a .; and g c -a"

# Some software still uses vimdiff
alias vimdiff="nvim -d"

# Start an SSH agent if required, if not, connect to it.
initialise_ssh_agent

# Prevent funky output inside emacs terminals.
if test "$TERM" = "eterm-color"
  function fish_title; end
end

# Local config.
if [ -f ~/.local.fish ]
  source ~/.local.fish
end


Add a function to find Min/Max number in a numerical array

function arrayminmax -d 'Find Min and Max number in an array and store in global f_ArrayMinMax_Min/f_ArrayMinMax_Max'
	set arrayName $argv  	# This is how to declare / initialize an array
	set max $arrayName[1]	# Use choose first element of array as initial values for min/max; (Defensive programming)
	set min $arrayName[1]	#
	for i in $arrayName  	# Loop through all elements in the array and update Max/Min if found a higher/lower element
	  if test $i -gt $max; set max $i; end
	  if test $i -lt $min; set min $i; end
	end
	# Output results:
	set -g f_ArrayMinMax_Min $min
	set -g f_ArrayMinMax_Max $max
	# echo "Max is: $f_ArrayMinMax_Max"
	# echo "Min is: $f_ArrayMinMax_Min"
end


function elastic-ips --argument-names resource
    set --local resource_type (echo "$resource" | cut -f 1 -d '-')
    if test "$resource_type" = 'eni'
        aws ec2 describe-network-interfaces --filters=Name=network-interface-id,Values=$resource | jq --raw-output .NetworkInterfaces[].Association.PublicIp
    else
        set --local filter
        switch "$resource_type"
            case 'i'
                set filter instance-id
            case 'eipassoc'
                set filter association-id
            case 'eipalloc'
                set filter allocation-id
        end

        if test ! -z "$filter"
            aws ec2 describe-addresses --filters Name=$filter,Values=$resource | jq --raw-output .Addresses[].PublicIp
        else
            aws ec2 describe-addresses | jq --raw-output .Addresses[].PublicIp
        end
    end
end


status --is-interactive; and source (pyenv init - | psub)
status --is-interactive; and source (pyenv virtualenv-init - | psub)
set PATH "$HOME/.local/bin" $PATH
# https://docs.python-guide.org/dev/pip-virtualenv/#requiring-an-active-virtual-environment-for-pip
set -x PIP_REQUIRE_VIRTUALENV true

Use Sublime Text as default editor, if available

status --is-interactive; and source (pyenv init - | psub)
status --is-interactive; and source (pyenv virtualenv-init - | psub)
set PATH "$HOME/.local/bin" $PATH
# https://docs.python-guide.org/dev/pip-virtualenv/#requiring-an-active-virtual-environment-for-pip
set -x PIP_REQUIRE_VIRTUALENV true

if type -q subl
  set -x EDITOR subl
else
  set -x EDITOR vi
end;


function __gabbr_expand

    if test (string trim (commandline -b)) = ''
        return
    end

    # expand abbreviations
    if test 0 = (count (commandline -poc))
        for abbr in $fish_user_abbreviations
            echo $abbr | read word phrase
            if test "$word" = (commandline -t)
                commandline -t $phrase
            end
        end
    end

    # expand global abbreviations
    for abbr in $global_abbreviations
        echo $abbr | read word phrase

        if string match -q -- "*.$word" (commandline -t)
            if string match -q -- '-x *' $phrase
                set -l file (commandline -t)
                if test 0 = (count (commandline -poc))
                    set -l cmd (string sub -s 4 -- $phrase)
                    commandline -t "$cmd $file"
                end
            end
        else if test "$word" = (commandline -t)
            if string match -q -- '-x *' $phrase
                # do nothing
            else if string match -q -- '-f *' $phrase
                # --function option
                set -l cmd (string sub -s 4 -- $phrase)
                eval $cmd ^/dev/null | string join ' ' | read -l buf
                and commandline -t $buf
            else
                commandline -t $phrase
            end
        end
    end

end

Expand user abbreviations without using $fish_user_abbreviations

function __gabbr_expand

    if test (string trim (commandline -b)) = ''
        return
    end

    # expand abbreviations
    if test 0 = (count (commandline -poc))
        for word in (abbr -l)
            if test "$word" = (commandline -t)
                set escaped_word (string escape --style=var -- $word)
                set phrase "_fish_abbr_$escaped_word"
                commandline -t $$phrase
            end
        end
    end

    # expand global abbreviations
    for abbr in $global_abbreviations
        echo $abbr | read word phrase

        if string match -q -- "*.$word" (commandline -t)
            if string match -q -- '-x *' $phrase
                set -l file (commandline -t)
                if test 0 = (count (commandline -poc))
                    set -l cmd (string sub -s 4 -- $phrase)
                    commandline -t "$cmd $file"
                end
            end
        else if test "$word" = (commandline -t)
            if string match -q -- '-x *' $phrase
                # do nothing
            else if string match -q -- '-f *' $phrase
                # --function option
                set -l cmd (string sub -s 4 -- $phrase)
                eval $cmd ^/dev/null | string join ' ' | read -l buf
                and commandline -t $buf
            else
                commandline -t $phrase
            end
        end
    end

end


########## env ##########

##### locale #####
set -gx LANG en_US.UTF-8

##### term #####
set -gx TERM xterm-256color

##### path #####
set -l local_paths /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin

# go
set -gx GOPATH $HOME/dev
set local_paths $GOPATH/bin $local_paths

# rust
set local_paths ~/.cargo/bin $local_paths

# pyenv
set local_paths ~/.pyenv/bin $local_paths
set local_paths ~/.pyenv/shims $local_paths

# rbenv
set local_paths ~/.rbenv/bin $local_paths
set local_paths ~/.rbenv/shims $local_paths

# update PATH via fish_user_paths
set -g fish_user_paths $local_paths

##### misc #####
set -gx GHQ_ROOT $GOPATH/src
set -gx TMUX_PLUGIN_MANAGER_PATH ~/.config/tmux/plugins/

########## alias ##########

alias e 'emacsclient -nw -a ""'
alias ekill 'emacsclient -e "(kill-emacs)"'
alias g 'git'
alias fzf 'fzf-tmux'

########## plugins ##########

if not functions -q fisher
    set -q XDG_CONFIG_HOME
    or set XDG_CONFIG_HOME ~/.config
    curl https://git.io/fisher --create-dirs -sLo $XDG_CONFIG_HOME/fish/functions/fisher.fish
    fish -c fisher
end

Refactor path setting by using brace expansion

########## env ##########

##### locale #####
set -gx LANG en_US.UTF-8

##### term #####
set -gx TERM xterm-256color

##### path #####
set -l local_paths /usr/local/{sbin,bin} /usr/{sbin,bin} /{sbin,bin}

# go
set -gx GOPATH $HOME/dev
set local_paths $GOPATH/bin $local_paths

# rust
set local_paths ~/.cargo/bin $local_paths

# pyenv
set local_paths ~/.pyenv/{bin,shims} $local_paths

# rbenv
set local_paths ~/.rbenv/{bin,shims} $local_paths

# update PATH via fish_user_paths
set -g fish_user_paths $local_paths

##### misc #####
set -gx GHQ_ROOT $GOPATH/src
set -gx TMUX_PLUGIN_MANAGER_PATH ~/.config/tmux/plugins/

########## alias ##########

alias e 'emacsclient -nw -a ""'
alias ekill 'emacsclient -e "(kill-emacs)"'
alias g 'git'
alias fzf 'fzf-tmux'

########## plugins ##########

if not functions -q fisher
    set -q XDG_CONFIG_HOME
    or set XDG_CONFIG_HOME ~/.config
    curl https://git.io/fisher --create-dirs -sLo $XDG_CONFIG_HOME/fish/functions/fisher.fish
    fish -c fisher
end


function ..; cd ..; end
function ...; cd ../..; end
function ....; cd ../../..; end

# Enable colour output for ls
function ls
    command ls --color=auto $argv
end

Move ls alias to function


set -x PATH ~/.local/bin $PATH

alias vim nvim
alias vi nvim

alias ghc 'stack exec -- ghc'
alias ghci 'stack exec -- ghci'

Add `tree` alias that show hidden files, ignoring the git directory

set -x PATH ~/.local/bin $PATH

alias vim nvim
alias vi nvim

alias ghc 'stack exec -- ghc'
alias ghci 'stack exec -- ghci'

alias treea 'tree -a -I .git'


set -U EDITOR vim
set -g fish_key_bindings fish_vi_key_bindings

alias phpgrep='find . -type f -name "*.php" -print0 | xargs -0 grep -n $1'
alias jsgrep='find . -type f -name "*.js" -print0 | xargs -0 grep -n $1'

alias c='cd ~/code'
alias d='cd ~/Downloads'
alias dt='cd ~/Desktop'
alias mc='cd ~/code/automattic-sandbox/missioncontrol/public_html'
alias uni='unison -ui text -repeat watch automattic-sandbox'
alias wpcom='cd ~/code/automattic-sandbox/wpcom/public_html'
alias www='cd ~/vagrant-local/www'

Clear out default fish greeting, jsgrep .jsx files too

set -U EDITOR vim
set -g -x fish_greeting ''
set -g fish_key_bindings fish_vi_key_bindings

alias phpgrep='find . -type f -name "*.php" -print0 | xargs -0 grep -n $1'
alias jsgrep='find . -type f -name "*.js" -o -name "*.jsx" -print0 | xargs -0 grep -n $1'

alias c='cd ~/code'
alias d='cd ~/Downloads'
alias dt='cd ~/Desktop'
alias mc='cd ~/code/automattic-sandbox/missioncontrol/public_html'
alias uni='unison -ui text -repeat watch automattic-sandbox'
alias wpcom='cd ~/code/automattic-sandbox/wpcom/public_html'
alias www='cd ~/vagrant-local/www'


# name: Zish

function _is_git_dirty
  echo (command git status -s --ignore-submodules=dirty ^/dev/null)
end

function fish_prompt
  set_color -o red
  printf '┌─<'
  set_color -o blue
  printf '%s ' (whoami)
  set_color $fish_color_autosuggestion[1]
  printf '@ '
  set_color cyan
  printf '%s ' (hostname|cut -d . -f 1)
  set_color $fish_color_autosuggestion[1]
  printf 'in '
  set_color -o green
  printf '%s' (prompt_pwd)
  set_color -o red
  printf '>'

  echo
  set_color -o red
  printf '└─<'
  set_color yellow
  printf '%s' (__fish_git_prompt)
  if [ (_is_git_dirty) ]
    set_color blue
    printf '* '
  end
  set_color -o red
  printf '>──'
  set_color yellow
  printf '» '
  set_color normal
end

Make stderr redirection compatible with Fish 3.0.

# name: Zish

function _is_git_dirty
  echo (command git status -s --ignore-submodules=dirty 2> /dev/null)
end

function fish_prompt
  set_color -o red
  printf '┌─<'
  set_color -o blue
  printf '%s ' (whoami)
  set_color $fish_color_autosuggestion[1]
  printf '@ '
  set_color cyan
  printf '%s ' (hostname|cut -d . -f 1)
  set_color $fish_color_autosuggestion[1]
  printf 'in '
  set_color -o green
  printf '%s' (prompt_pwd)
  set_color -o red
  printf '>'

  echo
  set_color -o red
  printf '└─<'
  set_color yellow
  printf '%s' (__fish_git_prompt)
  if [ (_is_git_dirty) ]
    set_color blue
    printf '* '
  end
  set_color -o red
  printf '>──'
  set_color yellow
  printf '» '
  set_color normal
end


source /Users/$USER/.config/fish/functions/docker.fish
# Path to Oh My Fish install.
set -gx OMF_PATH /Users/$USER/.local/share/omf

# Customize Oh My Fish configuration path.
#set -gx OMF_CONFIG /Users/$USER/.config/omf

# Load oh-my-fish configuration.
#source $OMF_PATH/init.fish

set -x GOPATH /Users/$USER/gocode
set -x PATH /opt/boxen/homebrew/bin/ $PATH $GOPATH/bin

Add fig alias for old times' sake

source /Users/$USER/.config/fish/functions/docker.fish
# Path to Oh My Fish install.
set -gx OMF_PATH /Users/$USER/.local/share/omf

# Customize Oh My Fish configuration path.
#set -gx OMF_CONFIG /Users/$USER/.config/omf

# Load oh-my-fish configuration.
#source $OMF_PATH/init.fish

set -x GOPATH /Users/$USER/gocode
set -x PATH /opt/boxen/homebrew/bin/ $PATH $GOPATH/bin

alias fig "docker-compose"


set -x PATH /usr/local/bin $PATH
set -x PATH /usr/local/heroku/bin $PATH

set -U EDITOR mvim
set RUBY_GC_MALLOC_LIMIT 60000000
set RUBY_FREE_MIN 200000

#rbenv
set -x PATH $HOME/.rbenv/bin $PATH
set -x PATH $HOME/.rbenv/shims $PATH
rbenv rehash >/dev/null ^&1

#aliases
alias rake='bundle exec rake'
alias spec='bundle exec spec'
alias rspec='bundle exec rspec'
alias clear_drive='rm -rf .fseventsd ._.Trashes .Trashes .Spotlight-V100'

Add npm path for all users

set -x PATH /usr/local/bin $PATH
set -x PATH /usr/local/heroku/bin $PATH
set -x PATH /usr/local/share/npm/bin $PATH

set -U EDITOR mvim
set RUBY_GC_MALLOC_LIMIT 60000000
set RUBY_FREE_MIN 200000

#rbenv
set -x PATH $HOME/.rbenv/bin $PATH
set -x PATH $HOME/.rbenv/shims $PATH
rbenv rehash >/dev/null ^&1

#aliases
alias rake='bundle exec rake'
alias spec='bundle exec spec'
alias rspec='bundle exec rspec'
alias clear_drive='rm -rf .fseventsd ._.Trashes .Trashes .Spotlight-V100'


#!/usr/bin/env fish

alias rm="trash"
alias t="todo.sh -d ~/.config/todo/config"
alias bk=bookkeeping

# Navigation
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias wo=workon

# VCS
alias g="git"
alias gx="gitx"
alias gp="git push"
alias gs="git status"

Add alias to enable default virtualenv

#!/usr/bin/env fish

alias rm="trash"
alias t="todo.sh -d ~/.config/todo/config"
alias bk=bookkeeping
alias activate="source ~/.local/venv/bin/activate.fish"

# Navigation
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias wo=workon

# VCS
alias g="git"
alias gx="gitx"
alias gp="git push"
alias gs="git status"


# Disable the default venv display override. This is here so I don't
# forget to do it elsewhere and it involves the prompt.
set -g VIRTUAL_ENV_DISABLE_PROMPT true

function fish_prompt --description 'Write out the prompt'
    echo "" # Add a blank line before the prompt

    set -l user_color af87ff
    set -l user_symbol \$
    if [ $USER = root ]
        set user_color d75f5f
        set user_symbol \#
    end

    echo -n -s [(set_color $user_color)$USER(set_color reset)@(set_color 5fafd7)(prompt_hostname)(set_color reset)]

    set -l git_prompt (fish_git_prompt "%s")
    if [ -n "$git_prompt" ]
        echo -n -s "[G:" $git_prompt (set_color reset) "]"
    end

    # Disable the default virtual env prompt
    if set -q VIRTUAL_ENV
        echo -n -s "[P:" (set_color a838a6) (basename $VIRTUAL_ENV) (set_color reset) "]"
    end

    kubernetes_prompt

    echo "" # Finish the first line
    echo -s (prompt_pwd) " $user_symbol "
end

function kubernetes_prompt --description 'Write out the kubernetes info'
    set -l cur_context (kubectl config current-context | string trim)
    if [ -n "$cur_context" ]
        echo -n -s "[K:" (set_color 5fafd7) $cur_context (set_color reset) "]"
    end
end

Fix kubectl info when kubectl isn't installed

# Disable the default venv display override. This is here so I don't
# forget to do it elsewhere and it involves the prompt.
set -g VIRTUAL_ENV_DISABLE_PROMPT true

function fish_prompt --description 'Write out the prompt'
    echo "" # Add a blank line before the prompt

    set -l user_color af87ff
    set -l user_symbol \$
    if [ $USER = root ]
        set user_color d75f5f
        set user_symbol \#
    end

    echo -n -s [(set_color $user_color)$USER(set_color reset)@(set_color 5fafd7)(prompt_hostname)(set_color reset)]

    set -l git_prompt (fish_git_prompt "%s")
    if [ -n "$git_prompt" ]
        echo -n -s "[G:" $git_prompt (set_color reset) "]"
    end

    # Disable the default virtual env prompt
    if set -q VIRTUAL_ENV
        echo -n -s "[P:" (set_color a838a6) (basename $VIRTUAL_ENV) (set_color reset) "]"
    end

    kubernetes_prompt

    echo "" # Finish the first line
    echo -s (prompt_pwd) " $user_symbol "
end

function kubernetes_prompt --description 'Write out the kubernetes info'
    if not type -q kubectl
        return
    end

    set -l cur_context (kubectl config current-context | string trim)
    if [ -n "$cur_context" ]
        echo -n -s "[K:" (set_color 5fafd7) $cur_context (set_color reset) "]"
    end
end


set LS_COLORS dxfxcxdxbxegedabagacad

function serve
        if test (count $argv) -ge 1
            if python -c 'import sys; sys.exit(sys.version_info[0] != 3)'
                /bin/sh -c "(cd $argv[1] && python -m http.server)"
            else
                /bin/sh -c "(cd $argv[1] && python -m SimpleHTTPServer)"
            end
        else
            python -m SimpleHTTPServer
        end
end

alias ls 'command ls -FG'
alias l ls
alias ll 'ls -la'
alias rm 'rm -i'
alias mv 'mv -i'
alias mkdir 'mkdir -p'
alias du 'du -kh'
alias df 'df -kh'

# Colorized cat (will guess file type based on contents)
alias ccat 'pygmentize -g'

alias pm 'python manage.py'
alias pmm 'python manage.py migrate'
alias pmmm 'python manage.py makemigrations'
alias pms 'python manage.py shell'
alias pmsp 'python manage.py shell_plus'
alias pmr 'python manage.py runserver'
alias ipn 'ipython notebook'

alias git hub
alias top 'glances'

alias pkill-emacs 'pkill -SIGUSR2 Emacs'

alias .. 'cd ..'
alias ... 'cd ../..'
alias .... 'cd ../../..'
alias ..... 'cd ../../../..'

alias psql pgcli

alias gp='cd ~/projects/gitprime.com/GitPrime'

Add alias for `python manage.py showmigrations`

set LS_COLORS dxfxcxdxbxegedabagacad

function serve
        if test (count $argv) -ge 1
            if python -c 'import sys; sys.exit(sys.version_info[0] != 3)'
                /bin/sh -c "(cd $argv[1] && python -m http.server)"
            else
                /bin/sh -c "(cd $argv[1] && python -m SimpleHTTPServer)"
            end
        else
            python -m SimpleHTTPServer
        end
end

alias ls 'command ls -FG'
alias l ls
alias ll 'ls -la'
alias rm 'rm -i'
alias mv 'mv -i'
alias mkdir 'mkdir -p'
alias du 'du -kh'
alias df 'df -kh'

# Colorized cat (will guess file type based on contents)
alias ccat 'pygmentize -g'

alias pm 'python manage.py'
alias pmm 'python manage.py migrate'
alias pmmm 'python manage.py makemigrations'
alias pms 'python manage.py shell'
alias pmsp 'python manage.py shell_plus'
alias pmr 'python manage.py runserver'
alias ipn 'ipython notebook'
alias pmsm 'python manage.py showmigrations'

alias git hub
alias top 'glances'

alias pkill-emacs 'pkill -SIGUSR2 Emacs'

alias .. 'cd ..'
alias ... 'cd ../..'
alias .... 'cd ../../..'
alias ..... 'cd ../../../..'

alias psql pgcli

alias gp='cd ~/projects/gitprime.com/GitPrime'


## Aliases
alias vi="nvim"
alias vim="nvim"
alias git="hub"
alias sudo="sudo -E "
alias diff="colordiff -u"
alias ctags="/usr/local/bin/ctags"
alias deckset="open -a Deckset"
alias rm="rm -i"
alias zatsu="memo edit zatsu.md"
alias ls="exa"
alias ghqg="$GOPATH/bin/get -shallow -unshallow ghq"

## Abbreviations
abbr -a b "bundle"
abbr -a v "vagrant"
abbr -a k "kubectl"
abbr -a kc "kubectx"
abbr -a kn "kubens"
abbr -a d "docker"
abbr -a dc "docker-compose"
abbr -a tf "terraform"
abbr -a be "bundle exec"
abbr -a bb "brew bundle"
abbr -a gcoo "git-branch-fzf"
abbr -a docker-stop "docker ps -aq | xargs docker stop"
abbr -a docker-rm "docker ps -aq | xargs docker rm -f"
abbr -a docker-rmi "docker images -f dangling=true -q | xargs docker rmi -f"

Remove sudo alias to avoid freeze when shell completion

## Aliases
alias vi="nvim"
alias vim="nvim"
alias git="hub"
alias diff="colordiff -u"
alias ctags="/usr/local/bin/ctags"
alias deckset="open -a Deckset"
alias rm="rm -i"
alias zatsu="memo edit zatsu.md"
alias ls="exa"
alias ghqg="$GOPATH/bin/get -shallow -unshallow ghq"

## Abbreviations
abbr -a b "bundle"
abbr -a v "vagrant"
abbr -a k "kubectl"
abbr -a kc "kubectx"
abbr -a kn "kubens"
abbr -a d "docker"
abbr -a dc "docker-compose"
abbr -a tf "terraform"
abbr -a be "bundle exec"
abbr -a bb "brew bundle"
abbr -a gcoo "git-branch-fzf"
abbr -a docker-stop "docker ps -aq | xargs docker stop"
abbr -a docker-rm "docker ps -aq | xargs docker rm -f"
abbr -a docker-rmi "docker images -f dangling=true -q | xargs docker rmi -f"


Add function to revoke all keys for a user

function revoke-access-keys --argument user
    if empty "$user"
        usage revoke-access-keys '<user>'
        return (false)
    end

    for key in (user-access-keys "$user")
        revoke-access-key "$user" "$key"
    end
end


bind ' ' '__gabbr_expand; commandline -i " "'

Add config file path variable

if not set -q gabbr_config
    set -U gabbr_config "$HOME/.config/fish/.gabbr.conf"
    set -q XDG_CONFIG_HOME
    and set gabbr_config "$XDG_CONFIG_HOME/fish/.gabbr.conf"
end
bind ' ' '__gabbr_expand; commandline -i " "'


#!/usr/bin/env fish

# Git
alias ga="git add"
alias gb="git branch"
alias gc="git commit"
alias gs="git stash"
alias gbd="git build"
alias gsp="git smart-pull"
alias gst="git status"
alias gco="git checkout"
alias gcm="git checkout master"
alias gcd="git checkout develop"

function current_branch
  set ref (git symbolic-ref HEAD 2> /dev/null); or \
  set ref (git rev-parse --short HEAD 2> /dev/null); or return
  echo $ref | sed s-refs/heads/--
end

alias ggpush='git push origin (current_branch)'

# Bundler (Undo harmful from oh-my-zsh)
alias zeus > /dev/null && unalias zeus

# Rails
alias rdm='rake db:migrate && rake db:test:prepare'

# Zeus
alias zr='zeus rspec'
alias zc='zeus console'
alias zs='zeus start'
alias z='zeus'

# Quick look
alias ql='qlmanage -p "$argv" >& /dev/null'

# AWS Vault
alias ave='aws-vault exec'

Add git/bundle aliases for fish

#!/usr/bin/env fish

# Git
alias ga="git add"
alias gb="git branch"
alias gc="git commit"
alias gs="git stash"
alias gbd="git build"
alias gsp="git smart-pull"
alias gst="git status"
alias gco="git checkout"
alias gcm="git checkout master"
alias gcd="git checkout develop"
alias gcp="git cherry-pick"

function current_branch
  set ref (git symbolic-ref HEAD 2> /dev/null); or \
  set ref (git rev-parse --short HEAD 2> /dev/null); or return
  echo $ref | sed s-refs/heads/--
end

alias ggpush='git push origin (current_branch)'

# Bundler (Undo harmful from oh-my-zsh)
alias zeus > /dev/null && unalias zeus

# Rails
alias rdm='rake db:migrate && rake db:test:prepare'
alias bi='bundle install'
alias be='bundle exec'

# Zeus
alias zr='zeus rspec'
alias zc='zeus console'
alias zs='zeus start'
alias z='zeus'

# Quick look
alias ql='qlmanage -p "$argv" >& /dev/null'

# AWS Vault
alias ave='aws-vault exec'


if not status --is-interactive
    exit 0
end

set -l config_home "$XDG_CONFIG_HOME"
set -l data_home "$XDG_DATA_HOME"

# install fisher
if not type fisher >/dev/null 2>&1
    curl -Lo "$config_home/fish/functions/fisher.fish" --create-dirs git.io/fisher
    cat "$config_home/fish/fishfile" | fisher install
end

# vim bindings
fish_vi_key_bindings
bind -M insert \cd '__fzf_cd'
bind -M insert \cp '__fzf_cd_with_hidden'

# aliases
source "$config_home/fish/aliases.fish"

# fzf
if test -d "$data_home/fzf"
    set -gx PATH "$data_home/fzf/bin" $PATH
    set -gx FZF_LEGACY_KEYBINDINGS 0
end

# z
set -gx Z_CMD "j"
set -gx Z_DATA "$data_home/z"

# base16 colour scheme
if test ! -d "$data_home/base16-shell"
    git clone https://github.com/chriskempson/base16-shell.git "$data_home/base16-shell"
end

eval sh "$data_home/base16-shell/scripts/base16-oceanicnext.sh"

if [ (uname) = "Darwin" ]
    bass source "$HOME/.profile"
    set -gx GPG_TTY (tty)
end

Use tmux friendly version of fzf

if not status --is-interactive
    exit 0
end

set -l config_home "$XDG_CONFIG_HOME"
set -l data_home "$XDG_DATA_HOME"

# install fisher
if not type fisher >/dev/null 2>&1
    curl -Lo "$config_home/fish/functions/fisher.fish" --create-dirs git.io/fisher
    cat "$config_home/fish/fishfile" | fisher install
end

# vim bindings
fish_vi_key_bindings

# aliases
source "$config_home/fish/aliases.fish"

# fzf
if test -d "$data_home/fzf"
    set -gx PATH "$data_home/fzf/bin" $PATH
    set -gx FZF_LEGACY_KEYBINDINGS 0
    set -gx FZF_TMUX 1
end

# z
set -gx Z_CMD "j"
set -gx Z_DATA "$data_home/z"

# base16 colour scheme
if test ! -d "$data_home/base16-shell"
    git clone https://github.com/chriskempson/base16-shell.git "$data_home/base16-shell"
end

eval sh "$data_home/base16-shell/scripts/base16-oceanicnext.sh"

if [ (uname) = "Darwin" ]
    bass source "$HOME/.profile"
    set -gx GPG_TTY (tty)
end


function ll --wraps ls --description "List contents of directory using long format"
    ls -lh --group-directories-first $argv
end

Use --group-directories-first only if available

# detect if flag supported
if ls --group-directories-first &> /dev/null
  function ll --wraps ls --description "List contents of directory using long format"
    ls -lh --group-directories-first $argv
  end
end


#!/usr/bin/env fish

function suite_dpaste
  function setup
    set -g __dpaste_expires_choises
    source ../dpaste.fish
    __dpaste_set_defaults
  end

  function test_dpaste_parse_expires
    assert_equal text (__dpaste_parse_expires text)
    assert_equal "https://dpaste.de/api/?format=url" $__dpaste_send_url
    set -g __dpaste_send_url $dpaste_url
    assert_equal text (__dpaste_parse_expires -t never text)
    assert_equal "https://dpaste.de/api/?format=url&expires=never" $__dpaste_send_url
    set -g __dpaste_send_url $dpaste_url
    assert_equal text (__dpaste_parse_expires -t hour text)
    assert_equal "https://dpaste.de/api/?format=url&expires=3600" $__dpaste_send_url
    set -g __dpaste_send_url $dpaste_url
  end
end

if not set -q tank_running
  source (dirname (status -f))/helper.fish
  tank_run
end

Allow test run with any working directory

#!/usr/bin/env fish

set -l script_dir (dirname (status -f))

function suite_dpaste
  function setup
    set -g __dpaste_expires_choises
    source $script_dir/../dpaste.fish
    __dpaste_set_defaults
  end

  function test_dpaste_parse_expires
    assert_equal text (__dpaste_parse_expires text)
    assert_equal "https://dpaste.de/api/?format=url" $__dpaste_send_url
    set -g __dpaste_send_url $dpaste_url
    assert_equal text (__dpaste_parse_expires -t never text)
    assert_equal "https://dpaste.de/api/?format=url&expires=never" $__dpaste_send_url
    set -g __dpaste_send_url $dpaste_url
    assert_equal text (__dpaste_parse_expires -t hour text)
    assert_equal "https://dpaste.de/api/?format=url&expires=3600" $__dpaste_send_url
    set -g __dpaste_send_url $dpaste_url
  end
end

if not set -q tank_running
  source $script_dir/helper.fish
  tank_run
end


function _find_project -a pattern
  set -l paths $HOME/Projects/{2016,2015}
  find $paths -type d -maxdepth 2 | ack --ignore-case --max-count=1 $pattern
end

function pd --description 'Change to a project directory'
  set -l project (_find_project "$argv[1]\$")

  if test $status -eq 0
    return (cd $project)
  end

  set -l project (_find_project $argv[1])

  if test $status -eq 0
    return (cd $project)
  end
end

Switch to -1 ack flag

function _find_project -a pattern
  set -l paths $HOME/Projects/{2016,2015}
  find $paths -type d -maxdepth 2 | ack --ignore-case -1 $pattern
end

function pd --description 'Change to a project directory'
  set -l project (_find_project "$argv[1]\$")

  if test $status -eq 0
    return (cd $project)
  end

  set -l project (_find_project $argv[1])

  if test $status -eq 0
    return (cd $project)
  end
end