function delete-security-group --argument id
    trace (status --current-filename) $argv

    if empty $id
        usage delete-security-group '<id>'
        return 23
    end

    if security-group is-default $id
        return
    else
        switch $id
            case 'sg-*'
                aws ec2 delete-security-group --group-id $id
            case '*'
                aws ec2 delete-security-group --group-name $id
        end
    end
end


# Sets git user.name and user.email
#
# ~/.gitconfig is tracked and shared. Sensitive or machine-specific data is
# stored in the alternate global config file.
# > If $XDG_CONFIG_HOME is not set or empty, $HOME/.config/git/config will be used.
function 🗄__gitconfig --argument-names email name
    echo "🗄  Git configuration"
    echo

    createdirs ~/.config/git
    set -l global_config ~/.config/git/config

    # Just print the current config when values are set.
    if begin
            git config --file $global_config user.name >/dev/null
            and git config --file $global_config user.email >/dev/null
        end
        cat $global_config
        return
    end

    # Prompt to add required values

    if test -z $name
        get --prompt "Git user.name: " | read name
    end

    if test -z $email
        get --prompt "Git user.email: " | read email
    end

    git config --file $global_config user.name "$name"
    git config --file $global_config user.email "$email"

    echo $global_config
    cat $global_config
end

Revise logic around config checks

# Sets git user.name and user.email
#
# ~/.gitconfig is tracked and shared. Sensitive or machine-specific data is
# stored in the alternate global config file.
# > If $XDG_CONFIG_HOME is not set or empty, $HOME/.config/git/config will be used.
function 🗄__gitconfig --argument-names email name
    echo "🗄  Git configuration"
    echo

    createdirs ~/.config/git
    set -l global_config ~/.config/git/config

    # Just print the current config when values are set.
    if git config --file $global_config user.name >/dev/null
            and git config --file $global_config user.email >/dev/null
        cat $global_config
        return 0
    end

    # Prompt to add required values

    if test -z $name
        get --prompt "Git user.name: " | read name
    end

    if test -z $email
        get --prompt "Git user.email: " | read email
    end

    git config --file $global_config user.name "$name"
    git config --file $global_config user.email "$email"

    echo $global_config
    cat $global_config
end


Add function to check if user has password

function user-has-password --argument user
    if empty "$user"
        usage user-has-password '<user>'
        return (false)
    end

    aws iam get-login-profile --user-name $user > /dev/null ^ /dev/null
end


function expand:choose-next
  # 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 complete
    return
  end

  # If a filter is specified and more than one replacement is available, use it to filter through the available
  # replacements.
  if begin; set -q __expand_replacements[2]; and set -q __expand_filter; end
    for line in $__expand_replacements
      echo $line
    end | eval $__expand_filter | read -a replacement

    # Interactive filters will cause Fish to need a repaint.
    commandline -f repaint

  # Otherwise, use basic tab cycling.
  else
    # Select the top replacement.
    set replacement "$__expand_replacements[1]"
  end

  # If a replacement was chosen, use it.
  if test -n "$replacement"
    # Enquote replacements with spaces.
    if echo "$replacement" | grep -q ' '
      commandline -t -r "\"$replacement\""
    else
      commandline -t -r "$replacement"
    end
  end

  # If there are at least two replacements, cycle the replacement queue order.
  set -q __expand_replacements[2]
    and set -g __expand_replacements $__expand_replacements[2..-1] $__expand_replacements[1]
end

Remove quotes from around expansions

function expand:choose-next
  # 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 complete
    return
  end

  # If a filter is specified and more than one replacement is available, use it to filter through the available
  # replacements.
  if begin; set -q __expand_replacements[2]; and set -q __expand_filter; end
    for line in $__expand_replacements
      echo $line
    end | eval $__expand_filter | read -a replacement

    # Interactive filters will cause Fish to need a repaint.
    commandline -f repaint

  # Otherwise, use basic tab cycling.
  else
    # Select the top replacement.
    set replacement "$__expand_replacements[1]"
  end

  # If a replacement was chosen, use it.
  if test -n "$replacement"
    commandline -t -r "$replacement"
  end

  # If there are at least two replacements, cycle the replacement queue order.
  set -q __expand_replacements[2]
    and set -g __expand_replacements $__expand_replacements[2..-1] $__expand_replacements[1]
end


Add a function for extracting compressed files

function extract_archive --description "Extract from compressed files"
  for file in $argv
    if test -f $file
      echo -s "Extracting " (set_color --bold blue) $file (set_color normal)
      switch $file
        case *.tar
          tar -xvf $file
        case *.tar.bz2 *.tbz2
          tar -jxvf $file
        case *.tar.gz *.tgz
          tar -zxvf $file
        case *.bz2
          bunzip2 $file
          # Can also use: bzip2 -d $file
        case *.gz
          gunzip $file
        case *.rar
          unrar x $file
        case *.zip *.ZIP
          unzip $file
        case *.pax
          pax -r < $file
        case '*'
          echo "Extension not recognized, cannot extract $file"
      end
    else
      echo "$file is not a valid file"
    end
  end
end


# Sets git user.name and user.email
#
# ~/.gitconfig is tracked and shared. Sensitive or machine-specific data is
# stored in the alternate global config file.
# > If $XDG_CONFIG_HOME is not set or empty, $HOME/.config/git/config will be used.
function 🗄__gitconfig --argument-names email name
    echo "🗄  Git configuration"
    echo

    createdirs ~/.config/git
    set -l global_config ~/.config/git/config

    # Only print config when values are set.
    if test -n (git config --global user.name); and test -n (git config --global user.email)
        cat $global_config
        return
    end

    # Prompt to add required values

    if test -z $name
        get --prompt "Git user.name: " | read name
    end

    if test -z $email
        get --prompt "Git user.email: " | read email
    end

    git config --file $global_config user.name "$name"
    git config --file $global_config user.email "$email"

    echo $global_config
    cat $global_config
end

Fix logic on git config checks

# Sets git user.name and user.email
#
# ~/.gitconfig is tracked and shared. Sensitive or machine-specific data is
# stored in the alternate global config file.
# > If $XDG_CONFIG_HOME is not set or empty, $HOME/.config/git/config will be used.
function 🗄__gitconfig --argument-names email name
    echo "🗄  Git configuration"
    echo

    createdirs ~/.config/git
    set -l global_config ~/.config/git/config

    # Just print the current config when values are set.
    if git config --global user.name >/dev/null; and git config --global user.email >/dev/null
        cat $global_config
        return
    end

    # Prompt to add required values

    if test -z $name
        get --prompt "Git user.name: " | read name
    end

    if test -z $email
        get --prompt "Git user.email: " | read email
    end

    git config --file $global_config user.name "$name"
    git config --file $global_config user.email "$email"

    echo $global_config
    cat $global_config
end


# . ~/.env

# Leaving temporary. This doesn't belong here
# if test (tty) = '/dev/tty2' -a -z "$TOP_FISH"
#     setenv TOP_FISH '1'
#     zsh -c '. ~/.profile && fish'; and exit
# end

# You should set up path in /etc/fish/conf.d/bin.fish
# set -gx PATH $PATH ~/bin

# This should also be moved to /etc/
if not ssh-add -l >/dev/null 2>&1; and test -e ~/.ssh/id_rsa
    ssh-add ~/.ssh/id_rsa
end

# OPAM configuration
. ~/.opam/opam-init/init.fish > /dev/null 2> /dev/null or true

Delete top fish (Now in etc)

# . ~/.env

# You should set up path in /etc/fish/conf.d/bin.fish
# set -gx PATH $PATH ~/bin

# This should also be moved to /etc/
if not ssh-add -l >/dev/null 2>&1; and test -e ~/.ssh/id_rsa
    ssh-add ~/.ssh/id_rsa
end

# OPAM configuration
. ~/.opam/opam-init/init.fish > /dev/null 2> /dev/null or true


function custom_shell_init
  abbr devlog tail -f log/development.log
  abbr g git
  abbr guard bundle exec guard
  abbr l exa
  abbr b bin/rails

  set -Ux EDITOR code

  # Setup rbenv
  set PATH $HOME/.rbenv/shims $PATH
  rbenv rehash >/dev/null ^&1
end

Update editor var to wait

function custom_shell_init
  abbr devlog tail -f log/development.log
  abbr g git
  abbr guard bundle exec guard
  abbr l exa
  abbr b bin/rails

  set -Ux EDITOR 'code --wait'

  # Setup rbenv
  set PATH $HOME/.rbenv/shims $PATH
  rbenv rehash >/dev/null ^&1
end


complete fzf_configure_bindings --no-files
complete fzf_configure_bindings --long help --short h --description "Print help"
complete fzf_configure_bindings --long directory --description "Change the key binding for searching directory"
complete fzf_configure_bindings --long git_log --description "Change the key binding for searching git log"
complete fzf_configure_bindings --long git_status --description "Change the key binding for searching git status"
complete fzf_configure_bindings --long history --description "Change the key binding for searching history"
complete fzf_configure_bindings --long variables --description "Change the key binding for searching variables"


function _pure_set_default \
    --description 'Set default value for configuration variable' \
    --argument-names var default

    if not set -q --universal $var
        set --universal $var $default
    end
end

Fix empty defaults for base colors

function _pure_set_default \
    --description 'Set default value for configuration variable' \
    --argument-names var default

    if not set -q --universal $var; or test -z $$var; and not set -q --global $var
        set --universal $var $default
    end
end


function __cdgitroot_usage
    echo 'Usage: cd-gitroot [PATH]'
    echo 'Jump to git repository\'s root directory.'
    echo 'If PATH is specified, it\'s recognized as relative path'
    echo 'from repository\'s root directory. And jump to it.'
end

function cd-gitroot -d 'Jump to git repo\'s root'
    if not command git rev-parse --git-dir > /dev/null ^ /dev/null
        echo 'It\'s out of working tree!' 1>&2
        return 1
    end

    set root_path (git rev-parse --show-toplevel)
    set argc (count $argv)

    if test (count $argv) -eq 0
        cd $root_path
    else if test (count $argv) -eq 1; and test -n $relative_path
        set relative_path $argv
        cd "$root_path/$relative_path"
    else
        __cdgitroot_usage
    end
end

function __cdgitroot_complete
    set directories
    set root_path (git rev-parse --show-toplevel)
    if test $status -ne 0
        return 1
    end

    set dirs \
        (find $root_path -type d -name '.git' -prune -o -type d -print | \
                sed "s#$root_path/##g" | sed "s#$root_path##g")
    complete -c cd-gitroot --no-files -d 'path' -a "$dirs"
end
__cdgitroot_complete

Revert "Add error bundle in completion function"

function __cdgitroot_usage
    echo 'Usage: cd-gitroot [PATH]'
    echo 'Jump to git repository\'s root directory.'
    echo 'If PATH is specified, it\'s recognized as relative path'
    echo 'from repository\'s root directory. And jump to it.'
end

function cd-gitroot -d 'Jump to git repo\'s root'
    if not command git rev-parse --git-dir > /dev/null ^ /dev/null
        echo 'It\'s out of working tree!' 1>&2
        return 1
    end

    set root_path (git rev-parse --show-toplevel)
    set argc (count $argv)

    if test (count $argv) -eq 0
        cd $root_path
    else if test (count $argv) -eq 1; and test -n $relative_path
        set relative_path $argv
        cd "$root_path/$relative_path"
    else
        __cdgitroot_usage
    end
end

function __cdgitroot_complete
    set directories
    set root_path (git rev-parse --show-toplevel)
    set dirs \
        (find $root_path -type d -name '.git' -prune -o -type d -print | \
                sed "s#$root_path/##g" | sed "s#$root_path##g")
    complete -c cd-gitroot --no-files -d 'path' -a "$dirs"
end
__cdgitroot_complete


# MANAGED BY ANSIBLE, DO NOT TOUCH

# Commands to run in interactive sessions can go here
if status is-interactive
    # Disable greeting on startup
    set -U fish_greeting

    # Set important variables
    set -gx EDITOR vim

    starship init fish | source
end

Enable colors for ls in kitty

# MANAGED BY ANSIBLE, DO NOT TOUCH

