# 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

Use global config --file for 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 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


#!/usr/local/bin/fish
# <bitbar.title>Homebrew updates</bitbar.title>
# <bitbar.author>Sebastian Klatt</bitbar.author>
# <bitbar.author.github>sebastianmarkow</bitbar.author.github>
# <bitbar.desc>List available updates from Homebrew</bitbar.desc>
# <bitbar.dependencies>fish,cut,wc,printf</bitbar.dependencies>

set -l brew (command -s brew)
and command brew update >/dev/null
or exit 1

set -l formulas (command brew outdated -1 --verbose)
set -l num (count $formulas)

switch "$num"
    case '0'
        set sym "✓"
    case '*'
        set sym $num
end

echo "⇡$sym| dropdown=false"
echo "---"
echo "Update| refresh=true"

if test -n "$formulas"
    echo "Upgrade all| bash=$brew param1=upgrade param2=--all terminal=false refresh=true"
    for item in $formulas
        if test "$item" = "$formulas[-1]"
            echo -n "└"
        else
            echo -n "├"
        end
        printf " %s| bash=$brew param1=upgrade param2=%s terminal=false refresh=true\n" $item (echo "$item" | cut -f 1 -d " ")
    end
end

Add separator after update item

#!/usr/local/bin/fish
# <bitbar.title>Homebrew updates</bitbar.title>
# <bitbar.author>Sebastian Klatt</bitbar.author>
# <bitbar.author.github>sebastianmarkow</bitbar.author.github>
# <bitbar.desc>List available updates from Homebrew</bitbar.desc>
# <bitbar.dependencies>fish,cut,wc,printf</bitbar.dependencies>

set -l brew (command -s brew)
and command brew update >/dev/null
or exit 1

set -l formulas (command brew outdated -1 --verbose)
set -l num (count $formulas)

switch "$num"
    case '0'
        set sym "✓"
    case '*'
        set sym $num
end

echo "⇡$sym| dropdown=false"
echo "---"
echo "Update| refresh=true"
echo "---"

if test -n "$formulas"
    echo "Upgrade all| bash=$brew param1=upgrade param2=--all terminal=false refresh=true"
    for item in $formulas
        if test "$item" = "$formulas[-1]"
            echo -n "└"
        else
            echo -n "├"
        end
        printf " %s| bash=$brew param1=upgrade param2=%s terminal=false refresh=true\n" $item (echo "$item" | cut -f 1 -d " ")
    end
end


which abs ^ /dev/null > /dev/null
if test $status -ne 1
  function pacupd -d "Update and refresh the local package and ABS databases against repositories"
    sudo pacman -Sy; and sudo abs
  end
else
  function pacupd -d "Update and refresh the local package against repositories"
    sudo pacman -Sy
  end
end

Make stderr redirection compatible with Fish 3.0.

which abs 2> /dev/null > /dev/null
if test $status -ne 1
  function pacupd -d "Update and refresh the local package and ABS databases against repositories"
    sudo pacman -Sy; and sudo abs
  end
else
  function pacupd -d "Update and refresh the local package against repositories"
    sudo pacman -Sy
  end
end


function mkdir --wraps mkdir
  command mkdir -p $argv;
end

function jl --description 'colorized pretty-printed JSON in less'
  jq -C . | less -R $argv;
end

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

function ll --wraps exa
  exa -lh --git $argv
end

function amm-cats --wraps amm
  amm -p ~/dotfiles/amm/cats-predef.sc
end

Add wrapper for ammonite to use from brew; add rbenv

function mkdir --wraps mkdir
  command mkdir -p $argv;
end

function jl --description 'colorized pretty-printed JSON in less'
  jq -C . | less -R $argv;
end

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

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

function ll --wraps exa
  exa -lh --git $argv
end

function amm --description 'Scala REPL'
  sh -c 'amm "$@"' amm $argv
end

function amm-cats --wraps amm
  amm -p ~/dotfiles/amm/cats-predef.sc
end


function __fish_kdb_no_subcommand \
-d 'Check if the current commandline buffer does not contain a subcommand'
    set subcommands (__fish_kdb_complete)
    for input in (commandline -opc)
        if contains -- $input $subcommands
            return 1
        end
    end
    return 0
end

function __fish_kdb_complete -d 'Print a list of kdb subcommands'
    kdb list-commands $argv | awk '{if(NR>1)print}'
end

complete -c kdb -n '__fish_kdb_no_subcommand' -x -a '(__fish_kdb_complete -v)'

Use more descriptive function name

function __fish_kdb_no_subcommand \
-d 'Check if the current commandline buffer does not contain a subcommand'
    set subcommands (__fish_kdb_print_subcommands)
    for input in (commandline -opc)
        if contains -- $input $subcommands
            return 1
        end
    end
    return 0
end

function __fish_kdb_print_subcommands -d 'Print a list of kdb subcommands'
    kdb list-commands $argv | awk '{if(NR>1)print}'
end

complete -c kdb -n '__fish_kdb_no_subcommand' -x \
    -a  '(__fish_kdb_print_subcommands -v)'


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

# tmux
if status --is-interactive
 if test -z (echo $TMUX)
    tmux-status
    if test $status -eq 0
      exec tmux
    end
  end
end

# aliases
alias vim 'nvim'
alias pypy 'pypy3.2'
alias tmux-reload 'tmux source-file ~/.tmux.conf'
alias git 'hub'

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

# path
set -x PATH /usr/local/bin $PATH
set -x PATH $PATH $HOME/bin
set -x PATH $PATH $HOME/Works/env/pypy3/bin
set -x PATH $PATH $HOME/.local/bin
set -x PATH $PATH $HOME/.stack/programs/x86_64-osx/ghc-7.10.3/bin

# fin
fin 6

Add relative node binary path to PATH

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

# tmux
if status --is-interactive
 if test -z (echo $TMUX)
    tmux-status
    if test $status -eq 0
      exec tmux
    end
  end
end

# aliases
alias vim 'nvim'
alias pypy 'pypy3.2'
alias tmux-reload 'tmux source-file ~/.tmux.conf'
alias git 'hub'

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

# path
set -x PATH /usr/local/bin $PATH
set -x PATH $PATH $HOME/bin
set -x PATH $PATH $HOME/Works/env/pypy3/bin
set -x PATH $PATH $HOME/.local/bin
set -x PATH $PATH $HOME/.stack/programs/x86_64-osx/ghc-7.10.3/bin
set -x PATH $PATH ./node_modules/.bin

# fin
fin 6


set -gx NPM_PACKAGES "$HOME/.npm-packages"
set -gx JANET_PATH ~/.cache/janet
set -gx NODE_PATH "$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
set -gx PATH ~/bin ~/npm-packages/bin ~/.cargo/bin ~/.luarocks/bin $PATH

mkdir -p ~/bin $NPM_PACKAGES/bin ~/.cargo/bin ~/.luarocks/bin $JANET_PATH

set -gx fish_greeting ""
set -gx BROWSER firefox

if type -q direnv
  eval (direnv hook fish)
end

if type -q nvim
  set -gx EDITOR nvim
  set -gx VISUAL nvim
  set -gx MANPAGER "nvim +Man! -c ':set signcolumn='"
  alias vimdiff="nvim -d"
end

if locale -a | grep -q en_GB.UTF-8
  set -gx LANG en_GB.UTF-8
end

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

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

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

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

Correct path for npm bin

set -gx NPM_PACKAGES "$HOME/.npm-packages"
set -gx JANET_PATH ~/.cache/janet
set -gx NODE_PATH "$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
set -gx PATH ~/bin $NPM_PACKAGES/bin ~/.cargo/bin ~/.luarocks/bin $PATH

mkdir -p ~/bin $NPM_PACKAGES/bin ~/.cargo/bin ~/.luarocks/bin $JANET_PATH

set -gx fish_greeting ""
set -gx BROWSER firefox

if type -q direnv
  eval (direnv hook fish)
end

if type -q nvim
  set -gx EDITOR nvim
  set -gx VISUAL nvim
  set -gx MANPAGER "nvim +Man! -c ':set signcolumn='"
  alias vimdiff="nvim -d"
end

if locale -a | grep -q en_GB.UTF-8
  set -gx LANG en_GB.UTF-8
end

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

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

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

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


function fish_title

	set -l process $_
	set -l god ""
	set -l on_project ""
	set -l title ""

	if [ (whoami) = "root" -o $process = "sudo" ]
		set god "⚡ "
	end

	if set -q FISH_TITLE
		set title $FISH_TITLE
	else
		if [ $process = "fish" ]
			set title (prompt_pwd)
		else
			if git_is_repo
				and test -n git_repository_root
				set on_project " on "(basename (git_repository_root))
			end

			if [ $process = "sudo" ]
				set process (echo $history[1] | sed -e 's/^ *//g' -e 's/^sudo *//g' -e 's/\(^[^ ]*\)\(.*\)/\1/g')
			end

			set title $process""$on_project
		end
	end

	echo "$god"(add_padding $title (math 12 - (echo $title | wc -c) ) )

end

Use wider min-width tab titles

function fish_title

	set -l process $_
	set -l god ""
	set -l on_project ""
	set -l title ""

	if [ (whoami) = "root" -o $process = "sudo" ]
		set god "⚡ "
	end

	if set -q FISH_TITLE
		set title $FISH_TITLE
	else
		if [ $process = "fish" ]
			set title (prompt_pwd)
		else
			if git_is_repo
				and test -n git_repository_root
				set on_project " on "(basename (git_repository_root))
			end

			if [ $process = "sudo" ]
				set process (echo $history[1] | sed -e 's/^ *//g' -e 's/^sudo *//g' -e 's/\(^[^ ]*\)\(.*\)/\1/g')
			end

			set title $process""$on_project
		end
	end

	echo "$god"(add_padding $title (math 28 - (echo $title | wc -c)))