# Commands to run in interactive sessions can go here
if status is-interactive
    # Disable greeting on startup
    set -U fish_greeting

    # Set important variables
    set -gx EDITOR vim

    # Enable colors for ls in kitty
    dircolors -c | source

    starship init fish | source
end


# Skip if cgitc_revision is up to date
set -l current_revision (git -C (dirname (status -f)) rev-parse HEAD)
if [ "$cgitc_revision" != "$current_revision" ]
  printf 'Initializing \x1b[33mcgitc\x1b[0m ... '
  set -l cgitc_text (
    for line in (cat (dirname (status -f))/abbreviations)
      # 1.  Strip out comments
      # 2.  Squeeze repeating spaces
      # 3.  Strip trailing whitespaces
      set line (echo "$line" | cut -d '#' -f 1 | tr -s ' ' | sed 's/[[:space:]]*$//')

      # Skip empty lines
      if not [ "$line" ]; continue; end

      # Wrap with double quote
      echo "\"$line\""
    end | tr '\n' ' '
  )

  echo "set -gx fish_user_abbreviations \$fish_user_abbreviations $cgitc_text" > (dirname (status -f))/run.fish

  set -U cgitc_revision "$current_revision"
  echo 'Done'
end
. (dirname (status -f))/run.fish

Support fish without abbr command

# Support fish < 2.2
switch "$FISH_VERSION"; case 2.1.2 2.1.1 2.1.0 2.0.0
  for line in (cat (dirname (status -f))/abbreviations)
    # 1.  Strip out comments
    # 2.  Squeeze repeating spaces
    # 3.  Strip trailing whitespaces
    set line (echo "$line" | cut -d '#' -f 1 | tr -s ' ' | sed 's/[[:space:]]*$//')

    # Skip empty lines
    if not [ "$line" ]; continue; end

    # Parse lines
    set key   (echo "$line" | cut -d ' ' -f 1)
    set value (echo "$line" | cut -d ' ' -f 2-)

    alias $key $value
  end
  exit
end

# Skip if cgitc_revision is up to date
set -l current_revision (git -C (dirname (status -f)) rev-parse HEAD)
if [ "$cgitc_revision" != "$current_revision" ]
  printf 'Initializing \x1b[33mcgitc\x1b[0m ... '
  set -l cgitc_text (
    for line in (cat (dirname (status -f))/abbreviations)
      # 1.  Strip out comments
      # 2.  Squeeze repeating spaces
      # 3.  Strip trailing whitespaces
      set line (echo "$line" | cut -d '#' -f 1 | tr -s ' ' | sed 's/[[:space:]]*$//')

      # Skip empty lines
      if not [ "$line" ]; continue; end

      # Wrap with double quote
      echo "\"$line\""
    end | tr '\n' ' '
  )

  echo "set -gx fish_user_abbreviations \$fish_user_abbreviations $cgitc_text" > (dirname (status -f))/run.fish

  set -U cgitc_revision "$current_revision"
  echo 'Done'
end
. (dirname (status -f))/run.fish


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

	if not set -q __fish_prompt_normal
		set -g __fish_prompt_normal (set_color normal)
	end

	# PWD
	set_color $fish_color_cwd
	echo -n (prompt_pwd)
	set_color normal

	printf '%s ' (__fish_git_prompt)

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

	echo -n '$ '

	set_color normal
end

Extend prompt and make it graphical with powerline symbols

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

	if not set -q __fish_prompt_normal
		set -g __fish_prompt_normal (set_color normal)
	end

	# Disable path shortening
	set -g fish_prompt_pwd_dir_length 0

	set_color -b 000000 $fish_color_cwd
	printf ' %s%s ' (prompt_pwd) (__fish_git_prompt)

	set_color -b 111111 000000
	printf '\ue0b0'

	set_color red
	printf ' %s ' (hostname | cut -d . -f 1)

	set_color -b 000000 111111
	printf '\ue0b0'
	set_color -b 000000

	set_color cyan
	printf ' %s ' (whoami)

	set_color -b 111111 000000
	printf '\ue0b0'
	set_color -b 111111

	set_color white
	printf ' %s ' (date -u "+%Y-%m-%d %H:%M:%S")

	set_color -b 000000 111111
	printf '\ue0b0'
	set_color -b 000000

	printf ' '

	set_color -b normal 000000
	printf '\ue0b0\n'
	set_color normal

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

	set_color -b 000000 magenta
	printf '$'

	set_color -b normal 000000
	printf '\ue0b0 '
	set_color normal
end


## SETTINGS

# editors, pagers
set -gx BROWSER open
set -gx EDITOR vim
set -gx PAGER less
set -gx MANPAGER $PAGER

# fish greeting
set -gx fish_greeting ""

## ALIASES

# navigation
alias ..   "cd .."
alias ...  "cd ../.."
alias .... "cd ../../.."

# ls
alias l   "ls -F"
alias la  "ls -AF"
alias ll  "ls -lF"
alias lla "ls -AlF"
alias lal lla

# apps
alias bo bower
alias bu bundler
alias g  git
alias gu gulp
alias no node
alias np npm
alias r  rails

## RBENV

set -gx PATH $PATH ~/.rbenv/bin ~/.rbenv/shims
rbenv rhash > /dev/null ^&1

Add atom alias and remove npm and node

## SETTINGS

# editors, pagers
set -gx BROWSER open
set -gx EDITOR vim
set -gx PAGER less
set -gx MANPAGER $PAGER

# fish greeting
set -gx fish_greeting ""

## ALIASES

# navigation
alias ..   "cd .."
alias ...  "cd ../.."
alias .... "cd ../../.."

# ls
alias l   "ls -F"
alias la  "ls -AF"
alias ll  "ls -lF"
alias lla "ls -AlF"
alias lal lla

# apps
alias a  atom
alias bo bower
alias bu bundler
alias g  git
alias gu gulp
alias r  rails

## RBENV

set -gx PATH $PATH ~/.rbenv/bin ~/.rbenv/shims
rbenv rhash > /dev/null ^&1


# Installs and updates SDKs.
# https://sdkman.io/
# https://get.sdkman.io/
# https://github.com/sdkman/sdkman-cli
#
# Sequencing
# - After: omf
function 🧰__sdkman
    echo "🧰  SDKman"
    echo

    if test -z "$sdkman_prefix"
        error "\$sdkman_prefix is not set"
        return 1
    end

    # Using /bin dir as test because /etc is tracked in dotfiles
    if not test -d $sdkman_prefix/bin
        echo "Installing SDKman"
        # Remove tracked etc/config file so that sdkman will actually install
        rm -rf $sdkmaan_prefix/
        curl -s "https://get.sdkman.io/" | bash
        git checkout $sdkman_prefix
    end

    sdk selfupdate
    sdk current
    sdk update
end

Fix type in sdkman upstall

# Installs and updates SDKs.
# https://sdkman.io/
# https://get.sdkman.io/
# https://github.com/sdkman/sdkman-cli
#
# Sequencing
# - After: omf
function 🧰__sdkman
    echo "🧰  SDKman"
    echo

    if test -z "$sdkman_prefix"
        error "\$sdkman_prefix is not set"
        return 1
    end

    # Using /bin dir as test because /etc is tracked in dotfiles
    if not test -d $sdkman_prefix/bin
        echo "Installing SDKman"
        # Remove tracked etc/config file so that sdkman will actually install
        rm -rf $sdkman_prefix/
        curl -s "https://get.sdkman.io/" | bash
        git checkout $sdkman_prefix
    end

    sdk selfupdate
    sdk current
    sdk update
end


# Initialize the current fish session and connect to the tmux session.
function init --on-event init_tmux-zen
  # If we're running in a superuser shell, do nothing.
  if test $USER = root
    return 0
  end

  # Connect to the TMUX session if it exists, or create it if it doesn't.
  if not set -q TMUX
    set -l tmux_bin (config tmux-zen --get tmux-bin --default tmux)
    set -l session_name (config tmux-zen --get session-name --default local)

    if eval "$tmux_bin has-session -t $session_name"
      eval "exec $tmux_bin -2 new-session -t $session_name \\; set destroy-unattached on \\; new-window"
    else
      eval "exec $tmux_bin -2 new-session -s $session_name"
    end
  end

  # Initialize the session if we didn't already.
  if not set -q ZEN_SESSION_INITIALIZED
    # Set a global variable to make sure we only get called once per session.
    set -g ZEN_SESSION_INITIALIZED true
    zen tmux setenv -g ZEN_SESSION_INITIALIZED true

    # Emit the init event. This by default triggers the default init code, but
    # can also be captured by the user.
    emit zen.init
  end
end

function zen.init --on-event zen.init
  config tmux-zen --query events.init
    and eval (config tmux-zen --get events.init)
end

Fix unwanted exec when fish is used to externally run shell commands

# Initialize the current fish session and connect to the tmux session.
function init --on-event init_tmux-zen
  # If we're not running in an interactive terminal, do nothing.
  if begin; not isatty; or not status --is-interactive; end
    return 0
  end

  # If we're running in a superuser shell, do nothing.
  if test $USER = root
    return 0
  end

  # Connect to the TMUX session if it exists, or create it if it doesn't.
  if not set -q TMUX
    set -l tmux_bin (config tmux-zen --get tmux-bin --default tmux)
    set -l session_name (config tmux-zen --get session-name --default local)

    if eval "$tmux_bin has-session -t $session_name"
      eval "exec $tmux_bin -2 new-session -t $session_name \\; set destroy-unattached on \\; new-window"
    else
      eval "exec $tmux_bin -2 new-session -s $session_name"
    end
  end

  # Initialize the session if we didn't already.
  if not set -q ZEN_SESSION_INITIALIZED
    # Set a global variable to make sure we only get called once per session.
    set -g ZEN_SESSION_INITIALIZED true
    zen tmux setenv -g ZEN_SESSION_INITIALIZED true

    # Emit the init event. This by default triggers the default init code, but
    # can also be captured by the user.
    emit zen.init
  end
end

function zen.init --on-event zen.init
  config tmux-zen --query events.init
    and eval (config tmux-zen --get events.init)
end


function fish_user_key_bindings
    bind \cr -M insert -m insert historyf
    bind \cr -m insert historyf
    bind \cs -M insert -m insert insert_filepath
    bind \cs -m insert insert_filepath
end

Add ctrl + j/k to iterate through history

function fish_user_key_bindings
    bind \cr -M insert -m insert historyf
    bind \cr -m insert historyf
    bind \cs -M insert -m insert insert_filepath
    bind \cs -m insert insert_filepath
    bind \cj -M insert -m insert down-or-search
    bind \cj -m insert down-or-search
    bind \ck -M insert -m insert up-or-search
    bind \ck -m insert up-or-search
end


# pyenv fish
set -gx PYENV_ROOT "$HOME/.pyenv"
set -x PATH $PATH "$PYENV_ROOT/bin"
status --is-interactive; and . (pyenv init - | psub)

# emacs alias
alias e="emacs -nw"

# peco
function peco_select_history
    if set -q $argv
        history | peco | read line; commandline $line
    else
        history | peco --query $argv | read line; commandline $line
    end
end

function fish_user_key_bindings
    bind \cr peco_select_history
end

# rmでゴミ箱へ移す
alias rm=trash

# git alias
alias g=git
alias ga='git add'
alias ga.='git add .'
alias gaA='git add -A'
alias gcm='git commit -m'
alias gcam='git commit -a -m'
alias gs='git status'
alias gp='git push'
alias gd='git diff'
alias gb='git branch'
alias gc='git checkout'
alias gl='git pull'
function gacp -d "gacp [file] 'commit message'"
    git add $argv[1]
    git commit -m $argv[2]
    git push
end

function gacp -d "gacp 'commit message' (file;optional)"
    if test count $argv -eq 2
        git add $argv[2]
    else
        git add -A
    end
    git commit -m $argv[1]
    git push
end

function counta
    count $argv
end

Fix gacp function with count command


# remove greeting
set fish_greeting

# Set aliases
alias k "kubectl"
alias c "clear"
alias b "babel-node"
alias fi "fisher"
alias tc "itermocil"
alias brc "brew cask"
alias brci "brew cask install"
alias brcu "brew cask uninstall"
alias y "yarn"
alias r "yarn"
alias gcl "git clone"
alias gs "git status"
alias gp "git push"
alias gpnf "git push --no-verify"
alias gpnff "git push --no-verify --force"
alias git='env LANG=en_US.UTF-8 git'