end


# Copyright 2017 Renato Utsch
#
# This project is released under the Apache 2 license.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set __fish_git_prompt_color_branch yellow
set __fish_git_prompt_showdirtystate 'yes'
set __fish_git_prompt_showuntrackedfiles 'yes'

set __fish_git_prompt_color_dirtystate red
set __fish_git_prompt_color_stagedstate green
set __fish_git_prompt_color_invalidstate red
set __fish_git_prompt_color_untrackedfiles red
set __fish_git_prompt_char_dirtystate '⚡'
set __fish_git_prompt_char_stagedstate '→'
set __fish_git_prompt_char_invalidstate '✖'
set __fish_git_prompt_char_untrackedfiles '…'

function fish_prompt
  set_color yellow
  printf '%s' (whoami)

  set_color $fish_color_cwd
  printf ' %s' (prompt_pwd)

  set_color normal
  printf '%s' (__fish_git_prompt)

  # Line 2
  echo
  printf '↪ '
  set_color normal
end

Remove git branch indicator from the fish prompt: it takes too long to return and is making the prompt slow.

# Copyright 2017 Renato Utsch
#
# This project is released under the Apache 2 license.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

function fish_prompt
  set_color yellow
  printf '%s' (whoami)

  set_color $fish_color_cwd
  printf ' %s' (prompt_pwd)

  # Line 2
  echo
  printf '↪ '
  set_color normal
end


function fish_prompt --description 'Write out the prompt'
    set -l cyan (set_color cyan)
    set -l prefix '$'

    printf '\n'
    set_color cyan
    printf '%s' (prompt_pwd)
    set_color normal
    printf '%s\n' (__fish_git_prompt)(__fish_git_prompt_dirty)
    set_color white
    printf '%s ' $prefix
    set_color normal
 end

Fix fish prompt after upgrade

function fish_prompt --description 'Write out the prompt'
    set -l cyan (set_color cyan)
    set -l prefix '$'

    printf '\n'
    set_color cyan
    printf '%s' (prompt_pwd)
    set_color normal
    printf '%s\n' (fish_git_prompt)(__fish_git_prompt_informative_status)
    set_color white
    printf '%s ' $prefix
    set_color normal
 end


complete \
    --no-files \
    -c run -c runcommand -c runcommands \
    -a '(runcommands-complete -- \
             (commandline) \
             (commandline --current-token) \
             (commandline --cursor) \
             fish)'

Add commands.py as command for fish completions

complete \
    --no-files \
    -c run -c runcommand -c runcommands -c commands.py \
    -a '(runcommands-complete -- \
             (commandline) \
             (commandline --current-token) \
             (commandline --cursor) \
             fish)'


Add an initialization script for the fish shell.

# configure git settings
if test ! -f ~/.gitconfig
    git config --global user.name "Alexandru Barbur"
    git config --global user.email "root.ctrlc@gmail.com"
    git config --global push.default simple
    git config --global color.ui auto
end

# golang
set GOPATH $HOME/go
if test -d "$GOPATH/bin"
    set PATH $PATH $GOPATH/bin
end

# user binaries
set PATH $PATH $HOME/bin


# 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"
    set -e MANPATH
end

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

Set go alias if latest go rc exists

# 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
  set GO_LATEST_RC go1.9rc2
  if which $GO_LATEST_RC >/dev/null ^&1
    alias go=$GO_LATEST_RC
  end
end

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

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


function init --on-event init_rvm
  rvm current 1>/dev/null 2>&1

  function __check_rvm --on-variable PWD -d 'Setup rvm on directory change'
    status --is-command-substitution; and return
    if test "$rvm_project_rvmrc" != 0
      set -l cwd $PWD
      while true
        if contains $cwd "" $HOME "/"
          if test "$rvm_project_rvmrc_default" = 1
            rvm default 1>/dev/null 2>&1
          end
          break
        else
          if begin
              test -s ".rvmrc"
              or test -s ".ruby-version"
              or test -s ".ruby-gemset"
              or test -s ".versions.conf"
              or test -s "Gemfile"
            end
            rvm reload 1> /dev/null 2>&1
            rvm rvmrc load 1>/dev/null 2>&1
            break
          else
            set cwd (dirname "$cwd")
          end
        end
      end
      set -e cwd
    end
  end
end

Initialize immediately, rather than waiting for an event.


function init -a path --on-event init_jump
  if not set -q MARKPATH
    set -gx MARKPATH $HOME/.marks
    command mkdir -p $MARKPATH
  end
end

Initialize immediately, rather than waiting for an event.


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


function laravel-logs
    tail -f -n 450 storage/logs/laravel/*.log | \
        rg -i "^\[\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}\]|Next [\w]+?\:"
end


function peco_checkout_git_branch
  if git_is_repo
    git branch -a | peco | tr -d ' ' | read branch
    echo $branch
    if [ $branch ]
        if contains $branch "remotes/"
            set -l b (echo $branch | awk -F'/' '{print $3}')
            git checkout -b $b $branch
        else
            git checkout $branch
        end
    end
    commandline -f repaint
  else
    echo '.git?'
  end
end

Fix handling that checkout a remote branch

function peco_checkout_git_branch
  if git_is_repo
    git branch -a | peco | tr -d ' ' | read branch
    echo $branch
    if [ $branch ]
      set -l is_remote (string match "remotes\/*" $branch)
      echo $is_remote
      if [ -n is_remote ]
        set -l b (string replace "remotes/origin/" "" $branch)
        echo $b
        git checkout $b
      else
        git checkout $branch
      end
    end
    commandline -f repaint
  else
    echo '.git?'
  end
end


# autojump
[ -f /usr/local/share/autojump/autojump.fish ]; and source /usr/local/share/autojump/autojump.fish
[ -f /usr/share/autojump/autojump.fish ]; and source /usr/share/autojump/autojump.fish

# rust
set -x RUSTPATH $HOME/.rust_workspace
set PATH $HOME/.cargo/bin $PATH

# golang
set -x GOPATH $HOME/.go_workspace
set PATH $GOPATH/bin $PATH

# theme
set fish_pager_color_progress cyan

Set GOPATH/RUSTPATH with global option

# autojump
[ -f /usr/local/share/autojump/autojump.fish ]; and source /usr/local/share/autojump/autojump.fish
[ -f /usr/share/autojump/autojump.fish ]; and source /usr/share/autojump/autojump.fish

# rust
set -xg RUSTPATH $HOME/.rust_workspace
set PATH $HOME/.cargo/bin $PATH

# golang
set -xg GOPATH $HOME/.go_workspace
set PATH $GOPATH/bin $PATH

# theme
set fish_pager_color_progress cyan


function subl --description 'Open Sublime Text'
  if test -d "/Applications/Sublime Text.app"
    "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" $argv
  else if test -d "/Applications/Sublime Text 2.app"
    "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" $argv
  else if test -x "/opt/sublime_text/sublime_text"
    "/opt/sublime_text/sublime_text" $argv
  else if test -x "/opt/sublime_text_3/sublime_text"
    "/opt/sublime_text_3/sublime_text" $argv
  else
    echo "No Sublime Text installation found"
  end
end

Add support for ST and ST3 installations inside `~/Applications` on OS X

function subl --description 'Open Sublime Text'
  if test -d "/Applications/Sublime Text.app"
    "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" $argv
  else if test -d "/Applications/Sublime Text 2.app"
    "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" $argv
  else if test -d "$HOME/Applications/Sublime Text.app"
    eval "$HOME/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl" $argv
  else if test -d "$HOME/Applications/Sublime Text 2.app"
    eval "$HOME/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl" $argv
  else if test -x "/opt/sublime_text/sublime_text"
    "/opt/sublime_text/sublime_text" $argv
  else if test -x "/opt/sublime_text_3/sublime_text"
    "/opt/sublime_text_3/sublime_text" $argv
  else
    echo "No Sublime Text installation found"
  end
end


#
# ~/.config/fish/config.fish
# Dotfiles
#

fish_vi_key_bindings

# Variables
source ~/.config/fish/variables.fish

# Termial colors
set fish_color_autosuggestion 555\x1eyellow
set fish_color_command 005fd7\x1epurple
set fish_color_comment red
set fish_color_cwd green
set fish_color_cwd_root red
set fish_color_error red\x1e\x2d\x2dbold
set fish_color_escape cyan
set fish_color_history_current cyan
set fish_color_host \x2do\x1ecyan
set fish_color_match cyan
set fish_color_normal normal
set fish_color_operator cyan
set fish_color_param 00afff\x1ecyan
set fish_color_quote brown
set fish_color_redirection normal
set fish_color_search_match \x2d\x2dbackground\x3dpurple
set fish_color_status red
set fish_color_user \x2do\x1egreen
set fish_color_valid_path \x2d\x2dunderline
set fish_greeting \x1d
set fish_key_bindings fish\x5fdefault\x5fkey\x5fbindings
set fish_pager_color_completion normal
set fish_pager_color_description 555\x1eyellow
set fish_pager_color_prefix cyan
set fish_pager_color_progress cyan

Print fish logo when fish starts

#
# ~/.config/fish/config.fish
# Dotfiles
#

logo
fish_vi_key_bindings

# Variables
source ~/.config/fish/variables.fish

# Termial colors
set fish_color_autosuggestion 555\x1eyellow
set fish_color_command 005fd7\x1epurple
set fish_color_comment red
set fish_color_cwd green
set fish_color_cwd_root red
set fish_color_error red\x1e\x2d\x2dbold
set fish_color_escape cyan
set fish_color_history_current cyan
set fish_color_host \x2do\x1ecyan
set fish_color_match cyan
set fish_color_normal normal
set fish_color_operator cyan
set fish_color_param 00afff\x1ecyan
set fish_color_quote brown
set fish_color_redirection normal
set fish_color_search_match \x2d\x2dbackground\x3dpurple
set fish_color_status red
set fish_color_user \x2do\x1egreen
set fish_color_valid_path \x2d\x2dunderline
set fish_greeting \x1d
set fish_key_bindings fish\x5fdefault\x5fkey\x5fbindings
set fish_pager_color_completion normal
set fish_pager_color_description 555\x1eyellow
set fish_pager_color_prefix cyan
set fish_pager_color_progress cyan


Add function to remove a path from fish_user_paths

function remove_from_user_path --description "Removes the given path from fish_user_paths"
  set -Ux fish_user_paths (echo $fish_user_paths | sed 's| '$argv[1]'||g')
end


function check_kernel --description='Output message if installed and running kernels are different.'
  set installed (string match --regex '\d\d?.\d\d?.\d\d?' (pacman --query linux))
  #                                                        linux 4.18.5.arch1-1
  set running (string match --regex '\d\d?.\d\d?.\d\d?' (uname --kernel-release))
  #                                                      4.18.4-arch1-1-ARCH
  if test ! $running = $installed
    printf 'Kernel out of date!'
  end
end

Update output format for status bar

function check_kernel --description='Output message if installed and running kernels are different.'
  #                                                     e.g. linux 4.18.5.arch1-1
  set installed (string match --regex '\d\d?.\d\d?.\d\d?' (pacman --query linux))
  #                                                     e.g. 4.18.4-arch1-1-ARCH
  set running (string match --regex '\d\d?.\d\d?.\d\d?' (uname --kernel-release))
  if test ! $running = $installed
    printf "🐧😞"
  else
    printf "🐧☺"
  end
end


function md5_file_verify
    if test (md5 $argv[1] | cut -f 2 -d "=" | sed 's/ *//') != $argv[2];
        echo "md5 NOT VERIFIED"; and return 1;
    end
end


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

Fix switching from insert mode to normal 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 force-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


#!/usr/bin/env fish

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

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

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

# Reference
alias rsbook="open /usr/local/share/doc/rust/html/book/index.html"

# Haxe
alias flixel="haxelib run flixel-tools"
alias lime="haxelib run lime"
alias ihx="haxelib run ihx"

Add alias to open command in same dir but new tmux pane

#!/usr/bin/env fish

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

# Navigation
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias wo=workon
# open a command in a new pane
alias tsplit="tmux split-window -h"

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

# Reference
alias rsbook="open /usr/local/share/doc/rust/html/book/index.html"

# Haxe
alias flixel="haxelib run flixel-tools"
alias lime="haxelib run lime"
alias ihx="haxelib run ihx"


function chrome-dl --description "Download Chrome extensions, given their IDs"
  for extension_id in $argv
    curl --output "$extension_id.zip" \
         --location "https://clients2.google.com/service/update2/crx?response=redirect&os=mac&arch=x86-64&nacl_arch=x86-64&prod=chromecrx&prodchannel=stable&prodversion=44.0.2403.130&x=id%3D$extension_id%26uc"
    unzip -d "$extension_id-source" "$extension_id.zip"
    rm "$extension_id.zip"
  end
end

Add source for how to download Chrome extensions from CLI

# Based on https://gist.github.com/paulirish/78d6c1406c901be02c2d

function chrome-dl --description "Download Chrome extensions, given their IDs"
  for extension_id in $argv
    curl --output "$extension_id.zip" \
         --location "https://clients2.google.com/service/update2/crx?response=redirect&os=mac&arch=x86-64&nacl_arch=x86-64&prod=chromecrx&prodchannel=stable&prodversion=44.0.2403.130&x=id%3D$extension_id%26uc"
    unzip -d "$extension_id-source" "$extension_id.zip"
    rm "$extension_id.zip"
  end
end


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

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

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

Add local bins for cabal installed user binaries

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

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

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

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


function __paradox_command_duration --description "Get the current command duration"
  if begin; set -q CMD_DURATION; and test $CMD_DURATION -ge 500; end
    # I do it in this somewhat roundabout way to preserve some floating point math
    set -l x (math "scale=2;$CMD_DURATION / 1000")
    set -l seconds (math "$x % 60")
    set -l timestamp (printf "%.02gs" $seconds)
    if test (math "$x >= 60") -eq 1
      set -l x (math "$x / 60")
      set -l minutes (math "$x % 60")
      set -l timestamp (printf "%dm" $minutes) $timestamp
      if test (math "$x >= 60") -eq 1
        set -l x (math "$x / 60")
        set -l hours (math "$x % 24")
        set -l timestamp (printf "%dh" $hours) $timestamp

        if test (math "$x >= 24") -eq 1
          set -l days (math "$x / 24")
          set -l timestamp (printf "%dd" $days) $timestamp

        end
      end
    end
    echo -s "[⌛ $timestamp]"
  end
end

Remove emoji from timestamp and update math for 3

function __paradox_command_duration --description "Get the current command duration"
  if begin; set -q CMD_DURATION; and test $CMD_DURATION -ge 500; end
    # I do it in this somewhat roundabout way to preserve some floating point math
    set -l x (math --scale=2 "$CMD_DURATION / 1000")
    set -l seconds (math "$x % 60")
    set -l timestamp (printf "%.02gs" $seconds)
    if test $x -ge 60
      set -l x (math "$x / 60")
      set -l minutes (math "$x % 60")
      set -l timestamp (printf "%dm" $minutes) $timestamp
      if test $x -ge 60
        set -l x (math "$x / 60")
        set -l hours (math "$x % 24")
        set -l timestamp (printf "%dh" $hours) $timestamp

        if test $x -ge 60
          set -l days (math "$x / 24")
          set -l timestamp (printf "%dd" $days) $timestamp

        end
      end
    end
    echo -s "[$timestamp]"
  end
end


function check_system -d 'Display short system name (OSX, Linux, Win, NA)'
  set -l osname (uname 2>/dev/null); or set -l osname (/usr/bin/uname 2>/dev/null)      # fix for lacking MSYS2 path
  if test "$osname" = Darwin
    echo OSX
  else if begin
      test (echo "$osname" | grep -E MSYS_NT 2>/dev/null)
      or test (echo "$osname" | grep -E MINGW32_NT 2>/dev/null)
      or test (echo "$osname" | grep -E MINGW64_NT 2>/dev/null)
    end
    echo Win
  else if test "$osname" = TESTLINUX
    echo Linux
  else
    echo NA
  end
end

Improve OS detection, adding Windows Subsystem for Linux

function check_system -d 'Display short system name (OSX, Linux, Win, NA)'
  set -l osname (uname | tr '[:upper:]' '[:lower:]' 2>/dev/null); or set -l osname (fish -c "uname | tr '[:upper:]' '[:lower:]'"); or set -l osname (/usr/bin/uname | tr '[:upper:]' '[:lower:]' 2>/dev/null)
  # fix for lacking MSYS2 path; 2nd needed for WSL as regular commands fails (bug https://github.com/Microsoft/BashOnWindows/issues/1210)
  if test "$osname" = darwin
    echo OSX
  else if begin
      test (echo "$osname" | grep -E msys_nt 2>/dev/null)
      or test (echo "$osname" | grep -E mingw32_nt 2>/dev/null)
      or test (echo "$osname" | grep -E mingw64_nt 2>/dev/null)
    end
    echo Win
  else if test "$osname" = linux
    echo Linux
  else
    echo NA
  end
end


set PATH ~/npm/bin $PATH
set EDITOR vim
set VISUAL vim
set fish_greeting ""

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

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

# Git alias.
alias g="git"
alias gs="cowsay -f ghostbusters 'gs is ghostscript, not git status!'"

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

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

Set a browser in my terminal

set PATH ~/npm/bin $PATH
set BROWSER firefox
set EDITOR vim
set VISUAL vim
set fish_greeting ""

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

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

# Git alias.
alias g="git"
alias gs="cowsay -f ghostbusters 'gs is ghostscript, not git status!'"

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

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


function randombase64 -d "Generate random base64 string"
  set -l n $argv[1]; test -z $n; and set n 16
  # https://en.wikipedia.org/wiki/Birthday_problem#Probability_table
  dd if=/dev/urandom bs=1 count=$n ^/dev/null | base64 | tr -d "[/+]" | cut -b -$n
end

Switch to non-deprecated redirection syntax

function randombase64 -d "Generate random base64 string"
  set -l n $argv[1]; test -z $n; and set n 16
  # https://en.wikipedia.org/wiki/Birthday_problem#Probability_table
  dd if=/dev/urandom bs=1 count=$n 2>/dev/null | base64 | tr -d "[/+]" | cut -b -$n
end


function __is_a_bundled_executable
  if available bundle
    set -l bindir (command bundle exec ruby -e "puts Gem.bindir")
    test -f "$bindir/$argv"
  else
    return 1
  end
end

Replace `available` usage with `type -q`

function __is_a_bundled_executable
  if type -q bundle
    set -l bindir (command bundle exec ruby -e "puts Gem.bindir")
    test -f "$bindir/$argv"
  else
    return 1
  end
end