# autocompletion for itermocil
# https://github.com/TomAnthony/itermocil#fish-autocompletion
complete -c itermocil -a "(itermocil --list)"

# Go
set --export GOPATH $HOME/go
set --export PATH $GOPATH/bin $PATH
set --export PATH $GOPATH/go_appengine $PATH
set --export PATH $HOME/.local/bin $PATH

# Rust
set --export PATH $HOME/.cargo/bin $PATH

# Brew stuff
set --export PATH /usr/local/sbin $PATH

# Load fishmarks (http://github.com/techwizrd/fishmarks)
. $HOME/.fishmarks/marks.fish

test -e {$HOME}/.iterm2_shell_integration.fish
and source {$HOME}/.iterm2_shell_integration.fish

Add built from source pgloader to PATH

# remove greeting
set fish_greeting

# Set aliases
alias k "kubectl"
alias c "clear"
alias b "babel-node"
alias fi "fisher"
alias tc "itermocil"
alias brc "brew cask"
alias brci "brew cask install"
alias brcu "brew cask uninstall"
alias y "yarn"
alias r "yarn"
alias gcl "git clone"
alias gs "git status"
alias gp "git push"
alias gpnf "git push --no-verify"
alias gpnff "git push --no-verify --force"
alias git='env LANG=en_US.UTF-8 git'

# autocompletion for itermocil
# https://github.com/TomAnthony/itermocil#fish-autocompletion
complete -c itermocil -a "(itermocil --list)"

# Go
set --export GOPATH $HOME/go
set --export PATH $GOPATH/bin $PATH
set --export PATH $GOPATH/go_appengine $PATH
set --export PATH $HOME/.local/bin $PATH

# Rust
set --export PATH $HOME/.cargo/bin $PATH

# Brew stuff
set --export PATH /usr/local/sbin $PATH

# pgloader (built from source because see link below)
# https://github.com/Homebrew/homebrew-core/issues/31591
set --export PATH /Applications/pgloader/build/bin $PATH

# Load fishmarks (http://github.com/techwizrd/fishmarks)
. $HOME/.fishmarks/marks.fish

test -e {$HOME}/.iterm2_shell_integration.fish
and source {$HOME}/.iterm2_shell_integration.fish


set -g fish_greeting ''

set -x EDITOR /usr/local/bin/vim
set -x NODE_PATH /usr/local/lib/node_modules
set -x PATH /usr/local/bin $PATH
set -x PATH /usr/local/sbin $PATH
set -x PATH /usr/local/share/npm/bin $PATH
set -x PATH $HOME/.rbenv/bin $PATH
set -x PATH $HOME/.rbenv/shims $PATH
set -x PATH $HOME/bin $PATH
set -x RUBYGEMS_EC2_DB1 ec2-54-245-133-190.us-west-2.compute.amazonaws.com
set -x RUBYGEMS_EC2_LB1 54.245.255.174

Use any editor, as long as it's vim

set -g fish_greeting ''

set -x EDITOR (which vim)
set -x NODE_PATH /usr/local/lib/node_modules
set -x PATH /usr/local/bin $PATH
set -x PATH /usr/local/sbin $PATH
set -x PATH /usr/local/share/npm/bin $PATH
set -x PATH $HOME/.rbenv/bin $PATH
set -x PATH $HOME/.rbenv/shims $PATH
set -x PATH $HOME/bin $PATH
set -x RUBYGEMS_EC2_DB1 ec2-54-245-133-190.us-west-2.compute.amazonaws.com
set -x RUBYGEMS_EC2_LB1 54.245.255.174


function __refresh_gpg_agent_info -d "Re-load ~/.gpg-agent-info into environment"
	cat ~/.gpg-agent-info | sed 's/=/ /' | while read key value
		set -e $key
		set -U -x $key "$value"
	end
end

if not set -q -x GPG_AGENT_INFO
	gpg-agent --daemon >/dev/null
end

if test -f ~/.gpg-agent-info
	__refresh_gpg_agent_info

	gpg-connect-agent /bye ^/dev/null
	if test $status -eq 1
		pkill -U $USER gpg-agent
		gpg-agent --daemon >/dev/null
		__refresh_gpg_agent_info
	end
end

Fix GPG agent env file

function __refresh_gpg_agent_info -d "Re-load ~/.gpg-agent-info into environment"
	cat ~/.gpg-agent-info | sed 's/=/ /' | while read key value
		set -e $key
		set -U -x $key "$value"
	end
end

if not set -q -x GPG_AGENT_INFO
	gpg-agent --daemon --write-env-file ~/.gpg-agent-info >/dev/null
end

if test -f ~/.gpg-agent-info
	__refresh_gpg_agent_info

	gpg-connect-agent /bye ^/dev/null
	if test $status -eq 1
		pkill -U $USER gpg-agent
		gpg-agent --daemon --write-env-file ~/.gpg-agent-info >/dev/null
		__refresh_gpg_agent_info
	end
end


set --global --export EDITOR 'subl -w'

Fix EDITOR to work on more than just OS X

if [ (uname -s) -eq 'Darwin' ]
    set --global --export EDITOR 'subl -w'
else
    set --global --export EDITOR vim
end


# Atom
set -gx EDITOR 'atom -wd'
set -gx ATOM_REPOS_HOME /Projects/2014/ryansobol

# postgres
set -gx PGDATA /usr/local/var/postgres

# chruby
source /usr/local/share/chruby/chruby.fish
source /usr/local/share/chruby/auto.fish

Remove the PGDATA env variable

# Atom
set -gx EDITOR 'atom -wd'
set -gx ATOM_REPOS_HOME /Projects/2014/ryansobol

# chruby
source /usr/local/share/chruby/chruby.fish
source /usr/local/share/chruby/auto.fish


Add fish Vi-mode key bindings that act like vim's virtualedit mode.

function my_vi_key_bindings --description "Mikel's vi-like key bindings for fish"
    if contains -- -h $argv
        or contains -- --help $argv
        echo "Sorry but this function doesn't support -h or --help"
        return 1
    end

    # Start with the standard Fish bindings that are similar to Vi.
    fish_vi_key_bindings

    # Don't move backwards when switching from insert to normal (command) mode.
    # If we are paging, stay in insert mode.
    bind -s -M insert \e "if commandline -P; commandline -f cancel; else; set fish_bind_mode default; commandline -f repaint; end"

    # Undo weird Vi EOL behavior.
    bind -s -M default x delete-char
    bind -s -M default X backward-delete-char
    bind -s -M insert -k dc delete-char
    bind -s -M default -k dc delete-char

    # Backspace deletes a char in normal/default mode too.
    bind -s -M default -k backspace backward-delete-char
    bind -s -M default \ch backward-delete-char
    bind -s -M default \x7f backward-delete-char
end


function _ssh_find_config_value
 ssh -G $argv[2..-1] | grep -ie "^$argv[1] " | sed "s/^$argv[1] \(.*\)/\1/I"
end

function fish_title
  set -l title ""
  switch $_
    case fish
      set title (prompt_pwd)
    case vim
      set -l args (echo $argv[1] | sed 's/ /\n/g')
      if test (count $args) -gt 1
        set title "$_ "(shorten_path $args[2])
      else
        set title "$_ *"
      end
    case ssh
      set -l args (echo $argv[1] | sed 's/ /\n/g')
      set ssh_user (_ssh_find_config_value "User" $args[2..-1])
      set ssh_host (_ssh_find_config_value "Hostname" $args[2..-1] | cut -d '.' -f 1)
      if test (count $args -eq 2)
        set title "$ssh_user@$ssh_host"
      else
        set title "$argv"
      end
    case '*'
      set title "$_"
  end
  echo $title
end

Use the commandline buffer for tokenization

function _ssh_find_config_value
 ssh -G $argv[2..-1] | grep -ie "^$argv[1] " | sed "s/^$argv[1] \(.*\)/\1/I"
end

function _tokenize_command
  commandline -r $argv[1]
  commandline -o
  commandline -r ""
end

function fish_title
  set -l title ""
  switch $_
    case fish
      set title (prompt_pwd)
    case vim
      set -l args (_tokenize_command $argv[1])
      if test (count $args) -gt 1
        set title "$_ "(shorten_path $args[2])
      else
        set title "$_ *"
      end
    case ssh
      set -l args (_tokenize_command $argv[1])
      set ssh_user (_ssh_find_config_value "User" $args[2..-1])
      set ssh_host (_ssh_find_config_value "Hostname" $args[2..-1] | cut -d '.' -f 1)
      if test (count $args -eq 2)
        set title "$ssh_user@$ssh_host"
      else
        set title "$argv"
      end
    case '*'
      set title "$_"
  end
  echo $title
end


Add fish function to lookup fields in bitwarden

function bwFields --description "Lookup password in bitwarden based on username and search term"

    set -l options (fish_opt -s h -l help)
    set options $options (fish_opt --short s --long search --required-val)
    set options $options (fish_opt --short u --long username --required-val)

    argparse $options -- $argv
    or return # exit if argparse failed because it found an option it didn't recognize - it will print an error

    # If -h or --help is given, we print a little help text and return
    if set -q _flag_help
        help
        return 0
    end

    # If -s or --search is given, get the search term from one or the other
    # otherwise return with non-zero exit code as this is required
    if set -q _flag_search
        set searchTerm $_flag_search
    else if set -q _flag_s
        set searchTerm $_flag_s
    else
        echo "Search term is required"
        help
        return 1
    end

    # If -u or --username is given, get the username from one or the other
    # otherwise return with non-zero exit code as this is required.
    if set -q _flag_username
        set user $_flag_username
    else if set -q _flag_u
        set user $_flag_u
    end

    # Username is not set
    if set -q $user
        echo "Searching for $searchTerm"
        bw list items --search $searchTerm | jq --raw-output ". | map(select(.fields != null)) | .[] | {username: .login.username, fields: .fields}"
    # Username is set
    else
        echo "Searching for $searchTerm, $user"
        bw list items --search $searchTerm | jq --raw-output ". | map(select(.fields != null)) | map(select(.login.username == \"$user\")) | .[0] | .fields"
    end
end

function help
    echo "Usage:"
    echo "bwFields (-s/--search SEARCH_TERM) [-u/--username USER_NAME]"
end


## Note: Replaced calls to brew --prefix with actual values since
## it is slow (~ 200 ms)
set -x PATH /usr/local/opt/libexec/gnubin $PATH

### RBENV
set -x RBENV_ROOT /usr/local/opt/rbenv
set -x PATH $RBENV_ROOT/bin $PATH
set -x PATH $RBENV_ROOT/shims $PATH

set -x GEM_HOME /usr/local/opt/gems
set -x GEM_PATH /usr/local/opt/gems

### NVM
#source ~/.config/fish/nvm-wrapper/nvm.fish

Add manually path to nvm bin/

## Note: Replaced calls to brew --prefix with actual values since
## it is slow (~ 200 ms) (min. b. -p. coreutils; b. -p itsel is quick)
set -x PATH /usr/local/opt/coreutils/libexec/gnubin $PATH

### RBENV
set -x RBENV_ROOT /usr/local/opt/rbenv
set -x PATH $RBENV_ROOT/bin $PATH
set -x PATH $RBENV_ROOT/shims $PATH

set -x GEM_HOME /usr/local/opt/gems
set -x GEM_PATH /usr/local/opt/gems

### NVM
#source ~/.config/fish/nvm-wrapper/nvm.fish
set -x PATH $PATH ~/.nvm/v0.10.38/bin


Add function to find AMIs (currently only Ubuntu)

function ami --argument distribution release
    trace (status --current-filename) $argv

    switch "$distribution"
        case ubuntu
            switch "$release"
                case 16.04 xenial lts
                    aws ec2 describe-images --filters "Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*" | jq -r '.Images | sort_by(.CreationDate) [] | select(.OwnerId == "099720109477") | .ImageId' | tail -1
                case 14.04 trusty
                    aws ec2 describe-images --filters "Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*" | jq -r '.Images | sort_by(.CreationDate) [] | select(.OwnerId == "099720109477") | .ImageId' | tail -1
                case 12.04 precise
                    aws ec2 describe-images --filters "Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-precise-12.04-amd64-server-*" | jq -r '.Images | sort_by(.CreationDate) [] | select(.OwnerId == "099720109477") | .ImageId' | tail -1
            end
    end