function fish_user_key_bindings
	bind --erase \cd
	bind \e\[A 'history --merge ; up-or-search'
end

Allow Ctrl-d to exit a shell

function fish_user_key_bindings
	bind \e\[A 'history --merge ; up-or-search'
end


# environment variables
set -gx GOPATH ~/.go
set -gx fish_user_paths $GOPATH/bin
set -gx EDITOR nvim
set -gx FZF_DEFAULT_COMMAND 'ag --hidden --ignore .git -l -g ""'
set -gx FZF_DEFAULT_OPTS '--color=16,fg+:4'
set -gx FZF_CTRL_T_COMMAND 'ag --hidden --ignore .git -l -g ""'
set -gx FZF_CTRL_R_OPTS '--reverse'
set -gx fish_prompt_pwd_dir_length 0

Make fzf use --ansi by default (for colored input & whatnot)

# environment variables
set -gx GOPATH ~/.go
set -gx fish_user_paths $GOPATH/bin
set -gx EDITOR nvim
set -gx FZF_DEFAULT_COMMAND 'ag --hidden --ignore .git -l -g ""'
set -gx FZF_DEFAULT_OPTS '--color=16,fg+:4 --ansi'
set -gx FZF_CTRL_T_COMMAND 'ag --hidden --ignore .git -l -g ""'
set -gx FZF_CTRL_R_OPTS '--reverse'
set -gx fish_prompt_pwd_dir_length 0


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

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

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

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

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

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

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

Add a fish function to test psci

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

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

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

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

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

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

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

# psci
set psci_env $HOME/Works/env/psci
function psci
  set prev (pwd)
  cd $psci_env
  pulp psci
  cd $prev
end


function dotfile::append_env
    if not contains $argv[1] $argv[2]
        set --append $argv[1] $argv[2]
    end
end

function dotfile::prepend_env
    if not contains $argv[1] $argv[2]
        set --prepend $argv[1] $argv[2]
    end
end

function dotfile::set_env
    set --export --global $argv[1] $argv[2]
end

function dotfile::unset_env
    set --erase $argv[1]
end

function dotfile::load
    if test -f $argv[1]
        source $argv[1]
    end
end

function dotfile::load_all
    for file in (find -L $argv[1] -name $argv[2] -type f)
        source $file
    end
end

function dotfile::alias
    alias $argv[1] $argv[2]
end

Support colon separated environmental variables

function dotfile::append_env
    set --local name $argv[1]
    set --local values $argv[2]

    if not set --query $name
        dotfile::set_env $name $values
        return
    end

    for value in (string split ":" $values)
        if not contains $value $$name
            set --append $name $value
        end
    end
end

function dotfile::prepend_env
    set --local name $argv[1]
    set --local values $argv[2]

    if not set --query $name
        dotfile::set_env $name $values
        return
    end

    for value in (string split ":" $values)[-1..1]
        if not contains $value $$name
            set --prepend $name $value
        end
    end
end

function dotfile::set_env
    set --export --global $argv[1] $argv[2]
end

function dotfile::unset_env
    set --erase $argv[1]
end

function dotfile::load
    if test -f $argv[1]
        source $argv[1]
    end
end

function dotfile::load_all
    for file in (find -L $argv[1] -name $argv[2] -type f)
        source $file
    end
end

function dotfile::alias
    alias $argv[1] $argv[2]
end


function create-bucket --argument-names name
    print-status s3/create-bucket $name
    aws s3api create-bucket --bucket $name
end

Add support for bucket regions

function create-bucket --argument-names name
    print-status s3/create-bucket $name
    set --local options

    has region s3/buckets/$name
    and set -- options $options --create-bucket-configuration LocationConstraint=(get s3/buckets/$name/region)

    aws s3api create-bucket --bucket $name $options
end


set -gx NPM_DIR "$HOME/.npm-data"
set -gx NODE_PATH "$NPM_DIR/lib/node_modules:$NODE_PATH"
set -gx PATH ~/bin $NPM_DIR/bin $PATH

mkdir -p ~/bin $NPM_DIR/bin

set -gx fish_greeting ""

test -d ~/.linuxbrew && eval (~/.linuxbrew/bin/brew shellenv)
test -d /home/linuxbrew/.linuxbrew && eval (/home/linuxbrew/.linuxbrew/bin/brew shellenv)

if type -q nvim
  set -gx EDITOR nvim
  set -gx VISUAL nvim
  set -gx MANPAGER "nvim +Man! -c ':set signcolumn='"
  alias vimdiff="nvim -d"
end

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

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

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

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

Add python pip dir to path

set -gx NPM_DIR "$HOME/.npm-data"
set -gx NODE_PATH "$NPM_DIR/lib/node_modules:$NODE_PATH"
set -gx PATH ~/bin $NPM_DIR/bin $HOME/.local/bin $PATH

mkdir -p ~/bin $NPM_DIR/bin

set -gx fish_greeting ""

test -d ~/.linuxbrew && eval (~/.linuxbrew/bin/brew shellenv)
test -d /home/linuxbrew/.linuxbrew && eval (/home/linuxbrew/.linuxbrew/bin/brew shellenv)

if type -q nvim
  set -gx EDITOR nvim
  set -gx VISUAL nvim
  set -gx MANPAGER "nvim +Man! -c ':set signcolumn='"
  alias vimdiff="nvim -d"
end

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

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

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

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


command -sq fluidsynth; and function playmidi
    fluidsynth -i ~/lib/arachno-soundfont/Arachno\ SoundFont\ -\ Version\ 1.0.sf2 $argv
end

command -sq kitty; and function icat
    kitty +kitten icat
end

command -sq kubectl; and function kcexec
    argparse -N 2 --name=kcexec 'r/replica=' -- $argv
    or return

    if not set -q _flag_replica
        set -l _flag_replica 0
    end

    kubectl exec -it (kubectl get pod -o jsonpath="{.items[$_flag_replica].metadata.name}" -l app.kubernetes.io/name=$argv[1]) -c $argv[1] $argv[2..-1]
end

command -sq kubectl; and begin
    function kcnodepods -d 'List all pods on a given node'
        argparse -N 1 -X 1 --name=kcnodepods 'n/namespace=?' -- $argv
        or return

        if not set -q _flag_namespace
            kubectl get pods --all-namespaces --field-selector=spec.nodeName=$argv[1]
        else
            kubectl get pods --namespace=$_flag_namespace --field-selector=spec.nodeName=$argv[1]
        end
    end

    function k8senv
        kops version
        kubectl version --client --short
        helm version --client --short
    end
end

functions rvm >/dev/null 2>&1; and rvm default

set fish_greeting

Set fish_greeting in k8s shells

command -sq fluidsynth; and function playmidi
    fluidsynth -i ~/lib/arachno-soundfont/Arachno\ SoundFont\ -\ Version\ 1.0.sf2 $argv
end

command -sq kitty; and function icat
    kitty +kitten icat
end

command -sq kubectl; and function kcexec
    argparse -N 2 --name=kcexec 'r/replica=' -- $argv
    or return

    if not set -q _flag_replica
        set -l _flag_replica 0
    end

    kubectl exec -it (kubectl get pod -o jsonpath="{.items[$_flag_replica].metadata.name}" -l app.kubernetes.io/name=$argv[1]) -c $argv[1] $argv[2..-1]
end

command -sq kubectl; and begin
    function kcnodepods -d 'List all pods on a given node'
        argparse -N 1 -X 1 --name=kcnodepods 'n/namespace=?' -- $argv
        or return

        if not set -q _flag_namespace
            kubectl get pods --all-namespaces --field-selector=spec.nodeName=$argv[1]
        else
            kubectl get pods --namespace=$_flag_namespace --field-selector=spec.nodeName=$argv[1]
        end
    end

    function k8senv
        kops version
        kubectl version --client --short
        helm version --client --short
    end
end

functions rvm >/dev/null 2>&1; and rvm default

if string match -r '.*k8s-\d+$' "$buildInputs"
    set fish_greeting (k8senv)
else
    set fish_greeting
end


function pip_save
    set -l reqs "requirements.txt"
    pip install $argv[1]
    set freeze (pip freeze | grep $argv[1])
    set tfile (mktemp)
    cp $reqs $tfile
    echo $freeze >> $tfile
    uniq $tfile | sort -o $reqs
end


set fish_greeting ""
set LANG en_GB.UTF-8
set PATH ~/bin $PATH
set EDITOR nvim
set VISUAL nvim

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

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

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

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

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

# Hook up node and ruby version managers.
# if [ -d ~/.nvm ]
#   nvm use default --silent
# end

# if [ -d ~/.rvm ]
#   rvm default
# end

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

Add npm to the path again

set fish_greeting ""
set LANG en_GB.UTF-8
set PATH ~/bin ~/npm/bin $PATH
set EDITOR nvim
set VISUAL nvim

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

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

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

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

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

# Hook up node and ruby version managers.
# if [ -d ~/.nvm ]
#   nvm use default --silent
# end

# if [ -d ~/.rvm ]
#   rvm default
# end

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


#
# Maintains a frequently used file and directory list for fast access.
#

# Avoid config if requirements are not found.
if not type -q fasd
  exit
end

#
# Tweaks
#

# Change fasd data dir
set -x _FASD_DATA "$HOME/.cache/fasd/data"

#
# Aliases
#

alias ao 'fasd -a -e atom' # find files/dirs with fasd and open them in Atom
alias so 'fasd -a -e subl' # find files/dirs with fasd and open them in Sublime

Add command to create folder for fasd during its setup

#
# Maintains a frequently used file and directory list for fast access.
#

# Avoid config if requirements are not found.
if not type -q fasd
  exit
end

#
# Tweaks
#

# Create fasd data dir if it's not already created
mkdir -p "$HOME/.cache/fasd"

# Change fasd data dir
set -x _FASD_DATA "$HOME/.cache/fasd/data"

#
# Aliases
#

alias ao 'fasd -a -e atom' # find files/dirs with fasd and open them in Atom
alias so 'fasd -a -e subl' # find files/dirs with fasd and open them in Sublime


mkdir -p ~/bin ~/npm/bin ~/.cargo/bin

set fish_greeting ""
set LANG en_GB.UTF-8
set PATH ~/bin ~/npm/bin ~/.cargo/bin ~/.gem/ruby/2.5.0/bin $PATH
set BROWSER chromium
set EDITOR nvim
set VISUAL nvim

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

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

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

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

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

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

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

Make sure the ruby gem bin dir exists

mkdir -p ~/bin ~/npm/bin ~/.cargo/bin ~/.gem/ruby/2.5.0/bin

set fish_greeting ""
set LANG en_GB.UTF-8
set PATH ~/bin ~/npm/bin ~/.cargo/bin ~/.gem/ruby/2.5.0/bin $PATH
set BROWSER chromium
set EDITOR nvim
set VISUAL nvim

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

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

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

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

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

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

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


set PATH ~/bin ~/npm/bin $PATH
set EDITOR nvim
set VISUAL nvim
set fish_greeting ""

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

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

# Git alias.
alias g="git"

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

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

Add an alias vimdiff -> nvim -d

set PATH ~/bin ~/npm/bin $PATH
set EDITOR nvim
set VISUAL nvim
set fish_greeting ""

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

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

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

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

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

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


function system-info -d 'Print the system information'
	free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%)\n", $3,$2,$3*100/$2 }'
	df -h | awk '$NF=="/"{printf "Disk Usage: %d/%dGB (%s)\n", $3,$2,$5}'
	top -bn1 | grep load | awk '{printf "CPU Load: %.2f\n", $(NF-2)}'
end

Add `open-file-info` alias to show the number of current open files descriptors

function system-info -d 'Print the system information'
  free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%)\n", $3,$2,$3*100/$2 }'
  df -h | awk '$NF=="/"{printf "Disk Usage: %d/%dGB (%s)\n", $3,$2,$5}'
  top -bn1 | grep load | awk '{printf "CPU Load: %.2f\n", $(NF-2)}'
end

function open-file-info -d 'Print the number of the open file descripters for each process'
  lsof -n | awk '{print $1 " " $2}' | uniq -c | sort -n
end


set fish_greeting ''

# PATH
set PATH '/usr/local/sbin' $PATH
set PATH '/usr/local/bin' $PATH
set PATH "$HOME/.cargo/bin" $PATH
set PATH "$HOME/bin" $PATH

# Environment variables - https://fishshell.com/docs/current/commands.html#set
set -xg EDITOR 'nvim'
set -xg BUNDLER_EDITOR $EDITOR
set -xg MANPAGER 'less -X' # Don’t clear the screen after quitting a manual page
set -xg HOMEBREW_CASK_OPTS '--appdir=/Applications'
set -xg SOURCE_ANNOTATION_DIRECTORIES 'spec'
set -xg RUBY_CONFIGURE_OPTS '--with-opt-dir=/usr/local/opt/openssl:/usr/local/opt/readline:/usr/local/opt/libyaml:/usr/local/opt/gdbm'
set -xg XDG_CONFIG_HOME "$HOME/.config"
set -xg XDG_DATA_HOME "$HOME/.local/share"
set -xg XDG_CACHE_HOME "$HOME/.cache"
set -xg TERM 'screen-256color'

. $OMF_CONFIG/abbreviations.fish

fish_vi_key_bindings

# https://github.com/starship/starship#fish
starship init fish | source

# asdf
. $HOME/.asdf/asdf.fish

if test -e ~/.fish.local
  . ~/.fish.local
end

Set FZF_DEFAULT_COMMAND to use rg.

set fish_greeting ''

# PATH
set PATH '/usr/local/sbin' $PATH
set PATH '/usr/local/bin' $PATH
set PATH "$HOME/.cargo/bin" $PATH
set PATH "$HOME/bin" $PATH

# Environment variables - https://fishshell.com/docs/current/commands.html#set
set -xg EDITOR 'nvim'
set -xg BUNDLER_EDITOR $EDITOR
set -xg MANPAGER 'less -X' # Don’t clear the screen after quitting a manual page
set -xg HOMEBREW_CASK_OPTS '--appdir=/Applications'
set -xg SOURCE_ANNOTATION_DIRECTORIES 'spec'
set -xg RUBY_CONFIGURE_OPTS '--with-opt-dir=/usr/local/opt/openssl:/usr/local/opt/readline:/usr/local/opt/libyaml:/usr/local/opt/gdbm'
set -xg XDG_CONFIG_HOME "$HOME/.config"
set -xg XDG_DATA_HOME "$HOME/.local/share"
set -xg XDG_CACHE_HOME "$HOME/.cache"
set -xg TERM 'screen-256color'
set -xg FZF_DEFAULT_COMMAND 'rg --files --hidden'

. $OMF_CONFIG/abbreviations.fish

fish_vi_key_bindings

# https://github.com/starship/starship#fish
starship init fish | source

# asdf
. $HOME/.asdf/asdf.fish

if test -e ~/.fish.local
  . ~/.fish.local
end


# gvm
# https://github.com/moovweb/gvm
bass [[ -s "$HOME/.gvm/scripts/gvm" ]]
bass source "$HOME/.gvm/scripts/gvm"

# 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 gs "git status"
alias gpnf "git push --no-verify"
alias gpnff "git push --no-verify --force"

# 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

# 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 a couple of git aliases

# gvm
# https://github.com/moovweb/gvm
bass [[ -s "$HOME/.gvm/scripts/gvm" ]]
bass source "$HOME/.gvm/scripts/gvm"

# 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"

# 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

# 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


function psource -d 'Execute POSIX shell script in the current shell context'
  /bin/sh -c '. "$@"; XDG_CONFIG_HOME="${0%/*/*}/etc" "$0" -c "set -gxL" | sed -e "/^\(HOME\|LC_CTYPE\|PATH\|PWD\|SHLVL\|USER\|XDG_CONFIG_HOME\) /d" -e "s/^/set -gx /" >&3' (status fish-path) $argv 3>| source
end

Make sed syntax bsd compatible

function psource -d 'Execute POSIX shell script in the current shell context'
  /bin/sh -c '. "$@"; XDG_CONFIG_HOME="${0%/*/*}/etc" "$0" -c "set -gxL" | sed -e "/^HOME /d" -e "/^LC_CTYPE /d" -e "/^PATH /d" -e "/^PWD /d" -e "/^SHLVL /d" -e "/^USER /d" -e "/^XDG_CONFIG_HOME /d" -e "s/^/set -gx /" >&3' (status fish-path) $argv 3>| source
end


function itunes -d "Control iTunes. Use -h or --help for a more detailed description."
  if [ (count $argv) -gt 0 ]
    set -l opt $argv[1]
    switch $opt
      case launch play pause stop rewind resume quit
      case mute
        set opt "set mute to true"
      case unmute
        set opt "set mute to false"
      case next previous
        set opt "$opt track"
      case vol volume
        set opt "set sound volume to $argv[2]"
      case "" -h --help
        echo "Usage: itunes <option>"
        echo "option:"
        echo \t"launch|play|pause|stop|rewind|resume|quit"
        echo \t"mute|unmute\tcontrol volume set"
        echo \t"next|previous\tplay next or previous track"
        echo \t"vol"\t"Set the volume, takes an argument from 0 to 100"
        echo \t"help"\t"show this message and exit"
        return 0
      case '*'
        echo "Unknown option $opt. Use -h or --help for a more detailed description."
        return 1
    end
    osascript -e "tell application \"iTunes\" to $opt"
  else
    echo "Arguments expected. Use -h or --help for a more detailed description."
  end
end

Improve `itune`'s `--help` output with usage info

function itunes -d "Control iTunes. Use -h or --help for a more detailed description."
  if [ (count $argv) -gt 0 ]
    set -l opt $argv[1]
    switch $opt
      case launch play pause stop rewind resume quit
      case mute
        set opt "set mute to true"
      case unmute
        set opt "set mute to false"
      case next previous
        set opt "$opt track"
      case vol volume
        set opt "set sound volume to $argv[2]"
      case "" -h --help
        echo "Usage: itunes <option>"
        echo "option:"
        echo \t"launch, play, pause, stop, rewind, resume, quit"
        echo \t"mute, unmute    Control volume set"
        echo \t"next, previous  Play next or previous track"
        echo \t"vol             Set the volume, takes an argument from 0 to 100"
        echo \t"help            Show this message and exit"
        return 0
      case '*'
        echo "Unknown option $opt. Use -h or --help for a more detailed description."
        return 1
    end
    osascript -e "tell application \"iTunes\" to $opt"
  else
    echo "Arguments expected. Use -h or --help for a more detailed description."
  end
end


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

# XDG
set --export XDG_CONFIG_HOME $HOME/.config
set --export XDG_DATA_HOME $HOME/.local/share

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

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

# Postgres
set --export PSQLRC $XDG_CONFIG_HOME/psqlrc

for profile in $NIX_PROFILES
	set PATH $profile/bin $PATH
end
set PATH $HOME/.local/bin $PATH
set PATH $HOME/.luarocks/bin $PATH
set PATH ./node_modules/.bin $XDG_DATA_HOME/node_modules/bin $PATH
set --export PATH $PATH

Set locale to British English

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

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

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