end


# Go
function g -d 'Change directory and look up'
  set is_okay true
  if test -z $argv
    cd -
  else
    if test -e $argv
      cd $argv
    else
      set is_okay false
      set_color $red
      echo 'Cannot find "'$argv'"'
      set_color normal
    end
  end

  if eval $is_okay
    ls -AF .
  end
end
alias gh 'g $HOME'
alias gconfig 'g $HOME/.config/fish/'
alias grepo 'g $HOME/repos/'
alias .. 'g ..'
alias ... 'g ../..'
alias .... 'g ../../..'
alias ..... 'g ../../../..'

# See
function s -d 'List files in details'
  if type -q exa;
		exa -lag $argv
	else;
		ls -AFlh $argv
	end
end
function st -d 'List files ordered from oldest to newest'
  s -tr
end
function sf -d 'List files with filter'
  s | grep $argv
end

Add comments for test statements

# Go
function g -d 'Change directory and look up'
  set is_okay true
  if test -z $argv # if no argument
    cd -
  else
    if test -e $argv # if the file exists
      cd $argv
    else
      set is_okay false
      set_color $red
      echo 'Cannot find "'$argv'"'
      set_color normal
    end
  end

  if eval $is_okay
    ls -AF .
  end
end
alias gh 'g $HOME'
alias gconfig 'g $HOME/.config/fish/'
alias grepo 'g $HOME/repos/'
alias .. 'g ..'
alias ... 'g ../..'
alias .... 'g ../../..'
alias ..... 'g ../../../..'

# See
function s -d 'List files in details'
  if type -q exa;
		exa -lag $argv
	else;
		ls -AFlh $argv
	end
end
function st -d 'List files ordered from oldest to newest'
  s -tr
end
function sf -d 'List files with filter'
  s | grep $argv
end


# Set path
set -x PATH $HOME/bin $PATH

# Include abbreviations
source $HOME/.config/fish/abbreviations.fish

# Initialize commajump
source ~/.config/fish/functions/__commajump_add.fish

# Activate chruby
[ -f /usr/local/share/chruby/chruby.fish ]; and source /usr/local/share/chruby/chruby.fish
[ -f /usr/local/share/chruby/auto.fish ]; and source /usr/local/share/chruby/auto.fish

# Git prompt options
set __fish_git_prompt_showcolorhints 'yes'
set __fish_git_prompt_show_informative_status 'yes'

# Set program options
set -x GREP_OPTIONS '--color=auto'
set -x LESS '-R'
set -x HOMEBREW_AUTO_UPDATE_SECS 86400

# Set environment variables
set -x JAVA_HOME (/usr/libexec/java_home)

Set GOPATH if golang is installed

# Set path
set -x PATH $HOME/bin $PATH

# Include abbreviations
source $HOME/.config/fish/abbreviations.fish

# Initialize commajump
source ~/.config/fish/functions/__commajump_add.fish

# Activate chruby
[ -f /usr/local/share/chruby/chruby.fish ]; and source /usr/local/share/chruby/chruby.fish
[ -f /usr/local/share/chruby/auto.fish ]; and source /usr/local/share/chruby/auto.fish

# Git prompt options
set __fish_git_prompt_showcolorhints 'yes'
set __fish_git_prompt_show_informative_status 'yes'

# Set program options
set -x GREP_OPTIONS '--color=auto'
set -x LESS '-R'
set -x HOMEBREW_AUTO_UPDATE_SECS 86400

# Set dev environment paths
set -x JAVA_HOME (/usr/libexec/java_home)
if test (which go)
	set -x GOPATH ~/dev/golang
	set -x PATH $GOPATH/bin $PATH
end


function pman --description 'Opens a man page in the OS X Preview app'
    if [ (uname -s) = 'Darwin' ]
        man -t $argv[1] | open -f -a /Applications/Preview.app
    else
        man $argv
    end
end

Use standard format for tests

function pman --description 'Opens a man page in the OS X Preview app'
    if test (uname -s) = 'Darwin'
        man -t $argv[1] | open -f -a /Applications/Preview.app
    else
        man $argv
    end
end


function fish_greeting -d "What's up, fish?"
    set_color $fish_color_autosuggestion
    uname -nmsr

    # TODO: `command -q -s` only works on fish 2.5+, so hold off on that for now
    command -s uptime >/dev/null
    and uptime

    set_color normal
end

Use `command uptime` to avoid coloured output when using grc plugin

function fish_greeting -d "What's up, fish?"
    set_color $fish_color_autosuggestion
    uname -nmsr

    # TODO: `command -q -s` only works on fish 2.5+, so hold off on that for now
    command -s uptime >/dev/null
    and command uptime

    set_color normal
end


# Hook jump on directory changes.
function __jump_add --on-variable PWD
  status --is-command-substitution; and return
  jump update
end

# Shortcut to j for the autojump folks.
function j
  set -l output (jump cd $argv)
  if test -d "$output"
	  cd $output
  end
end


# Path to Oh My Fish install.
set -gx OMF_PATH "/home/e4r7hbug/.local/share/omf"

# Customize Oh My Fish configuration path.
#set -gx OMF_CONFIG "/home/e4r7hbug/.config/omf"

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

fish_vi_mode

Extend $PATH with bin dirs in fish

# Path to Oh My Fish install.
set -gx OMF_PATH "/home/e4r7hbug/.local/share/omf"

# Customize Oh My Fish configuration path.
#set -gx OMF_CONFIG "/home/e4r7hbug/.config/omf"

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

fish_vi_mode

set PATH \
    "$HOME/bin" \
    "$HOME/.local/bin" \
    "$HOME/Library/Python/2.7/bin" \
    "$HOME/go/bin" \
        $PATH


if which postgres > /dev/null
    set --global --export POSTGRES (get_active_brew_dir (which postgres))
    set --global --export POSTGRES_BIN $POSTGRES/bin
end

Add PostgreSQL startup and shutdown functions

if which postgres > /dev/null
    set --global --export POSTGRES_DATA /usr/local/var/postgres

    function start_postgres
        set --local logfile $argv[1]
        if [ -z $logfile ]
            set logfile ~/postgres.log
        end

        pg_ctl start --pgdata $POSTGRES_DATA --log $logfile
    end

    function stop_postgres
        pg_ctl stop --pgdata $POSTGRES_DATA
    end
end


function __paradox_git_hash --description "Get the current git commit hash, if we're in a git working tree"
  if status --is-interactive
    set -l git_command 'git rev-parse --is-inside-work-tree --short HEAD ^/dev/null'

    if type gtimeout >/dev/null ^/dev/null
      set  -l git_command 'timeout 1' git_command
    end

    set -l git_info (eval $git_command)
    if test (count $git_info) -gt 1
      set -l inside_worktree $git_info[1]
      set -l git_head $git_info[2]
      if test "true" = "$inside_worktree"
        echo -s (set_color blue) "[$git_head]"
      end
    end
  end
end

Allow git_hash to be run uninteractively

function __paradox_git_hash --description "Get the current git commit hash, if we're in a git working tree"
  set -l git_command 'git rev-parse --is-inside-work-tree --short HEAD ^/dev/null'

  if type gtimeout >/dev/null ^/dev/null
    set  -l git_command 'timeout 1' git_command
  end

  set -l git_info (eval $git_command)
  if test (count $git_info) -gt 1
    set -l inside_worktree $git_info[1]
    set -l git_head $git_info[2]
    if test "true" = "$inside_worktree"
      echo -s (set_color blue) "[$git_head]"
    end
  end
end


# Set defaults
set -q fry_rubies       ; or set -gx fry_rubies $HOME/.rubies
set -q fry_auto_switch  ; or set -gx fry_auto_switch 0

# Path
set -l fry_path (dirname (status -f))

if not contains $fry_path/functions $fish_function_path
  set fish_function_path $fry_path/functions $fish_function_path
end

if not contains $fry_path/completions $fish_complete_path
  set fish_complete_path $fry_path/completions $fish_complete_path
end

# Auto-switch
if test $fry_auto_switch = 1
  function __fry_auto_switch --on-variable PWD --description 'Auto-switch ruby version from .ruby-version file'
    status --is-command-substitution; and return

    set -l version_file (__fry_find_version_file)
    test -n "$version_file"; or return

    set -l version_data (cat $version_file)
    test -n "$version_data"; or return

    fry use $version_data >/dev/null
  end

  __fry_auto_switch
end

Create rubies directory if not existing

# Set defaults
set -q fry_rubies       ; or set -gx fry_rubies $HOME/.rubies
set -q fry_auto_switch  ; or set -gx fry_auto_switch 0

test -d $fry_rubies; or mkdir -p $fry_rubies

# Path
set -l fry_path (dirname (status -f))

if not contains $fry_path/functions $fish_function_path
  set fish_function_path $fry_path/functions $fish_function_path
end

if not contains $fry_path/completions $fish_complete_path
  set fish_complete_path $fry_path/completions $fish_complete_path
end

# Auto-switch
if test $fry_auto_switch = 1
  function __fry_auto_switch --on-variable PWD --description 'Auto-switch ruby version from .ruby-version file'
    status --is-command-substitution; and return

    set -l version_file (__fry_find_version_file)
    test -n "$version_file"; or return

    set -l version_data (cat $version_file)
    test -n "$version_data"; or return

    fry use $version_data >/dev/null
  end

  __fry_auto_switch
end


# pyenv fish
set -gx PYENV_ROOT "$HOME/.pyenv"
set -x PATH $PATH "$PYENV_ROOT/bin"
status --is-interactive; and . (pyenv init - | psub)

# emacs alias
alias e="emacs -nw"

# peco
function peco_select_history
    if set -q $argv
        history | peco | read line; commandline $line
    else
        history | peco --query $argv | read line; commandline $line
    end
end

function fish_user_key_bindings
    bind \cr peco_select_history
end

# rmでゴミ箱へ移す
alias rm=trash

# git alias
alias g=git
alias ga='git add'
alias ga.='git add .'
alias gaA='git add -A'
alias gcm='git commit -m'
alias gcam='git commit -a -m'
alias gs='git status'
alias gp='git push'
alias gd='git diff'
alias gb='git branch'
alias gc='git checkout'
alias gl='git pull'
function gacp -d "gacp [file] 'commit message'"
    git add $argv[1]
    git commit -m $argv[2]
    git push
end
うまく動かん
function gacp -d "gacp 'commit message' (file;optional)"
    if test count $argv -eq 2
        git add $argv[2]
    else
        git add -A
    end
    git commit -m $argv[1]
    git push
end

Fix gacp function with count command

# pyenv fish
set -gx PYENV_ROOT "$HOME/.pyenv"
set -x PATH $PATH "$PYENV_ROOT/bin"
status --is-interactive; and . (pyenv init - | psub)

# emacs alias
alias e="emacs -nw"

# peco
function peco_select_history
    if set -q $argv
        history | peco | read line; commandline $line
    else
        history | peco --query $argv | read line; commandline $line
    end
end

function fish_user_key_bindings
    bind \cr peco_select_history
end

# rmでゴミ箱へ移す
alias rm=trash

# git alias
alias g=git
alias ga='git add'
alias ga.='git add .'
alias gaA='git add -A'
alias gcm='git commit -m'
alias gcam='git commit -a -m'
alias gs='git status'
alias gp='git push'
alias gd='git diff'
alias gb='git branch'
alias gc='git checkout'
alias gl='git pull'
function gacp -d "gacp [file] 'commit message'"
    git add $argv[1]
    git commit -m $argv[2]
    git push
end

function gacp -d "gacp 'commit message' (file;optional)"
    if test count $argv -eq 2
        git add $argv[2]
    else
        git add -A
    end
    git commit -m $argv[1]
    git push
end

function counta
    count $argv
end


Add a plugin for finding a string in files, find + grep