# XDG
set --export XDG_CONFIG_HOME $HOME/.config
set --export XDG_DATA_HOME $HOME/.local/share

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

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

# Postgres
set --export PSQLRC $XDG_CONFIG_HOME/psqlrc

for profile in $NIX_PROFILES
	set PATH $profile/bin $PATH
end
set PATH $HOME/.local/bin $PATH
set PATH $HOME/.luarocks/bin $PATH
set PATH ./node_modules/.bin $XDG_DATA_HOME/node_modules/bin $PATH
set --export PATH $PATH


function __vfext_global_requirements --on-event virtualenv_did_create
    if test -f $VIRTUALFISH_HOME/global_requirements.txt
        pip install -r $VIRTUALFISH_HOME/global_requirements.txt
    end
end

function __vf_requirements --description "Edit the global requirements file for all virtualenvs"
    eval $EDITOR $VIRTUALFISH_HOME/global_requirements.txt
    pushd $VIRTUALFISH_HOME
    for i in */bin/pip
        eval $i install -r $VIRTUALFISH_HOME/global_requirements.txt
    end
end

Use wheel for global requirements if it's enabled.

function __vfext_global_requirements --on-event virtualenv_did_create
    if test -f $VIRTUALFISH_HOME/global_requirements.txt
        pip install -r $VIRTUALFISH_HOME/global_requirements.txt
    end
end

function __vf_requirements --description "Edit the global requirements file for all virtualenvs"
    eval $EDITOR $VIRTUALFISH_HOME/global_requirements.txt
    pushd $VIRTUALFISH_HOME
    # If the user has set up wheels, make sure we build wheels of all the deps
    # prior to trying to install them, so as to speed things up
    if set -q PIP_USE_WHEEL
        pip wheel -r $VIRTUALFISH_HOME/global_requirements.txt
    end
    for i in */bin/pip
        eval $i install -U -r $VIRTUALFISH_HOME/global_requirements.txt
    end
    popd
end


# Language settings
set -x LC_ALL en_US.UTF-8
set -x LC_CTYPE en_US.UTF-8

# respect local bins
set -x PATH "./bin" $PATH

# editor
set -x EDITOR "nvim"

# LESS with colors
# from http://blog.0x1fff.com/2009/11/linux-tip-color-enabled-pager-less.html
set -x LESS "-RSM~gIsw"

# Colorful man pages
# from http://pastie.org/pastes/206041/text
setenv -x LESS_TERMCAP_mb (set_color -o red)
setenv -x LESS_TERMCAP_md (set_color -o red)
setenv -x LESS_TERMCAP_me (set_color normal)
setenv -x LESS_TERMCAP_se (set_color normal)
setenv -x LESS_TERMCAP_so (set_color -b blue -o yellow)
setenv -x LESS_TERMCAP_ue (set_color normal)
setenv -x LESS_TERMCAP_us (set_color -o green)

# grep colors
setenv -x GREP_OPTIONS "--color=auto"

Remove grep colors. Its is obsolete


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

set fish_color_command white
set fish_color_autosuggestion yellow
set fish_pager_color_description yellow
set fish_color_param white

Initialize rbenv when starting a fish shell

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

set fish_color_command white
set fish_color_autosuggestion yellow
set fish_pager_color_description yellow
set fish_color_param white

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


direnv hook fish | source
opam config env | source

set brew_rbenv "/usr/local/var/rbenv/shims"

set -gx EDITOR vim
set -gx GIT_EDITOR vim
set -gx RBENV_ROOT /usr/local/var/rbenv
set -gx PYENV_ROOT /usr/local/var/pyenv
set -gx GOPATH /usr/local/var/go
set -gx NVM_DIR /usr/local/var/nvm

set -gx DOCKER_USER rajatvig

set -gx RUST_SRC_PATH $HOME/.multirust/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src

set -g fish_user_paths $HOME/.cabal/bin $fish_user_paths
set -g fish_user_paths $HOME/.cargo/bin $fish_user_paths
set -g fish_user_paths "/usr/local/sbin" $fish_user_paths

set tacklebox_path  ~/.config/fish_plugins/z ~/.config/fish_plugins/tackle ~/.config/fish_plugins/to ~/.config/fish_plugins/brew ~/.config/fish_plugins/pyenv ~/.config/fish_plugins/git
set tacklebox_modules virtualfish z
set tacklebox_plugins docker extract grc pip python

# set tacklebox_theme budspencer

source ~/.config/fish_plugins/tacklebox/tacklebox.fish

Add alias for the thefuck

direnv hook fish | source
opam config env | source
thefuck --alias | source

set brew_rbenv "/usr/local/var/rbenv/shims"

set -gx EDITOR vim
set -gx GIT_EDITOR vim
set -gx RBENV_ROOT /usr/local/var/rbenv
set -gx PYENV_ROOT /usr/local/var/pyenv
set -gx GOPATH /usr/local/var/go
set -gx NVM_DIR /usr/local/var/nvm

set -gx DOCKER_USER rajatvig

set -gx RUST_SRC_PATH $HOME/.multirust/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src

set -g fish_user_paths $HOME/.cabal/bin $fish_user_paths
set -g fish_user_paths $HOME/.cargo/bin $fish_user_paths
set -g fish_user_paths "/usr/local/sbin" $fish_user_paths

set tacklebox_path  ~/.config/fish_plugins/z ~/.config/fish_plugins/tackle ~/.config/fish_plugins/to ~/.config/fish_plugins/brew ~/.config/fish_plugins/pyenv ~/.config/fish_plugins/git
set tacklebox_modules virtualfish z
set tacklebox_plugins docker extract grc pip python

# set tacklebox_theme budspencer

source ~/.config/fish_plugins/tacklebox/tacklebox.fish


# gvm
# https://github.com/moovweb/gvm
bass [[ -s "$HOME/.gvm/scripts/gvm" ]]
bass source "$HOME/.gvm/scripts/gvm"

# 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"

# 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

# 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 local executables to PATH

# gvm
# https://github.com/moovweb/gvm
bass [[ -s "$HOME/.gvm/scripts/gvm" ]]
bass source "$HOME/.gvm/scripts/gvm"

# 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"

# 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

# 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


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

	# Just calculate this 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

	set -l suffix

	switch (whoami)
	case root toor
		set suffix '#'
	case '*'
		set suffix '>'
	end

	set -l success

	switch $exit_code
	case 0
		set success green
	case '*'
		set success red
	end

	set -l prompt_git
	set git_branch " ("(git rev-parse --abbrev-ref HEAD ^ /dev/null)") "

	switch $status
	case 0
		set prompt_git $git_branch
	case '*'
		set prompt_git ''
	end

	echo -n -s "$USER" @ "$__fish_prompt_hostname" ' ' (set_color $success) (prompt_pwd) (set_color --bold $success) "$git_branch"  (set_color normal) "$suffix "
end


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

eval (python -m virtualfish compat_aliases)

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

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

Add hub alias to fish config

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

eval (python -m virtualfish compat_aliases)
eval (hub alias -s)

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

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


# name: GitStatus
# Find latest version from: https://github.com/godfat/fish_prompt-gitstatus

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

function _git_status_symbol
  set -l git_status (git status --porcelain ^/dev/null)
  if test -n "$git_status"
    # Is there anyway to preserve newlines so we can reuse $git_status?
    if git status --porcelain ^/dev/null | grep '^.[^ ]' >/dev/null
      echo '*' # dirty
    else
      echo '#' # all staged
    end
  else
    echo    '' # clean
  end
end

function _remote_hostname
  if test $SSH_CONNECTION
    echo (whoami)@(hostname)
  end
end

function fish_prompt
  set -l cyan (set_color cyan)
  set -l normal (set_color normal)
  set -l cwd (set_color $fish_color_cwd)(prompt_pwd)

  echo -n (_remote_hostname) \
          $cwd $cyan(_git_status_symbol)(_git_branch_name)$normal'> '
end

Fix where it shows extra a space

# name: GitStatus
# Find latest version from: https://github.com/godfat/fish_prompt-gitstatus

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

function _git_status_symbol
  set -l git_status (git status --porcelain ^/dev/null)
  if test -n "$git_status"
    # Is there anyway to preserve newlines so we can reuse $git_status?
    if git status --porcelain ^/dev/null | grep '^.[^ ]' >/dev/null
      echo '*' # dirty
    else
      echo '#' # all staged
    end
  else
    echo    '' # clean
  end
end

function _remote_hostname
  if test $SSH_CONNECTION
    echo (whoami)@(hostname)
  end
end

function fish_prompt
  set -l cyan (set_color cyan)
  set -l normal (set_color normal)

  set -l cwd (set_color $fish_color_cwd)(prompt_pwd)
  set -l git_status (_git_status_symbol)(_git_branch_name)

  if test -n "$git_status"
    set git_status " $git_status"
  end

  echo -n (_remote_hostname) $cwd$cyan$git_status$normal'> '
end


# Set path
set -x PATH $PATH /Users/sahil/Documents/dev/android/adt/sdk/platform-tools /Users/sahil/Documents/dev/android/adt/sdk/tools /usr/local/heroku/bin /usr/local/bin /usr/local/sbin $HOME/bin

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

# Include aliases
. $HOME/.files/aliases

# Set default pager and options for less
# (copied from zsh, makes it scroll faster for some reason)
set -x PAGER less
set -x LESS '-F -g -i -M -R -S -w -X -z-4'

# Set colors
set fish_color_command 89adff
set fish_color_cwd ffffa4
set fish_color_host 8cd6ff
set fish_color_user fdd8aa

set GREP_COLOR '' # use default grep color

Use colors in grep (dunno how it was working previously)