# The MIT License
#
# Copyright (c) Simon Lees <http://simotek.net/> and contributors
#
# 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 find-in -d "Find a string in a file"
    switch (count $argv)
        case 2
            find $argv[2] -type f -exec grep -Hns --color=auto $argv[1] '{}' \;
        case 3
            find $argv[3] -type f -exec grep -Hns --color=auto $argv[1] $argv[2] '{}' \;
        case '*'
            echo "find-in finds occurances of a Pattern in a text File"
            echo "Usage: find-in [OPTION] PATTERN FILES"
            echo "    Where [OPTION] is a Regexp selection as defined by grep --help"
    end
end


# This script should be sourced in the context of your shell like so:
# source $HOME/.homesick/repos/homeshick/homeshick.fish
# Once the homeshick() function is defined, you can type
# "homeshick cd CASTLE" to enter a castle.

function homeshick
	if test \( (count $argv) = 2 -a $argv[1] = "cd" \)
		cd "$HOME/.homesick/repos/$argv[2]"
	else if set -q HOMESHICK_DIR
		eval $HOMESHICK_DIR/bin/homeshick $argv
	else
		eval $HOME/.homesick/repos/homeshick/bin/homeshick $argv
	end
end

Fix fish path resolution for paths with spaces

# This script should be sourced in the context of your shell like so:
# source $HOME/.homesick/repos/homeshick/homeshick.fish
# Once the homeshick() function is defined, you can type
# "homeshick cd CASTLE" to enter a castle.

function homeshick
	if test \( (count $argv) = 2 -a $argv[1] = "cd" \)
		cd "$HOME/.homesick/repos/$argv[2]"
	else if set -q HOMESHICK_DIR
		eval $HOMESHICK_DIR/bin/homeshick (string escape -- $argv)
	else
		eval $HOME/.homesick/repos/homeshick/bin/homeshick (string escape -- $argv)
	end
end


function _prompt_dir_component
  _prompt_wrap_text (prompt_pwd) 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 __fish_is_git_repository
    set --local sha (git rev-parse HEAD)
    set --local branch (git rev-parse --abbrev-ref HEAD)

    set --local info ''
    if [ $branch = HEAD ]
      set --local ref (git show-ref --tags | grep $sha)

      if set -q ref
        set --local parts (string split / -- $ref)
        set info tag $parts[3]
      else
        set info detached $sha
      end
    else
      set info branch $branch
    end

    switch $info[1]
    case branch
      _prompt_wrap_text $info[2] green
    case tag
      _prompt_wrap_text $info[2] 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

  echo -n (_prompt_git_component)
  echo -n (_prompt_dir_component)
  echo -n (_prompt_err_component $error_code)
  echo ' '
end

Fix git prompt component when checking out an individual commit

function _prompt_dir_component
  _prompt_wrap_text (prompt_pwd) 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 __fish_is_git_repository
    set --local sha (git rev-parse HEAD)
    set --local branch (git rev-parse --abbrev-ref HEAD)

    set --local info ''
    if [ $branch = HEAD ]
      if set --local ref (git show-ref --tags | grep $sha)
        set --local parts (string split / -- $ref)
        set info tag $parts[3]
      else
        set info detached $sha
      end
    else
      set info branch $branch
    end

    switch $info[1]
    case branch
      _prompt_wrap_text $info[2] green
    case tag
      _prompt_wrap_text $info[2] 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

  echo -n (_prompt_git_component)
  echo -n (_prompt_dir_component)
  echo -n (_prompt_err_component $error_code)
  echo ' '
end


Add function to create instance profiles

function create-instance-profile --argument name
    trace (status --current-filename) $argv

    if empty "$name"
        usage create-instance-profile '<name>'
        return (false)
    end

    if not instance-profile-exists $name
        aws iam create-instance-profile --instance-profile-name $name
    end
end


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


function pip3
    set -l cmd $argv[1]
    set -e argv[1]

    switch "$cmd"
        case install list
            command pip3 $cmd --user $argv
        case update upgrade
            pip3 list --outdated --format=legacy $argv | cut -d ' ' -f 1 | xargs -n 1 pip3 install --upgrade $argv
        case '*'
            command pip3 $cmd $argv
    end
end

Fix installation of user pip packages

function pip3
    set -l cmd $argv[1]
    set -e argv[1]

    switch "$cmd"
        case install list
            command pip3 $cmd --user $argv
        case update upgrade
            command pip3 list --user --outdated --format=legacy $argv | cut -d ' ' -f 1 | xargs -n 1 pip3 install --user --upgrade $argv
        case '*'
            command pip3 $cmd $argv
    end
end


# pyenv fish
set -gx PYENV_ROOT "$HOME/.pyenv"
set -x PATH $PATH "$PYENV_ROOT/bin"
status --is-interactive; and . (pyenv init - | psub)

# peco
function peco_select_history
    if set -q $argv
        history | peco | read line; commandline $line
    else
        history | peco --query $argv | read line; commandline $line
    end
end

function fish_user_key_bindings
    bind \cr peco_select_history
end

# emacs alias
alias e="emacs -nw"
alias sue='sudo emacs -nw'

# rmでゴミ箱へ移す
alias rm=trash

# git alias
alias g=git
alias ga='git add'
alias ga.='git add .'
alias gaA='git add -A'
alias gcm='git commit -m'
alias gcam='git commit -a -m'
alias gs='git status'
alias gp='git push'
alias gd='git diff'
alias gb='git branch'
alias gc='git checkout'
alias gf='git fetch'
alias gl='git pull'

Add "git merge" as gm and "git checkout master" as gcm

# pyenv fish
set -gx PYENV_ROOT "$HOME/.pyenv"
set -x PATH $PATH "$PYENV_ROOT/bin"
status --is-interactive; and . (pyenv init - | psub)

# peco
function peco_select_history
    if set -q $argv
        history | peco | read line; commandline $line
    else
        history | peco --query $argv | read line; commandline $line
    end
end

function fish_user_key_bindings
    bind \cr peco_select_history
end

# emacs alias
alias e="emacs -nw"
alias sue='sudo emacs -nw'

# rmでゴミ箱へ移す
alias rm=trash

# git alias
alias g=git
alias ga='git add'
alias ga.='git add .'
alias gaA='git add -A'
alias gc-m='git commit -m'
alias gcam='git commit -a -m'
alias gs='git status'
alias gp='git push'
alias gd='git diff'
alias gb='git branch'
alias gm='git merge'
alias gc='git checkout'
alias gcm='git checkout master'
alias gf='git fetch'
alias gl='git pull'


source ~/.asdf/asdf.fish
set -x ERL_AFLAGS "-kernel shell_history enabled"
set -x HOMEBREW_EDITOR "vim"
set -x GOPATH "/Users/rockwood/devel/go"

Add sbin to fish paths

source ~/.asdf/asdf.fish
set -x ERL_AFLAGS "-kernel shell_history enabled"
set -x HOMEBREW_EDITOR "vim"
set -x GOPATH "/Users/rockwood/devel/go"
set -g fish_user_paths "/usr/local/sbin" $fish_user_paths


# global encoding
set -gx LANG en_US.UTF-8

# global path
mkdir -p $HOME/bin $HOME/.local/bin
set PATH $HOME/bin $HOME/.local/bin /usr/local/bin $PATH

# homebrew settings
function check_brew_installtion --description "check homebrew if installed"
  if not which brew >/dev/null ^&1
    echo 'Homebrew is not installed, please use `$ brew_tools` to install first'
    exit 1
  end
end

if which brew >/dev/null ^&1
    set -gx HOMEBREW_BOTTLE_DOMAIN https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
    set -gx HOMEBREW_NO_ANALYTICS 1
    set -gx HOMEBREW_AUTO_UPDATE_SECS 86400
end

# go settings
if which go >/dev/null ^&1
  mkdir -p $HOME/.go
  set -gx GOPATH $HOME/.go
  mkdir -p $GOPATH/bin
  set PATH $PATH /usr/local/opt/go/libexec/bin $GOPATH/bin
end

# ocaml opam settings
if which opam >/dev/null ^&1
    eval (opam config env)
    set -gx OCAMLPARAM "_,bin-annot=1"
end

# rust cargo settings
if test -d $HOME/.cargo/bin
    set PATH $PATH $HOME/.cargo/bin
end

Fix exec-path-from-shell :config: Expected printf output from shell, but got: ""

# global encoding
set -gx LANG en_US.UTF-8

# global path
mkdir -p $HOME/bin $HOME/.local/bin
set PATH $HOME/bin $HOME/.local/bin /usr/local/bin $PATH

# homebrew settings
function check_brew_installtion --description "check homebrew if installed"
  if not which brew >/dev/null ^&1
    echo 'Homebrew is not installed, please use `$ brew_tools` to install first'
    exit 1
  end
end

if which brew >/dev/null ^&1
    set -gx HOMEBREW_BOTTLE_DOMAIN https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
    set -gx HOMEBREW_NO_ANALYTICS 1
    set -gx HOMEBREW_AUTO_UPDATE_SECS 86400
end

# go settings
if which go >/dev/null ^&1
  mkdir -p $HOME/.go
  set -gx GOPATH $HOME/.go
  mkdir -p $GOPATH/bin
  set PATH $PATH /usr/local/opt/go/libexec/bin $GOPATH/bin
end

# ocaml opam settings
if which opam >/dev/null ^&1
    opam config env | source
    set -gx OCAMLPARAM "_,bin-annot=1"
end

# rust cargo settings
if test -d $HOME/.cargo/bin
    set PATH $PATH $HOME/.cargo/bin
end


function database-instance-create --argument name
    trace (status --current-filename) $argv

    if empty $name
        usage database-instance-create '<name>'
        return 23
    end

    if database instance exists $name
        print --warning "$name already exists"
    else
        if has $name databases
            set database databases/$name
            set flags
            for flag in db-instance-class engine engine-version master-username allocated-storage storage-type db-subnet-group-name
                set -- flags $flags --$flag (get $database/$flag)
            end

            for secret in master-user-password
                set -- flags $flags --$secret (get-secret $database/$secret)
            end

            if has multi-az $database
                set flags $flags --multi-az
            else
                set flags $flags --no-multi-az
            end

            set tags
            for tag in (get $database/tags)
                set tags $tags Key=$tag,Value=(get $database/tags/$tag)
            end

            if not empty $tags
                set -- flags $flags --tags $tags
            end

            aws rds create-db-instance --db-instance-identifier $name $flags
        else
            print --failure "No such file or directory: $database/$name"
        end
    end
end


fish_vi_mode
set fish_bind_mode insert
set fish_key_bindings fish_user_key_bindings

set -x FZF_CTRL_T_COMMAND "$FZF_DEFAULT_COMMAND"
set -x EDITOR vim
set -x P4DIFF "vimdiff -R"
set -x P4MERGE vimdiff

# Load fishmarks (http://github.com/techwizrd/fishmarks)
if test -e $HOME/.fishmarks/marks.fish
    source $HOME/.fishmarks/marks.fish
end

if test -e "$HOME/.homesick/repos/homeshick/homeshick.fish"
    source "$HOME/.homesick/repos/homeshick/homeshick.fish"
end

if test -e $HOME/.config/fish/config_local.fish
  source $HOME/.config/fish/config_local.fish
end

Disable fishmarks (so it doesn't clobber g as an alias for git

fish_vi_mode
set fish_bind_mode insert
set fish_key_bindings fish_user_key_bindings

set -x FZF_CTRL_T_COMMAND "$FZF_DEFAULT_COMMAND"
set -x EDITOR vim
set -x P4DIFF "vimdiff -R"
set -x P4MERGE vimdiff

# Load fishmarks (http://github.com/techwizrd/fishmarks)
# if test -e $HOME/.fishmarks/marks.fish
#    source $HOME/.fishmarks/marks.fish
# end

if test -e "$HOME/.homesick/repos/homeshick/homeshick.fish"
    source "$HOME/.homesick/repos/homeshick/homeshick.fish"
end

if test -e $HOME/.config/fish/config_local.fish
  source $HOME/.config/fish/config_local.fish
end


function init --on-event init_thefuck
  if type -q thefuck
    set -q __tf_func; or __tf_updt
    eval $__tf_func
  else
    echo "Please install thefuck first. Check https://github.com/nvbn/thefuck"
  end
end

Initialize immediately, rather than waiting for an event.


function init --on-event init_thefuck
  if available thefuck
    eval (thefuck --alias | tr '\n' ';')  # function stays up-to-date, always
  else
    echo "Please install thefuck first. Check https://github.com/nvbn/thefuck"
  end
end

Replace `available` usage with `type -q`

function init --on-event init_thefuck
  if type -q thefuck
    eval (thefuck --alias | tr '\n' ';')  # function stays up-to-date, always
  else
    echo "Please install thefuck first. Check https://github.com/nvbn/thefuck"
  end
end


if status --is-login
    set PATH ~/bin /usr/local/bin $PATH
end

if test -f ~/.autojump/etc/profile.d/autojump.fish
  . ~/.autojump/etc/profile.d/autojump.fish
end

Set TERM to xterm-256color for tmux... Alias vim to vi if vi does not exists.

if status --is-login
    set PATH ~/bin /usr/local/bin $PATH
end

if test -f ~/.autojump/etc/profile.d/autojump.fish
  . ~/.autojump/etc/profile.d/autojump.fish
end

set -e TERM
set -Ux TERM xterm-256color

if test ! (which vi 2>/dev/null)
    alias vi=vim
end


# name: eclm
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) ]

    if test (_git_branch_name) = 'master'
      set -l git_branch (_git_branch_name)
      set git_info "$blue ($red$git_branch$blue)"
    else
      set -l git_branch (_git_branch_name)
      set git_info "$blue ($git_branch)$blue"
    end

    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

Make branch name more prominent

# name: eclm
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) ]

    if test (_git_branch_name) = 'master'
      set -l git_branch (_git_branch_name)
      set git_info "$normal ($red$git_branch$normal)"
    else
      set -l git_branch (_git_branch_name)
      set git_info "$normal ($blue$git_branch$normal)"
    end

    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


umask 077 # WSL: Default umask is not applied (github:Microsoft/WSL/issues/352)

set -x PATH $PATH ~/bin
set -x SHELL (which fish)

# github:danhper/fish-ssh-agent
if test -z "$SSH_ENV"
    set -xg SSH_ENV $HOME/.ssh/environment
end

if not __ssh_agent_is_started
    __ssh_agent_start
end

# Base16 Shell
if status --is-interactive
    set BASE16_SHELL "$HOME/.config/base16-shell/"
    source "$BASE16_SHELL/profile_helper.fish"
end

# THEME PURE #
set fish_function_path /home/nannangar/.config/fish/functions/theme-pure/functions/ $fish_function_path
source /home/nannangar/.config/fish/functions/theme-pure/conf.d/pure.fish

Change bin path to .bin (refactor)

umask 077 # WSL: Default umask is not applied (github:Microsoft/WSL/issues/352)

set -x PATH $PATH ~/.bin
set -x SHELL (which fish)

# github:danhper/fish-ssh-agent
if test -z "$SSH_ENV"
    set -xg SSH_ENV $HOME/.ssh/environment
end

if not __ssh_agent_is_started
    __ssh_agent_start
end

# Base16 Shell
if status --is-interactive
    set BASE16_SHELL "$HOME/.config/base16-shell/"
    source "$BASE16_SHELL/profile_helper.fish"
end

# THEME PURE #
set fish_function_path /home/nannangar/.config/fish/functions/theme-pure/functions/ $fish_function_path
source /home/nannangar/.config/fish/functions/theme-pure/conf.d/pure.fish


# Replace the process to tmux
if [ -z "$TMUX" -a x"$TERM" != x"screen" ]
    switch "$WSLENV"
        case 'VSCODE*'
            /bin/true # do nothing
        case '*'
            which tmux && exec tmux -u
    end
end

Create temporary files if running on WSL

# Create temporary files if running on WSL
if [ -n "$WSLENV" ]
    sudo systemd-tmpfiles --create
end

# Replace the process to tmux
if [ -z "$TMUX" -a x"$TERM" != x"screen" ]
    switch "$WSLENV"
        case 'VSCODE*'
            /bin/true # do nothing
        case '*'
            which tmux && exec tmux -u
    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 pms 'python manage.py shell'
alias pmr 'python manage.py runserver'
alias ipn 'ipython notebook'

alias git hub
alias top 'glances'

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

alias psql pgcli

Add alias for pkill when Emacs hangs

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 pms 'python manage.py shell'
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


function switchaudio --description 'Switch between audio outputs (assuming there are only 2)'
    set -l sinks (pactl list short sinks)
    for sink in $sinks
       set sink_info (string split \t $sink)
       set sink_id $sink_info[1]
       set sink_state $sink_info[5]

       switch $sink_state
           case RUNNING
               set active_sink $sink_id
           case SUSPENDED
               set inactive_sink $sink_id
           case IDLE
               set inactive_sink $sink_id
       end
    end

    # If the output we switch to is not set as default then the
    # system volume slider controls will not affect it.
    pactl set-default-sink $inactive_sink

    set -l inputs (pactl list short sink-inputs)
    for input in $inputs
        set input_id (string split \t $input)[1]
        pactl move-sink-input $input_id $inactive_sink
    end
end

Remove unnecessary '--local' option from 'set' call

function switchaudio --description 'Switch between audio outputs (assuming there are only 2)'
    set sinks (pactl list short sinks)
    for sink in $sinks
       set sink_info (string split \t $sink)
       set sink_id $sink_info[1]
       set sink_state $sink_info[5]

       switch $sink_state
           case RUNNING
               set active_sink $sink_id
           case SUSPENDED
               set inactive_sink $sink_id
           case IDLE
               set inactive_sink $sink_id
       end
    end

    # If the output we switch to is not set as default then the
    # system volume slider controls will not affect it.
    pactl set-default-sink $inactive_sink

    set inputs (pactl list short sink-inputs)
    for input in $inputs
        set input_id (string split \t $input)[1]
        pactl move-sink-input $input_id $inactive_sink
    end
end


set -x SHELL /usr/local/bin/fish
set -x EDITOR vim

set -x PATH $PATH /usr/local/sbin

# Golang
set -x GOPATH $HOME/go
set -x PATH $GOPATH/bin:$PATH

set gorootbin "/usr/local/go/bin"

if not contains $gorootbin $PATH
    set -x PATH $PATH $gorootbin
end

# Rust
set -x PATH $HOME/.cargo/bin:$PATH
if type -q rustc
    set -x RUST_SRC_PATH (rustc --print sysroot)/lib/rustlib/src/rust/src

    if type -q racer
        set -x RACER_PATH (command -v racer)
    end
end

starship init fish | source

Add pack completion to fish

set -x SHELL /usr/local/bin/fish
set -x EDITOR vim

set -x PATH $PATH /usr/local/sbin

# Golang
set -x GOPATH $HOME/go
set -x PATH $GOPATH/bin:$PATH

set gorootbin "/usr/local/go/bin"

if not contains $gorootbin $PATH
    set -x PATH $PATH $gorootbin
end

# Rust
set -x PATH $HOME/.cargo/bin:$PATH
if type -q rustc
    set -x RUST_SRC_PATH (rustc --print sysroot)/lib/rustlib/src/rust/src

    if type -q racer
        set -x RACER_PATH (command -v racer)
    end
end

source (pack completion --shell fish)

starship init fish | source


Add function to check if a security group exists

function security-group-exists --argument group vpc
    trace (status --current-filename) $argv

    if empty $group
        usage security-group-exists '<group>' '[vpc]'
        return 23
    end

    if empty $vpc
        security-group-exists $group (default-vpc)
    end

    if string match --quiet 'vpc-*' $vpc
        if string match --quiet 'sg-*' $group
            contains $group (vpc security-groups $vpc)
        else
            contains $group (vpc security-groups $vpc | map security-group name)
        end
    else
        security-group-exists $group (lookup vpc $vpc)
    end
end


function _ssh_find_config_value
 ssh -G $argv[2..-1] | grep -ie "^$argv[1] " | sed "s/^$argv[1] \(.*\)/\1/I"
end

function _tokenize_command
  commandline -r $argv[1]
  commandline -o
  commandline -r ""
end

function fish_title
  set -l title ""
  switch $_
    case fish
      set title (prompt_pwd)
    case vim
      set -l args (_tokenize_command $argv[1])
      if test (count $args) -gt 1
        set title "$_ "(shorten_path $args[2])
      else
        set title "$_ *"
      end
    case ssh
      set -l args (_tokenize_command $argv[1])
      set ssh_user (_ssh_find_config_value "User" $args[2..-1])
      set ssh_host (_ssh_find_config_value "Hostname" $args[2..-1] | cut -d '.' -f 1)
      if test (count $args -eq 2)
        set title "$ssh_user@$ssh_host"
      else
        set title "$argv"
      end
    case '*'
      set title "$_"
  end
  echo $title
end

Add host and user to title if ssh connection is detected

function _ssh_find_config_value
 ssh -G $argv[2..-1] | grep -ie "^$argv[1] " | sed "s/^$argv[1] \(.*\)/\1/I"
end

function _tokenize_command
  commandline -r $argv[1]
  commandline -o
  commandline -r ""
end

function fish_title
  set -l title ""
  switch $_
    case fish
      set title (prompt_pwd)
    case vim
      set -l args (_tokenize_command $argv[1])
      if test (count $args) -gt 1
        set title "$_ "(shorten_path $args[2])
      else
        set title "$_ *"
      end
    case ssh
      set -l args (_tokenize_command $argv[1])
      set ssh_user (_ssh_find_config_value "User" $args[2..-1])
      set ssh_host (_ssh_find_config_value "Hostname" $args[2..-1] | cut -d '.' -f 1)
      if test (count $args -eq 2)
        set title "$ssh_user@$ssh_host"
      else
        set title "$argv"
      end
    case '*'
      set title "$_"
  end
  if test "$SSH_CONNECTION"
    set title "$title ($USER@"(hostname)")"
  end
  echo $title
end


function _done --on-event fish_prompt

	if test $CMD_DURATION
		# Store duration of last command
		set duration (echo "$CMD_DURATION 1000" | awk '{printf "%.3fs", $1 / $2}')

		# when a command takes longer than notify_duration
		set notify_duration 10000
		set exclude_cmd "zsh|bash|less|man|more|ssh|drush php|git add|vim"
		if begin
				test $CMD_DURATION -gt $notify_duration
				and echo $history[1] | grep -vqE "^($exclude_cmd).*"
			end

			switch (uname)
				case Darwin # macOS
					echo "
						tell application \"System Events\"
							set activeApp to name of first application process whose frontmost is true
							if \"iTerm\" is not in activeApp then
								display notification \"Finished in $duration\" with title \"$history[1]\"
							end if
						end tell
						" | osascript
				case Linux
					notify-send "Finished in $duration with title $history[1]"
        case "*"
          # bell sound
          echo -e "\a"
			end
		end
	end
end

Add support for icons and all terminals on macOS

set _bundleID ''

function _get_bundle_id
	lsappinfo info -only bundleID (lsappinfo front) | cut -d '"' -f4
end

function _is_terminal_focused
	test $_bundleID = _get_bundle_id
end

function _is_command_available
	type -q $argv
end

function _started --on-event fish_preexec
	if _is_command_available lsappinfo
		set _bundleID _get_bundle_id
	end
end

function _done --on-event fish_prompt

	if test $CMD_DURATION
		# Store duration of last command
		set duration (echo "$CMD_DURATION 1000" | awk '{printf "%.3fs", $1 / $2}')

		# when a command takes longer than notify_duration
		set notify_duration 10000
		set exclude_cmd "zsh|bash|less|man|more|ssh|drush php|git add|vim"

		if begin
				test $CMD_DURATION -gt $notify_duration
				and echo $history[1] | grep -vqE "^($exclude_cmd).*"
			end

			set -l message "Finished in $duration"
			set -l title "$history[1]"

			if test (uname) = 'Darwin' # macOS
				if not _is_terminal_focused
					if _is_command_available terminal-notifier # if command available
						terminal-notifier -message "$message" -title "$title" -sender "$_bundleID"
					else
						osascript -e "display notification \"$message\" with title \"$title\""
					end
				end

			else if _is_command_available notify-send # linux
				notify-send "Finished in $duration with title $history[1]"

			else # anything else
      	echo -e "\a" # bell sound
			end
		end
	end
end


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

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