# Set path
set -x PATH $PATH /Users/sahil/Documents/dev/android/adt/sdk/platform-tools /Users/sahil/Documents/dev/android/adt/sdk/tools /usr/local/heroku/bin /usr/local/bin /usr/local/sbin $HOME/bin

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

# Include aliases
. $HOME/.files/aliases

# Set default pager and options for less
# (copied from zsh, makes it scroll faster for some reason)
set -x PAGER less
set -x LESS '-F -g -i -M -R -S -w -X -z-4'

# Set colors for fish prompt
set fish_color_command 89adff
set fish_color_cwd ffffa4
set fish_color_host 8cd6ff
set fish_color_user fdd8aa

# Make grep use color
set -x GREP_OPTIONS '--color=auto'


bind \cg '__ghq_crtl_g'
if bind -M insert >/dev/null ^/dev/null
    bind -M insert \cg '__ghq_crtl_g'
end

Use "2>" to redirect stderr instead of the deprecated "^"

bind \cg '__ghq_crtl_g'
if bind -M insert >/dev/null 2>/dev/null
    bind -M insert \cg '__ghq_crtl_g'
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

Remove unnecessary trailing slash from a PATH item

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


function gscp -d "Create patch for head and scp it"
  git show HEAD -U999999 > /tmp/head.patch
  scp /tmp/patch "$argv":/tmp/head.patch
end


set -l rbenv_root (rbenv root)
set -U fish_user_paths $fish_user_paths $rbenv_root/shims
set -xg RBENV_SHELL fish
command mkdir -p $rbenv_root/{shims,versions}
command rbenv rehash 2>/dev/null

Fix setting of environment variables

set -l rbenv_root (rbenv root)
set -x PATH $rbenv_root/shims $PATH
set -x RBENV_SHELL fish
command mkdir -p $rbenv_root/{shims,versions}
command rbenv rehash 2>/dev/null


Set fish terminal title and tmux window name

function fish_title
  # $argv is always the last command, but fish_title is called before and after
  # the command executes, so this conditional uses just the pwd
  if test $_ = "fish"
    set title (prompt_pwd)
  else
    set title (prompt_pwd) $argv
  end
  test -n "$TMUX"; and tmux rename-window "$title"
  echo $title
end


# 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

# virtualfish
source ~/.virtualfish/virtual.fish
source ~/.virtualfish/projects.fish

Remove debug flag from the default EDITOR

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

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

# virtualfish
source ~/.virtualfish/virtual.fish
source ~/.virtualfish/projects.fish


alias dir="ls -l"

# https://github.com/fish-shell/fish-shell/blob/master/share/functions/__fish_git_prompt.fish
set -g __fish_git_prompt_showupstream "auto"
set -g __fish_git_prompt_showstashstate "1"
set -g __fish_git_prompt_showdirtystate "1"

Switch "dir" from alias to function

function dir
  ls -l $argv
end

# https://github.com/fish-shell/fish-shell/blob/master/share/functions/__fish_git_prompt.fish
set -g __fish_git_prompt_showupstream "auto"
set -g __fish_git_prompt_showstashstate "1"
set -g __fish_git_prompt_showdirtystate "1"


# name: Gianu
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 cyan (set_color cyan)
  set -l yellow (set_color -o yellow)
  set -l red (set_color -o red)
  set -l green (set_color -o green)
  set -l white (set_color -o white)
  set -l normal (set_color normal)

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

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

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

    set git_info "$git_info$normal)"
  end

  echo -n -s $normal '[' $white (whoami) $normal '@' $red (hostname -s) $normal ' ' $cwd ' '  $git_info $normal ']$ '
end

Make stderr redirection compatible with Fish 3.0.

# name: Gianu
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 cyan (set_color cyan)
  set -l yellow (set_color -o yellow)
  set -l red (set_color -o red)
  set -l green (set_color -o green)
  set -l white (set_color -o white)
  set -l normal (set_color normal)

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

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

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

    set git_info "$git_info$normal)"
  end

  echo -n -s $normal '[' $white (whoami) $normal '@' $red (hostname -s) $normal ' ' $cwd ' '  $git_info $normal ']$ '
end


function fish_prompt --description 'Compose fish prompt'

    set -l last_status $status

    set -l status_string ''
    if test $status -ne 0
        set status_string (set_color red --bold) '(' $last_status ') ' (set_color normal)
    end

    set -l virtualenv_string ''
    if set -q VIRTUAL_ENV
        set virtualenv_string ' ' (set_color brown) '(' (basename "$VIRTUAL_ENV") ')' (set_color normal)
    end

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

    set -l pwd_string (prompt_pwd)
    set -l git_string (__fish_git_prompt)
    set -l mode_string (fish_mode_cm)
    set -l user_string (fish_user_cm)

    echo -n -s $status_string $pwd_string $virtualenv_string $git_string ' ' $mode_string ' ' $user_string ' '
end

Reformat none zero exit status

function fish_prompt --description 'Compose fish prompt'

    set -l status_string
    if test $status -ne 0
        set status_string (set_color red) '(!) ' (set_color normal)
    end

    set -l virtualenv_string ''
    if set -q VIRTUAL_ENV
        set virtualenv_string ' ' (set_color brown) '(' (basename "$VIRTUAL_ENV") ')' (set_color normal)
    end

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

    set -l pwd_string (prompt_pwd)
    set -l git_string (__fish_git_prompt)
    set -l mode_string (fish_mode_cm)
    set -l user_string (fish_user_cm)

    echo -n -s $status_string $pwd_string $virtualenv_string $git_string ' ' $mode_string ' ' $user_string ' '
end


Add function to check if a user has MFA enabled

function mfa-enabled --argument user
    trace (status --current-filename) $argv

    if empty "$user"
        usage mfa-enabled '<user>'
        return (false)
    end

    contains $user (users-with-mfa)
    set enabled $status

    if test $enabled -eq 0
        print --tag=mfa-enabled --pass $argv
    else
        print --tag=mfa-enabled --fail $argv
    end

    return $enabled
end


function fish_greeting -d "what's up, fish?"
  set_color $fish_color_autosuggestion[1]
  uname -npsr
  uptime
  set_color normal
end

Fix fish greeting when autosuggest is bold.

function fish_greeting -d "what's up, fish?"
  set_color $fish_color_autosuggestion
  uname -npsr
  uptime
  set_color normal
end


function grs --description="git reset"
  set -l arguments

  set -l cmd "command git diff --cached --name-only"

  if test (count $argv) -gt 0
    set arguments (gish find -c $cmd $argv)

    if test -z $arguments
      set_color red
      echo "No matches found"
      set_color normal
      return 0
    end
  end

  command git reset $arguments
  gs
end


function update-all -d "Update macOS software, Homebrew brews & casks, gems, packages (apms, npms), repos"
  # macOS software updates
  update-os
  # Homebrew brews updates
  update-brews
  # Homebrew cask updates
  update-casks
  # NPM updates
  update-npms
  # Gem updates
  update-gems
  # APM updates
  update-apms
  # Fish completions
  fish_update_completions
end

Update fish configs and functions.

function update-all -d "Update macOS software, Homebrew brews & casks, gems, packages (apms, npms), repos"
  # Ask for the administrator password upfront
  sudo -v
  # macOS software updates
  update-os
  # Homebrew brews updates
  update-brews
  # Homebrew cask updates
  update-casks
  # NPM updates
  update-npms
  # Gem updates
  update-gems
  # APM updates
  update-apms
  # Fish completions
  fish_update_completions
end


#! /usr/bin/env fish

# Load utility functions
set utilsFilePath (dirname (status -f))"/utils.fish"
source "$utilsFilePath"

set newVersion "$argv[1]"

if test -z "$newVersion"
    set scriptName (basename (status -f))

    error "Missing new version value."
    warn "Usage: "
    warn "    ./$scriptName [newVersion]"
    exit 1
end

# Use sed to replace the <VersionPrefix>1.2.3</VersionPrefix> element in the project file
sed -i "" -e "s/<VersionPrefix>.*<\/VersionPrefix>/<VersionPrefix>$newVersion<\/VersionPrefix>/" "ShopifySharp/ShopifySharp.csproj"


# Use python2 if found, otherwise fallback to python.
function _python
  if which python2
    python2 $argv
  else
    python $argv
  end
end

Use `available` to test if python2 is available

# Use python2 if found, otherwise fallback to python.
function _python
  if available python2
    python2 $argv
  else
    python $argv
  end
end


# Display git branch and dirty bit and current time on the right

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_right_prompt
  set -l cyan (set_color cyan)
  set -l red (set_color red)
  set -l normal (set_color normal)
  set -l yellow (set_color cccc00)
  set -l green (set_color 80ff00)
  set -l pink (set_color ff99ff)
  set -l dark_pink (set_color cc99ff)

  # Show git branch and dirty state
  if [ (_git_branch_name) ]
    set -l git_branch (_git_branch_name)

    if [ (_is_git_dirty) ]
      echo -n -s $cyan '‹' $yellow $git_branch $red '*' $cyan '›' $normal
    else
		echo -n -s $cyan '‹' $yellow $git_branch $cyan '›' $normal
    end
  end

  echo -n -s $pink ' [' $dark_pink (date +%H:%M:%S) $pink '] '

end

Make stderr redirection compatible with Fish 3.0.