function fish_prompt
  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)

  set -l cwd $cyan(basename (prompt_pwd))

  if [ (_git_branch_name) ]
    set -l git_branch (_git_branch_name)
    set git_info "$green$git_branch "

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

  echo -n -s $cwd $red '|'$git_info $normal⇒ ' '$normal
end

Fix prompt so it shows the red pipe even when in the home directory

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

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

function fish_prompt
  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)

  set -l cwd $cyan(basename (prompt_pwd))

  if [ (_git_branch_name) ]
    set -l git_branch (_git_branch_name)
    set git_info "$green$git_branch "

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

  echo -n -s $cwd $red '|' $git_info $normal ⇒ ' ' $normal
end


# Updates and installs system and shell dependencies (utilities, libraries, plugins, apps).
# Sometimes these are custom forks or configuration to tweak any of these.
function 🔻_upstall
    createdirs ~/.config/upstall

    set -l last_ran_file ~/.config/upstall/last_run.(machine_id)
    set -l last_ran (cat $last_ran_file)
    echo "🔻  Upstall (Last ran: "$last_ran")"
    date >$last_ran_file

    repeatchar -

    # Only prompt for user info when not already set
    if test -z (git config user.email)
        _gitconfig
    else
        echo "Git configuration"
        cat ~/.config/git/config
    end

    repeatchar -
    ♻_fisherman
    repeatchar -
    ♻_tmbundles
    repeatchar -
end

Add options: --no-fisherman (--nofm), --no-textmate (--notm)

# Updates and installs system and shell dependencies (utilities, libraries, plugins, apps).
# Sometimes these are custom forks or configuration to tweak any of these.
function 🔻_upstall
    createdirs ~/.config/upstall

    set -l last_ran_file ~/.config/upstall/last_run.(machine_id)
    set -l last_ran (cat $last_ran_file)
    echo "🔻  Upstall (Last ran: "$last_ran")"
    date >$last_ran_file

    repeatchar -

    # Only prompt for user info when not already set
    if test -z (git config user.email)
        _gitconfig
    else
        echo "Git configuration"
        cat ~/.config/git/config
    end

    if not contains -- "--no-fisherman" $argv; and not contains -- "--nofm" $argv
        repeatchar -
        echo ♻_fisherman
        # ♻_fisherman
    end

    if not contains -- "--no-textmate" $argv; and not contains -- "--notm" $argv
        repeatchar -
        echo ♻_tmbundles
        # ♻_tmbundles
    end

    repeatchar -
end


Add function for quickly creating a PR with your new branch

function git-new-branch --description "Create a new branch and opens a Pull Request for it"
  git checkout -b $argv[1]
  git commit --allow-empty -m 'Empty commit to open PR'
  git push origin HEAD
  git pull-request  # Opens your default text editor. Uses hub.
end


# name: FishFace

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 blue (set_color -o blue)
  set -l green (set_color -o green)

  if [ (_git_branch_name) ]
    echo -n -s "$green><(((\"> "
  else
    echo -n -s "$blue><(((\"> "
  end
end

Make stderr redirection compatible with Fish 3.0.

# name: FishFace

function _git_branch_name
  echo (command git symbolic-ref HEAD 2> /dev/null | sed -e 's|^refs/heads/||')
end

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

function fish_prompt
  set -l blue (set_color -o blue)
  set -l green (set_color -o green)

  if [ (_git_branch_name) ]
    echo -n -s "$green><(((\"> "
  else
    echo -n -s "$blue><(((\"> "
  end
end


set -xg TERM "xterm-256color"
set -xg DOTFILES "$HOME/.dotfiles"

source "$DOTFILES/__abbreviations.fish"
source "$DOTFILES/__aliases.fish"
source "$DOTFILES/__env.fish"
source "$DOTFILES/__path.fish"

for completion_dir in $DOTFILES/fish/*/completions
    set fish_complete_path $completion_dir $fish_complete_path
end
for completion_dir in $DOTFILES/*/completions
    set fish_complete_path $completion_dir $fish_complete_path
end

for func_dir in $DOTFILES/fish/*/functions
    set fish_function_path $func_dir $fish_function_path
end
for func_dir in $DOTFILES/*/functions
    set fish_function_path $func_dir $fish_function_path
end

# GPG
eval (gpgconf --launch gpg-agent)

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

# starship
starship init fish | source

# direnv
direnv hook fish | source

if test -e "$HOME/.localrc"; source "$HOME/.localrc"; end

Fix completions and functions paths

set -xg TERM "xterm-256color"
set -xg DOTFILES "$HOME/.dotfiles"

source "$DOTFILES/__abbreviations.fish"
source "$DOTFILES/__aliases.fish"
source "$DOTFILES/__env.fish"
source "$DOTFILES/__path.fish"

# Completions
set -xp fish_complete_path $DOTFILES/completions
for completion_dir in $DOTFILES/*/completions
    set -xp fish_complete_path $completion_dir
end

# Functions
set -xp fish_function_path $DOTFILES/functions
for func_dir in $DOTFILES/*/functions
    set -xp fish_function_path $func_dir
end

# GPG
eval (gpgconf --launch gpg-agent)

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

# starship
starship init fish | source

# direnv
direnv hook fish | source

if test -e "$HOME/.localrc"; source "$HOME/.localrc"; end


Add function to find users not in a group

function users-not-in-group --argument group
    if empty "$group"
        usage users-not-in-group '<group>'
        return (false)
    end

    comm -13 (users-in-group $group | psub) (get iam/users | psub)
end


set PATH /usr/local/sbin $PATH

# Perl
set -x PERL_MM_OPT "INSTALL_BASE=$HOME/perl5"
eval (perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)

# Android tools
set PATH ~/Library/Android/sdk/platform-tools $PATH

# Add directory with "subl" command to lunch Sublime Text
set PATH /Applications/Sublime\ Text.app/Contents/SharedSupport/bin $PATH

# Golang
set -x GOPATH ~/workspace/go
set PATH $GOPATH/bin $PATH

# fuck
eval (thefuck --alias | tr '\n' ';')

####################
# Helper functions #
####################

function docker-bash
	docker exec -it $argv /bin/bash
end

function docker-sh
    docker exec -it $argv /bin/sh
end

function docker-clean
	echo "Removing containers..."
	docker rm -f (docker ps -a -q)
	echo "Removing images..."
	docker rmi -f (docker images -q)
	docker ps -a | cut -c-12 | xargs docker rm
end

Add function for serving a directory through HTTP

set PATH /usr/local/sbin $PATH

# Perl
set -x PERL_MM_OPT "INSTALL_BASE=$HOME/perl5"
eval (perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)

# Android tools
set PATH ~/Library/Android/sdk/platform-tools $PATH

# Add directory with "subl" command to lunch Sublime Text
set PATH /Applications/Sublime\ Text.app/Contents/SharedSupport/bin $PATH

# Golang
set -x GOPATH ~/workspace/go
set PATH $GOPATH/bin $PATH

# fuck
eval (thefuck --alias | tr '\n' ';')

####################
# Helper functions #
####################

function serve
    python3 -m http.server --bind=localhost 8080
end

function docker-bash
	docker exec -it $argv /bin/bash
end

function docker-sh
    docker exec -it $argv /bin/sh
end

function docker-clean
	echo "Removing containers..."
	docker rm -f (docker ps -a -q)
	echo "Removing images..."
	docker rmi -f (docker images -q)
	docker ps -a | cut -c-12 | xargs docker rm
end


function fish_prompt --description 'Write out the prompt'

    set -l last_status $status

    # Just calculate these once, to save a few cycles when displaying the prompt
    if not set -q __fish_prompt_hostname
        set -g __fish_prompt_hostname (hostname|cut -d . -f 1)
    end

    if not set -q __fish_prompt_normal
        set -g __fish_prompt_normal (set_color normal)
    end

    set -l delim '$'

    switch $USER

    case root

        if not set -q __fish_prompt_cwd
            if set -q fish_color_cwd_root
                set -g __fish_prompt_cwd (set_color $fish_color_cwd_root)
            else
                set -g __fish_prompt_cwd (set_color $fish_color_cwd)
            end
        end

    case '*'

        if not set -q __fish_prompt_cwd
            set -g __fish_prompt_cwd (set_color $fish_color_cwd)
        end

    end

    set -l prompt_status
    if test $last_status -ne 0
        if not set -q __fish_prompt_status
            set -g __fish_prompt_status (set_color $fish_color_status)
        end
        set prompt_status "$__fish_prompt_status [$last_status]$__fish_prompt_normal"
    end

    if not set -q __fish_prompt_user
        set -g __fish_prompt_user (set_color $fish_color_user)
    end
    if not set -q __fish_prompt_host
        set -g __fish_prompt_host (set_color $fish_color_host)
    end

    echo -n -s "$__fish_prompt_normal" "$__fish_prompt_host" "$__fish_prompt_hostname" "$__fish_prompt_normal" ':' "$__fish_prompt_cwd" (prompt_pwd) (__fish_git_prompt "#%s") "$__fish_prompt_normal" '$ '
end

Remove unused settings and variables

function fish_prompt --description 'Write out the prompt'

    # Just calculate these once, to save a few cycles when displaying the prompt
    if not set -q __fish_prompt_hostname
        set -g __fish_prompt_hostname (hostname|cut -d . -f 1)
    end

    if not set -q __fish_prompt_normal
        set -g __fish_prompt_normal (set_color normal)
    end

    if not set -q __fish_prompt_cwd
        set -g __fish_prompt_cwd (set_color $fish_color_cwd)
    end

    echo -n -s "$__fish_prompt_hostname" "$__fish_prompt_normal" ' ' "$__fish_prompt_cwd" (prompt_pwd) (__fish_git_prompt "#%s") "$__fish_prompt_normal" '$ '

end


function , --description 'Commajump'
	set found_paths (grep $argv ~/.commajump | grep -v (pwd)\$)
	set found_folders (printf '%s\n' $found_paths | xargs basename | grep -in $argv)

	if test (count $found_folders) -ne 0
		set found_paths $found_paths[(printf '%s\n' $found_folders | cut -d':' -f1 | paste -d' ' -s -)]
	end

	cd (printf '%s\n' $found_paths | uniq -c | sort -nr | head -1 | tr -s ' ' | cut -d' ' -f3)
end

Fix splitting paths that include spaces

function , --description 'Commajump'
	set found_paths (grep $argv ~/.commajump | grep -v (pwd)\$)
	set found_folders (printf '%s\n' $found_paths | xargs basename | grep -in $argv)

	if test (count $found_folders) -ne 0
		set found_paths $found_paths[(printf '%s\n' $found_folders | cut -d':' -f1 | paste -d' ' -s -)]
	end

	cd (printf '%s\n' $found_paths | uniq -c | sort -nr | head -1 | tr -s ' ' | cut -d' ' -f3-)
end


function tmpdir --description "cd into a fresh, one-time temporary directory"
  if not set --global --query TMPDIR_TAB
    mkdir -p /tmp/tmpdir
    set --global --export TMPDIR_TAB (mktemp -d /tmp/tmpdir/XXXXXX)
  end
  cd $TMPDIR_TAB
end

function _tmpdir_on_exit --on-process-exit %self
  if set --global --query TMPDIR_TAB
    rm -rf $TMPDIR_TAB
  end
end

Fix subshells / same shell behavior

function tmpdir --description "cd into a fresh, one-time temporary directory"
  if set --global --query TMPDIR_TAB
    cd $TMPDIR_TAB
    rm -- {.*,*}
  else
    mkdir -p /tmp/tmpdir
    set --global TMPDIR_TAB (mktemp -d /tmp/tmpdir/XXXXXX)
    cd $TMPDIR_TAB
  end
end

function _tmpdir_on_exit --on-process-exit %self
  if set --global --query TMPDIR_TAB
    rm -rf $TMPDIR_TAB
  end
end


complete -c gabbr -d 'Global abbreviation for fish'
complete -c gabbr -s a -l add -d 'Add abbreviation'
complete -c gabbr -s e -l erase -d 'Erase abbreviation'
complete -c gabbr -s l -l list -d 'Print all abbreviation names'
complete -c gabbr -s s -l show -d 'Print all abbreviations'
complete -c gabbr -s h -l help -d 'Help'