# Display git branch and dirty bit and current time on the right

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_right_prompt
  set -l cyan (set_color cyan)
  set -l red (set_color red)
  set -l normal (set_color normal)
  set -l yellow (set_color cccc00)
  set -l green (set_color 80ff00)
  set -l pink (set_color ff99ff)
  set -l dark_pink (set_color cc99ff)

  # Show git branch and dirty state
  if [ (_git_branch_name) ]
    set -l git_branch (_git_branch_name)

    if [ (_is_git_dirty) ]
      echo -n -s $cyan '‹' $yellow $git_branch $red '*' $cyan '›' $normal
    else
		echo -n -s $cyan '‹' $yellow $git_branch $cyan '›' $normal
    end
  end

  echo -n -s $pink ' [' $dark_pink (date +%H:%M:%S) $pink '] '

end


function sync
  # Early sudo because it's needed later.
  sudo echo "Updating everything!"

  yay

  cd ~/.config/nvim
  git pull --rebase --autostash
  ./sync.sh
  cd -
end

Use topgrade to update everything

function sync
  # Early sudo because it's needed later.
  sudo echo "Updating everything!"

  topgrade --disable git_repos containers vim

  cd ~/.config/nvim
  git pull --rebase --autostash
  ./sync.sh
  cd -
end


function fish_prompt
   set stat $status
   if test $stat -ne 0
    printf "%s[%s]%s" (set_color red) "$stat" (set_color normal)
   end

   set_color yellow
   printf '%s' (whoami)
   set_color normal
   printf '@'

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

   set_color $fish_color_cwd
   printf '%s' (prompt_pwd)
   set_color normal

   # Line 2
   if test $VIRTUAL_ENV
       printf "(%s) " (set_color blue)(basename $VIRTUAL_ENV)(set_color normal)
   end
   set_color normal
end


# fzf and fzf.fish
if command --query fzf
  # fzf.fish
  fzf_configure_bindings --directory=\cf --git_log=\cl --git_status=\cs
  set --global fzf_fd_opts --follow --hidden --exclude=Documents --exclude=Library --exclude=.git

  # fzf
  set --export FZF_DEFAULT_COMMAND "fd --type f --color always $fzf_fd_opts"
  set --export FZF_DEFAULT_OPTS '--ansi --border --color bg:black,bg+:bright-black,fg:white,fg+:bright-white,gutter:black,prompt:blue,pointer:cyan,marker:green,info:yellow,hl:green,spinner:cyan --cycle --height 40% --marker • --layout reverse --pointer ❯ --preview-window=wrap --prompt "❯ "'
end

Change fzf marker to bold checkmark

# fzf and fzf.fish
if command --query fzf
  # fzf.fish
  fzf_configure_bindings --directory=\cf --git_log=\cl --git_status=\cs
  set --global fzf_fd_opts --follow --hidden --exclude=Documents --exclude=Library --exclude=.git

  # fzf
  set --export FZF_DEFAULT_COMMAND "fd --type f --color always $fzf_fd_opts"
  set --export FZF_DEFAULT_OPTS '--ansi --border --color bg:black,bg+:bright-black,fg:white,fg+:bright-white,gutter:black,prompt:blue,pointer:cyan,marker:green:bold,info:yellow,hl:green,spinner:cyan --cycle --height 40% --marker ✓ --layout reverse --pointer ❯ --preview-window=wrap --prompt "❯ "'
end


function videograb --description="Records video of screen selection in sway"
  # TODO: stop recording when recv SIGINT

  set --local record true
  function record_stop_handler --on-signal INT
    set --global record false
  end

  set TMPDIR (mktemp --directory)
  set CROP_COORDS (slop)
  set FOCUSED_MONITOR (swaymsg --type get_workspaces | \
                       jq --raw-output '.[] | select(.focused == true) | .output')
  set RESOLUTION (swaymsg --type get_outputs | \
                  jq --arg name $FOCUSED_MONITOR '.[] | select(.name == $name) | .rect.width, .rect.height')

  set num 1
  set elapsed 0
  while test "$record" -a (math "$elapsed < 30") -eq 1
    swaygrab --raw | \
    convert -flip -crop "$CROP_COORDS" -depth 8 -size $RESOLUTION[1]x$RESOLUTION[2] RGBA:- (string join "" $TMPDIR "/" $num ".png")
    set num (math $num+1)
    sleep 0.01s
    set elapsed (math $elapsed+0.01)
  end

  ffmpeg -loglevel quiet \
         -pattern_type glob \
         -i '*.png' \
         (string join "" $SCREENSHOT_DIR "/gif" $TIME (date +%Y%m%d_%Hh%Mm%Ss) ".webm")
end

Fix output directory for recording

function videograb --description="Records video of screen selection in sway"
  # TODO: stop recording when recv SIGINT

  set --local record true
  function record_stop_handler --on-signal INT
    set --global record false
  end

  set TMPDIR (mktemp --directory)
  set CROP_COORDS (slop)
  set FOCUSED_MONITOR (swaymsg --type get_workspaces | \
                       jq --raw-output '.[] | select(.focused == true) | .output')
  set RESOLUTION (swaymsg --type get_outputs | \
                  jq --arg name $FOCUSED_MONITOR '.[] | select(.name == $name) | .rect.width, .rect.height')

  set num 1
  set elapsed 0
  while test "$record" -a (math "$elapsed < 30") -eq 1
    swaygrab --raw | \
    convert -flip -crop "$CROP_COORDS" \
            -depth 8 \
            -size $RESOLUTION[1]x$RESOLUTION[2] \
            RGBA:- (string join "" $TMPDIR "/" $num ".png")
    set num (math $num+1)
    set elapsed (math $elapsed+0.01)
    sleep 0.01s
  end

  # TODO: handle int so we can actually get here on demand
  ffmpeg -loglevel quiet \
         -pattern_type glob \
         -i (string join "" $TMPDIR "/" "*.png") \
         (string join "" $SCREENSHOT_DIR "/gif" $TIME (date +%Y%m%d_%Hh%Mm%Ss) ".webm")
end


function fold_string
  set -l fold_replace $argv[1]
  set -l fold_length $argv[2]
  if [ (string length $argv[3]) -le $fold_length ]
    echo $argv[3]
  else
    set -l prefix_length (math $fold_length - (string length $fold_replace))
    set -l prefix (string sub -l $prefix_length $argv[3])
    echo -n $prefix
    echo $fold_replace
  end
end


function sudoer -d 'Check if user is admin'
    # channels are only moderated if they have a file in sudoers.d
    if test -f etc/sudoers.d/$CHAN
        # check global moderator list
        grep -Fxq $NICK etc/sudoers
        # then per chan list
        or grep -Fxq $NICK etc/sudoers.d/$CHAN
        or begin
            echo "Aquaman says he doesn't like you."
            false
        end
    else
        true
    end
end

Make all chans moderated, as acess is cross-chan

function sudoer -d 'Check if user is admin'
    # check global moderator list
    grep -Fxq $NICK etc/sudoers
    # then per chan list
    or grep -Fxq $NICK etc/sudoers.d/$CHAN ^/dev/null
    or begin
        echo "Aquaman says he doesn't like you."
        false
    end
end


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

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

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

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

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

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

Add sbin path and newrelic alias

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

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

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

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

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

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


#!/usr/bin/env fish

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

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

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

Add shortcut to local copy of the RPL

#!/usr/bin/env fish

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

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

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

# Reference
alias rsbook="open /usr/local/share/doc/rust/html/book/index.html"


function gap --description="git add patch"
  set -l arguments

  set -l cmd "command git diff --name-only"

  if test (count $argv) -gt 0
    set arguments (gish find -c $cmd $argv)

    if test -z $arguments
      set_color red
      echo "No matches found"
      set_color normal
      return 0
    end
  end

  command git add -p $arguments
end


function gcm --description="git commit with message"
  if test (count (command git status --porcelain | command grep "^[^ ?]")) -eq 0
    set_color yellow
    echo "Nothing to commit..."
    set_color normal
    return 1
  end

  set -l arguments

  set -l cmd "command git diff --cached --name-only"

  if test (count $ARGV) -gt 0
    set arguments (gish find -c $cmd $ARGV)

    if test -z $arguments
      set_color red
      echo "No matches found"
      set_color normal
      return 0
    end
  end

  command git commit $OPTV $ARGV
  gs
end


append-to-path ~/projects/git-toolbelt

set -gx WORKON_HOME ~/.virtualenvs
set -gx PYTHONPATH ~/.local/bin

append-to-path ~/.local/bin
append-to-path /Applications/Postgres.app/Contents/Versions/9.5/bin

Update postgres bin for 9.6

append-to-path ~/projects/git-toolbelt

set -gx WORKON_HOME ~/.virtualenvs
set -gx PYTHONPATH ~/.local/bin

append-to-path ~/.local/bin
append-to-path /Applications/Postgres.app/Contents/Versions/9.6/bin


import plugins/fish-spec
import plugins/ta

function describe_ta -d "ta: to-done task manager"
    function before_all
    end

    function after_all
    end

    # function it_does_something
    # end

end

spec.run $argv

Add test stub for ta plugin.

import plugins/fish-spec
import plugins/ta

function describe_ta -d "ta: to-done task manager"
    function before_all
    end

    function after_all
    end

    function it_does_something
      ta -h
      expect $status --to-equal 0
    end

end

spec.run $argv


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

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

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

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

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

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

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

Add option to not show untracked files as dirty in git status

# name: RobbyRussel
#
# You can override some default options in your config.fish:
#   set -g theme_disable_untracked_files_dirty yes

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

function _is_git_dirty
  if [ "$theme_disable_untracked_files_dirty" = 'yes' ]
    echo (command git status -s --ignore-submodules=dirty --untracked-files=no ^/dev/null)
  else
    echo (command git status -s --ignore-submodules=dirty ^/dev/null)
  end
end

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

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

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

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

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