Add completion for --function option

complete -c gabbr -d 'Global abbreviation for fish'
complete -c gabbr -s a -l add -d 'Add abbreviation'
complete -c gabbr -s e -l erase -d 'Erase abbreviation'
complete -c gabbr -s f -l function -d 'Add function-abbreviation'
complete -c gabbr -s l -l list -d 'Print all abbreviation names'
complete -c gabbr -s s -l show -d 'Print all abbreviations'
complete -c gabbr -s h -l help -d 'Help'


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 | tail -r)
    switch $i
      case "$name*" "$rubyless_name*" "ruby-$name*"
        echo $i
        return
    end
  end

  return 1
end

Use sed instead of tail

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


function __z_complete -d "add completions"
  function __z_marks
      printf "%s\n" (string replace -r '\|.*' '' < $Z_DATA)
  end

  complete -c $Z_CMD -a "(__z -l | string replace -r '^\\S*\\s*' '')" -f -k
  complete -c $ZO_CMD -a "(__z -l | string replace -r '^\\S*\\s*' '')" -f -k

  complete -c $Z_CMD -s c -l clean  -d "Cleans out $Z_DATA"
  complete -c $Z_CMD -s e -l echo   -d "Prints best match, no cd"
  complete -c $Z_CMD -s l -l list   -d "List matches, no cd"
  complete -c $Z_CMD -s p -l purge  -d "Purges $Z_DATA"
  complete -c $Z_CMD -s r -l rank   -d "Searches by rank, cd"
  complete -c $Z_CMD -s t -l recent -d "Searches by recency, cd"
  complete -c $Z_CMD -s h -l help   -d "Print help"
end

Add argument completion for "-x/--delete"

function __z_complete -d "add completions"
  function __z_marks
      printf "%s\n" (string replace -r '\|.*' '' < $Z_DATA)
  end

  complete -c $Z_CMD -a "(__z -l | string replace -r '^\\S*\\s*' '')" -f -k
  complete -c $ZO_CMD -a "(__z -l | string replace -r '^\\S*\\s*' '')" -f -k

  complete -c $Z_CMD -s c -l clean  -d "Cleans out $Z_DATA"
  complete -c $Z_CMD -s e -l echo   -d "Prints best match, no cd"
  complete -c $Z_CMD -s l -l list   -d "List matches, no cd"
  complete -c $Z_CMD -s p -l purge  -d "Purges $Z_DATA"
  complete -c $Z_CMD -s r -l rank   -d "Searches by rank, cd"
  complete -c $Z_CMD -s t -l recent -d "Searches by recency, cd"
  complete -c $Z_CMD -s h -l help   -d "Print help"
  complete -c $Z_CMD -s x -l delete -d "Removes the current directory from $Z_DATA"
end


function shorten_path
  set -l prefix $HOME
  set -l replacement "~"
  if test (count $argv) -gt 2
    set prefix $argv[2]
    set replacement $argv[3]
  end
  set -l partial_result (string replace -r "^$prefix(/|\$)" "$replacement\$1" $argv[1])
  string replace -ra '(\\.?[^/]{1})[^/]*/' '$1/' $partial_result
end

Remove a rather embarrising redundant quantifier

function shorten_path
  set -l prefix $HOME
  set -l replacement "~"
  if test (count $argv) -gt 2
    set prefix $argv[2]
    set replacement $argv[3]
  end
  set -l partial_result (string replace -r "^$prefix(/|\$)" "$replacement\$1" $argv[1])
  string replace -ra '(\\.?[^/])[^/]*/' '$1/' $partial_result
end


function phone_battery_status --description='Get battery status and level from KDEConnect to display in i3status-rs'

  argparse --name phone_battery_status 'd/device=' -- $argv
  or return 1  #error

  set path "/modules/kdeconnect/devices/$_flag_device"
  set charging (qdbus org.kde.kdeconnect $path org.kde.kdeconnect.device.battery.isCharging)
  set level (qdbus org.kde.kdeconnect $path org.kde.kdeconnect.device.battery.charge)

  if test $level -ge 80
    # battery-full
    set icon ""
  else if test ($level -ge 51) -a ($level -lt 80)
    # battery-three-quarters
    set icon ""
  else if test ($level -ge 26) -a ($level -lt 51)
    # battery-half
    set icon ""
  else if test ($level -ge 11) -a ($level -lt 26)
    # battery-quarter
    set icon ""
  else if test $level -le 10
    # battery-none
    set icon ""
  end

  if test $charging = true
    printf "$icon$level%%"
  else
    printf "$icon$level%%"
  end
end

Add fallack for device ID

function phone_battery_status --description='Get battery status and level from KDEConnect to display in i3status-rs'

  argparse --name phone_battery_status 'd/device=' -- $argv
  or return 1  #error

  if test -z $_flag_device
    # just grab first device found (TODO: see what happens if more than one device is connected)
    set device (qdbus org.kde.kdeconnect /modules/kdeconnect org.kde.kdeconnect.daemon.devices)
  else
    set device $_flag_device
  end
  set path "/modules/kdeconnect/devices/$device"
  set charging (qdbus org.kde.kdeconnect $path org.kde.kdeconnect.device.battery.isCharging)
  set level (qdbus org.kde.kdeconnect $path org.kde.kdeconnect.device.battery.charge)

  if test $level -ge 80
    # battery-full
    set icon ""
  else if test ($level -ge 51) -a ($level -lt 80)
    # battery-three-quarters
    set icon ""
  else if test ($level -ge 26) -a ($level -lt 51)
    # battery-half
    set icon ""
  else if test ($level -ge 11) -a ($level -lt 26)
    # battery-quarter
    set icon ""
  else if test $level -le 10
    # battery-none
    set icon ""
  end

  if test $charging = true
    printf "$icon$level%%"
  else
    printf "$icon$level%%"
  end
end


set -gx GOROOT /usr/lib/go
set -gx GOPATH $HOME/dev/go
set -gx PATH $PATH $HOME/dev/go/bin

alias blaze "bazel"

Set custom color scheme for fish

set -gx GOROOT /usr/lib/go
set -gx GOPATH $HOME/dev/go
set -gx PATH $PATH $HOME/dev/go/bin

alias blaze "bazel"

set fish_color_normal c5c8c6
set fish_color_error cc6666
set fish_color_command c5c8c6 --bold
set fish_color_quote b5bd68
set fish_color_end cc6666
set fish_color_redirection b294bb --bold
set fish_color_param f0c674
set fish_color_comment 81a2be

# Tomorrow-theme
# See https://github.com/chriskempson/tomorrow-theme
#1d1f21 Background
#282a2e Current Line
#373b41 Selection
#c5c8c6 Foreground
#969896 Comment
#cc6666 Red
#de935f Orange
#f0c674 Yellow
#b5bd68 Green
#8abeb7 Aqua
#81a2be Blue
#b294bb Purple


source ~/.config/fish/variables.fish
source ~/.config/fish/aliases.fish

Add `/usr/local/sbin` to user path

source ~/.config/fish/variables.fish
source ~/.config/fish/aliases.fish
set -g fish_user_paths "/usr/local/sbin" $fish_user_paths


alias nvm 'bass source ~/.nvm/nvm.sh --no-use ";" nvm' # Use nvm because it by default doesn't work with fish
alias psf 'pgrep' # Find a running process
alias dit 'docker exec -it'
alias dr 'docker run'
alias db 'docker build'
alias sagi 'sudo apt-get install -y'
alias bi 'brew install'
alias bs 'brew services'
alias et 'e t --reporter dot'
alias bsl 'brew services list'
alias p 'python3' # Typing is hard ok
alias e 'nvm use 8.11.1 ;and ember' # Switch to node 8.11.1, which I use a lot, then do something ember-related
alias es 'e serve'
alias quit 'exit' # 'quit' is significantly easier to type than 'exit'. I am a very lazy person
alias gcat './gradlew clean connectedAndroidTest'
alias gt './gradlew clean test'
alias mdg 'mix deps.get'
alias renv 'cp .env.sample .env'
alias sd 'serverless deploy'

function mkcd
  mkdir -p $argv[1]
  cd $argv[1]
end

# Kill all processes listening on the given port
function kp
  lsof -i ":$argv[1]" | grep LISTEN | awk '{print $2}' | xargs kill
end

Make renv use Sailthru Sandbox example

alias nvm 'bass source ~/.nvm/nvm.sh --no-use ";" nvm' # Use nvm because it by default doesn't work with fish
alias psf 'pgrep' # Find a running process
alias dit 'docker exec -it'
alias dr 'docker run'
alias db 'docker build'
alias sagi 'sudo apt-get install -y'
alias bi 'brew install'
alias bs 'brew services'
alias et 'e t --reporter dot'
alias bsl 'brew services list'
alias p 'python3' # Typing is hard ok
alias e 'nvm use 8.11.1 ;and ember' # Switch to node 8.11.1, which I use a lot, then do something ember-related
alias es 'e serve'
alias quit 'exit' # 'quit' is significantly easier to type than 'exit'. I am a very lazy person
alias gcat './gradlew clean connectedAndroidTest'
alias gt './gradlew clean test'
alias mdg 'mix deps.get'
alias renv 'cp .env.sample.sb .env'
alias sd 'serverless deploy'

function mkcd
  mkdir -p $argv[1]
  cd $argv[1]
end

# Kill all processes listening on the given port
function kp
  lsof -i ":$argv[1]" | grep LISTEN | awk '{print $2}' | xargs kill
end


alias nvm 'bass source ~/.nvm/nvm.sh --no-use ";" nvm' # Use nvm because it by default doesn't work with fish
alias psf 'pgrep' # Find a running process
alias dit 'docker exec -it'
alias dr 'docker run'
alias db 'docker build'
alias sagi 'sudo apt-get install -y'
alias bi 'brew install'
alias bs 'brew services'
alias code 'code-insiders'
alias et 'e t --reporter dot'
alias bsl 'brew services list'
alias p 'python3' # Typing is hard ok
alias e 'nvm use 5.7.0 ;and ember' # Switch to node 5.7.0, which I use a lot, then do something ember-related
alias es 'e serve'
alias quit 'exit' # 'quit' is significantly easier to type than 'exit'. I am a very lazy person
alias gcat './gradlew clean connectedAndroidTest'
alias gt './gradlew clean test'

Rewrite mkcd as function, add kp

alias nvm 'bass source ~/.nvm/nvm.sh --no-use ";" nvm' # Use nvm because it by default doesn't work with fish
alias psf 'pgrep' # Find a running process
alias dit 'docker exec -it'
alias dr 'docker run'
alias db 'docker build'
alias sagi 'sudo apt-get install -y'
alias bi 'brew install'
alias bs 'brew services'
alias code 'code-insiders'
alias et 'e t --reporter dot'
alias bsl 'brew services list'
alias p 'python3' # Typing is hard ok
alias e 'nvm use 5.7.0 ;and ember' # Switch to node 5.7.0, which I use a lot, then do something ember-related
alias es 'e serve'
alias quit 'exit' # 'quit' is significantly easier to type than 'exit'. I am a very lazy person
alias gcat './gradlew clean connectedAndroidTest'
alias gt './gradlew clean test'

function mkcd
  mkdir -p $argv[1]
  cd $argv[1]
end

# Kill all processes listening on the given port
function kp
  lsof -i ":$argv[1]" | grep LISTEN | awk '{print $2}' | xargs kill
end


function create-role --argument-names name
    print-status iam/create-role $name

    if test -z "$name"
        print-status usage 'create-role <name>'
        return -1
    end

    set --local role iam/roles/$name
    set --local policy assume-role-policy.json

    if has $policy $role
        aws iam create-role --role-name $name --assume-role-policy-document file://$role/$policy
    else
        print-status error "Expected to find policy at $role/$policy"
    end
end

Change expected path for AssumeRole Policy

function create-role --argument-names name
    print-status iam/create-role $name

    if test -z "$name"
        print-status usage 'create-role <name>'
        return -1
    end

    set --local role iam/roles/$name
    set --local policy assume-role.json

    if has $policy $role
        aws iam create-role --role-name $name --assume-role-policy-document file://$role/$policy
    else
        print-status error "Expected to find policy at $role/$policy"
    end
end