#
# __bh_check_bashhub_installation.fish
# Should only be sourced once following installation.
#

# Small function to check our Bashhub installation.
function __bh_check_bashhub_installation --on-event fish_preexec
    set -l ret 0
    set -l config_path "$BH_HOME_DIRECTORY/config"
    if [ -n "$FISH_VERSION" && -n "$__bh_enable_subshells" && "(trap)" -ne *"__bh_preexec_invoke_exec"* ]
        echo "Bashhub's preexec hook is being overriden and is not saving commands. Please resolve what may be holding the DEBUG trap."
        set ret 1
    else if [ -f "$config_path" ]
        echo "Missing Bashhub config file. Please run 'bashhub setup' to generate one."
        set ret 2
    else if not grep -Fq "access_token" "$config_path"
        echo "Missing Bashhub access token. Please run 'bashhub setup' to re-login."
        set ret 3
    else if not grep -Fq "system_name" "$config_path"
        echo "Missing system name. Please run 'bashhub setup' to re-login."
        set ret 4
    else if grep -Fq "save_commands = False" "$config_path"
        echo "Bashhub is currently disabled. Run 'bashhub on' to re-enable."
        set ret 5
    end

    return $ret
end

Call function once manually rather than using `perexec' hook

#
# __bh_check_bashhub_installation.fish
# Should only be sourced once following installation.
#

# Small function to check our Bashhub installation.
function __bh_check_bashhub_installation
    set -l ret 0
    set -l config_path "$BH_HOME_DIRECTORY/config"
    if [ -n "$FISH_VERSION" && -n "$__bh_enable_subshells" && "(trap)" -ne *"__bh_preexec_invoke_exec"* ]
        echo "Bashhub's preexec hook is being overriden and is not saving commands. Please resolve what may be holding the DEBUG trap."
        set ret 1
    else if [ -f "$config_path" ]
        echo "Missing Bashhub config file. Please run 'bashhub setup' to generate one."
        set ret 2
    else if not grep -Fq "access_token" "$config_path"
        echo "Missing Bashhub access token. Please run 'bashhub setup' to re-login."
        set ret 3
    else if not grep -Fq "system_name" "$config_path"
        echo "Missing system name. Please run 'bashhub setup' to re-login."
        set ret 4
    else if grep -Fq "save_commands = False" "$config_path"
        echo "Bashhub is currently disabled. Run 'bashhub on' to re-enable."
        set ret 5
    end

    return $ret
end

__bh_check_bashhub_installation


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

# Theme
set fish_theme bobthefish

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-fish/plugins/*)
# Custom plugins may be added to ~/.oh-my-fish/custom/plugins/
# set fish_plugins autojump bundler
source /usr/local/etc/autojump.fish

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

# Homebrew sbin
set PATH /usr/local/sbin $PATH
# Go binaries
set PATH ~/go/bin /usr/local/opt/go/libexec/bin $PATH
# Scripts
set PATH ~/scripts $PATH

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

Add jon's .setenv-* automatic env variables

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

# Theme
set fish_theme bobthefish

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-fish/plugins/*)
# Custom plugins may be added to ~/.oh-my-fish/custom/plugins/
# set fish_plugins autojump bundler
source /usr/local/etc/autojump.fish

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

# Homebrew sbin
set PATH /usr/local/sbin $PATH
# Go binaries
set PATH ~/go/bin /usr/local/opt/go/libexec/bin $PATH
# Scripts
set PATH ~/scripts $PATH

alias realpath="grealpath"
alias readlink="grealink"

# Automatically set environment variables using .setenv-* files.
# From github.com/jonhoo/configs
set nooverride PATH PWD
function -v PWD onchdir
	set dr $PWD
	while [ "$dr" != "/" ]
		for e in $dr/.setenv-*
			set envn (basename -- $e | sed 's/^\.setenv-//')
			if contains $envn $nooverride
				continue
			end

			if not test -s $e
				# setenv is empty
				# var value is file's dir
				set envv (readlink -e $dr)
			else if test -L $e; and test -d $e
				# setenv is symlink to directory
				# var value is target directory
				set envv (readlink -e $e)
			else
				# setenv is non-empty file
				# var value is file content
				set envv (cat $e)
			end

			if not contains $envn $wasset
				set wasset $wasset $envn
				setenv $envn $envv
			end
		end
		set dr (realpath -eL $dr/..)
	end
end

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


function add-tag-to-vpc --argument-names resource key value
    print-status vpc/add-tag "$argv"
    for argument in resource key value
        if empty "$$argument"
            print-status usage "add-tag-to-vpc <vpc-id> <key> <value>"
            return -1
        end
    end

    and aws ec2 create-tags --resources $resource --tags Key=$key,Value=$value
end

Replace loop over arguments with empty

function add-tag-to-vpc --argument-names resource key value
    print-status vpc/add-tag "$argv"
    if empty "$resource" "$key" "$value"
        print-status usage "add-tag-to-vpc <vpc-id> <key> <value>"
        return -1
    end

    and aws ec2 create-tags --resources $resource --tags Key=$key,Value=$value
end


# Prints a clean list of paths for all installed versions of Xcode
function xclist
    set -l app_dirs /Applications ~/Applications
    set -l xcodes

    for app_dir in $app_dirs
        set xcodes $xcodes $app_dir/Xcode*.app
    end

    for xcode_path in $xcodes
        set -l link_target (readlink $xcode_path)
        if test -n "$link_target"
            # Symlinks are magenta
            echo (set_color magenta)$xcode_path(set_color normal)" -> "$link_target
        else
            # Directories are blue
            echo (set_color blue)$xcode_path(set_color normal)
        end
    end
end

Add -1 option (default when non-interactive) for plain output

# Prints a clean list of paths for all installed versions of Xcode
#
# Options:
# -1 (The numeric digit 'one'.) Force output to be one entry per line. This is the default when output is not to a terminal.
function xclist --argument-names option
    set -l app_dirs /Applications ~/Applications
    set -l xcodes

    for app_dir in $app_dirs
        set xcodes $xcodes $app_dir/Xcode*.app
    end

    # One entry per line, no colors
    if not status is-interactive; or test $option = -1
        echo $xcodes | tr ' ' \n
        return
    end

    # Colorized output showing symlink target
    for xcode_path in $xcodes
        set -l link_target (readlink $xcode_path)
        if test -n "$link_target"
            # Symlinks are magenta
            echo (set_color magenta)$xcode_path(set_color normal)" -> "$link_target
        else
            # Directories are blue
            echo (set_color blue)$xcode_path(set_color normal)
        end
    end
end


function _pure_prompt_git_dirty
    set --local git_dirty_symbol
    set --local git_dirty_color

    set --local is_git_dirty (
        not command git diff-index --ignore-submodules --cached --quiet HEAD -- >/dev/null 2>&1
        or not command git diff --ignore-submodules --no-ext-diff --quiet --exit-code >/dev/null 2>&1
    )
    if test -n "$is_git_dirty"  # untracked or un-commited files
        set git_dirty_symbol "$pure_symbol_git_dirty"
        set git_dirty_color "$pure_color_git_dirty"
    end

    echo "$git_dirty_color$git_dirty_symbol"
end

Fix conditions for prompt git dirty

function _pure_prompt_git_dirty
    set --local git_dirty_symbol
    set --local git_dirty_color

    set --local is_git_dirty (
        # The first checks for staged changes, the second for unstaged ones.
        # We put them in this order because checking staged changes is *fast*.
        not command git diff-index --ignore-submodules --cached --quiet HEAD -- >/dev/null 2>&1
        or not command git diff --ignore-submodules --no-ext-diff --quiet --exit-code >/dev/null 2>&1
        and echo "true"
    )
    if test -n "$is_git_dirty"  # untracked or un-commited files
        set git_dirty_symbol "$pure_symbol_git_dirty"
        set git_dirty_color "$pure_color_git_dirty"
    end

    echo "$git_dirty_color$git_dirty_symbol"
end


# Abbreviations (text expansion)
abbr --add gp 'git push'
abbr --add gst 'git status'  # gs taken by Ghostscript
abbr --add uparch 'sudo pacman --sync --refresh --sysupgrade'
abbr --add upaur 'pikaur --sync --refresh --sysupgrade --devel --needed --noconfirm'
abbr --add send2phone 'kdeconnect-cli --device (kdeconnect-cli --list-available --id-only) --share $PWD/(fzf)'
abbr --add ytdl 'youtube-dl'

Update fish completions after running package manager

# Abbreviations (text expansion)
abbr --add gp 'git push'
abbr --add gst 'git status'  # gs taken by Ghostscript
abbr --add uparch 'sudo pacman --sync --refresh --sysupgrade; and fish_update_completions'
abbr --add upaur 'pikaur --sync --refresh --sysupgrade --devel --needed --noconfirm; and fish_update_completions'
abbr --add send2phone 'kdeconnect-cli --device (kdeconnect-cli --list-available --id-only) --share $PWD/(fzf)'
abbr --add ytdl 'youtube-dl'


Add function to find password requirements

function password-requirements
    set --local policy (mktemp)
    aws iam get-account-password-policy | jq .PasswordPolicy > $policy

    if jq --exit-status .RequireLowercaseCharacters $policy > /dev/null
        echo [:lower:]
    end

    if jq --exit-status .RequireUppercaseCharacters $policy > /dev/null
        echo [:upper:]
    end

    if jq --exit-status .RequireNumbers $policy > /dev/null
        echo [:digit:]
    end

    if jq --exit-status .RequireSymbols $policy > /dev/null
        echo '!@#$%^&()_+-={}|'
    end

    rm -f "$policy"
end


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

Update fish functions to update stuff.

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
end


function _project_dirs
  string replace -r "$REPO_HOME/(.*)/" '$1' $REPO_HOME/*/*/
end

complete -c project -a '(_project_dirs)'

Stop using short option names

function _project_dirs
  string replace -r "$REPO_HOME/(.*)/" '$1' $REPO_HOME/*/*/
end

complete --command project --arguments '(_project_dirs)'


function __fisher_path_update -a path
    pushd $path

    if not git pull --quiet --rebase origin master
        git rebase --abort
        git fetch --quiet origin master
        git reset --quiet --hard FETCH_HEAD
        git clean --quiet -d --force
    end ^ /dev/null

    popd
end

Clear ignored files on cleanup

function __fisher_path_update -a path
    pushd $path

    if not git pull --quiet --rebase origin master
        git rebase --abort
        git fetch --quiet origin master
        git reset --quiet --hard FETCH_HEAD
        git clean --quiet -dx --force
    end ^ /dev/null

    popd
end


function __all_dock_formulars
  dock -l | tail -n +2 | tr '\n' ' '
end

complete -c dock -a (__all_dock_formulars)
complete -c dock -s l -l list -d 'List available formulas'
complete -c dock -s c -l cat -a (__all_dock_formulars) -d 'Display formula details'
complete -c dock -s u -l upgrade -d 'Upgrade list of available formulas'
complete -c dock -s d -l rm -d 'Stop and remove all containers'
complete -c dock -s h -l help -d 'Display help text'
complete -c dock -s v -l version -d 'Display current script version'


set -xg theme_color_scheme zenburn
set -xg theme_nerd_fonts no
set -xg fish_key_bindings fish_vi_key_bindings
set -xg theme_show_exit_status no

set -xg EDITOR nvim
set -xg LC_ALL en_US.UTF-8
set -xg LANG en_US.UTF-8

set -xg VIRTUAL_ENV_DISABLE_PROMPT 1

# don"t show brew git information on brew commands
set -xg HOMEBREW_NO_GITHUB_API 1

set -xg GPG_TTY (tty)
set -xg OPENSSL_LIB_DIR /usr/local/opt/openssl/lib
set -xg OPENSSL_INCLUDE_DIR /usr/local/opt/openssl/include

set -xg HOST_IP 192.168.65.2

set -xg GOPATH ~/go
set -xg PATH $GOPATH/bin $HOME/.yarn/bin $HOME/.config/yarn/global/node_modules/.bin $HOME/.cargo/bin $PATH /usr/local/sbin
set -xg WEECHAT_HOME $XDG_CONFIG_HOME/weechat

eval (direnv hook fish)

source $HOME/.opam/opam-init/init.fish > /dev/null 2> /dev/null or true

if [ -f "$HOME/Downloads/google-cloud-sdk/path.fish.inc" ]; . "$HOME/Downloads/google-cloud-sdk/path.fish.inc"; end

if [ -f "$HOME/.local/profile" ]; source "$HOME/.local/profile"; end

Move GOPATH out of home root and one level inside

set -xg theme_color_scheme zenburn
set -xg theme_nerd_fonts no
set -xg fish_key_bindings fish_vi_key_bindings
set -xg theme_show_exit_status no

set -xg EDITOR nvim
set -xg LC_ALL en_US.UTF-8
set -xg LANG en_US.UTF-8

set -xg VIRTUAL_ENV_DISABLE_PROMPT 1

# don"t show brew git information on brew commands
set -xg HOMEBREW_NO_GITHUB_API 1

set -xg GPG_TTY (tty)
set -xg OPENSSL_LIB_DIR /usr/local/opt/openssl/lib
set -xg OPENSSL_INCLUDE_DIR /usr/local/opt/openssl/include

set -xg HOST_IP 192.168.65.2

set -xg GOPATH ~/src/go
set -xg PATH $GOPATH/bin $HOME/.yarn/bin $HOME/.config/yarn/global/node_modules/.bin $HOME/.cargo/bin $PATH /usr/local/sbin
set -xg WEECHAT_HOME $XDG_CONFIG_HOME/weechat

eval (direnv hook fish)

source $HOME/.opam/opam-init/init.fish > /dev/null 2> /dev/null or true

if [ -f "$HOME/Downloads/google-cloud-sdk/path.fish.inc" ]; . "$HOME/Downloads/google-cloud-sdk/path.fish.inc"; end

if [ -f "$HOME/.local/profile" ]; source "$HOME/.local/profile"; end


#!/usr/bin/env fish

# PATH

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

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

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

# Neovim settings

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

# if test -n "$NVIM_LISTEN_ADDRESS"
  # set -x MANPAGER "/usr/local/bin/nvr -c 'set ft=man' -o -"
  # if test -x /usr/local/bin/page
    # set -x PAGER /usr/local/bin/page
  # end
# end

# Git

set -x REVIEW_BASE main

# Fisher plugins

if not functions -q fisher
  set -q XDG_CONFIG_HOME; or set XDG_CONFIG_HOME ~/.config
  curl https://git.io/fisher --create-dirs -sLo $XDG_CONFIG_HOME/fish/functions/fisher.fish
  fish -c fisher
end
set -g fish_user_paths "/usr/local/opt/curl/bin" $fish_user_paths

Fix enhanced manpager inside neovim

#!/usr/bin/env fish

# PATH

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

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

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

# Neovim settings

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

if test -n "$NVIM_LISTEN_ADDRESS"
  set -x MANPAGER "/usr/local/bin/nvr -c 'Man!' -o -"
end

# Git

set -x REVIEW_BASE main

# Fisher plugins

if not functions -q fisher
  set -q XDG_CONFIG_HOME; or set XDG_CONFIG_HOME ~/.config
  curl https://git.io/fisher --create-dirs -sLo $XDG_CONFIG_HOME/fish/functions/fisher.fish
  fish -c fisher
end
set -g fish_user_paths "/usr/local/opt/curl/bin" $fish_user_paths


#!/usr/bin/env fish

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

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

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

Add neovim pager and control r history search for fish

#!/usr/bin/env fish

# PATH

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

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

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

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

# Keybindings

if test -x /usr/local/bin/fzy
  bind \cr 'set hist_cmd (history | fzy) && eval $hist_cmd'
end


#!/usr/bin/env fish

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

# we get an ugly warning when setting the path if shims does not exist
mkdir -p $asdf_dir/shims

if not contains $asdf_dir/{bin,shims} $PATH
and test -d $asdf/{bin,shims}
  set -gx PATH $asdf_dir/{bin,shims} $PATH
end

Fix issue with Fish shell shim loading script

#!/usr/bin/env fish

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

# we get an ugly warning when setting the path if shims does not exist
mkdir -p $asdf_dir/shims

for x in $asdf_dir/{bin,shims}
  if not contains $x $PATH
  and test -d $x
    set -gx PATH $x $PATH
  end
end


function fish_prompt --description 'Compose fish prompt'

    set -l last_status $status
    set -l prompt_sign (__fish_prompt_sign)

    switch $last_status
        case 0
            set last_status ''
        case '*'
            set last_status (set_color red) $__fish_prompt_sign_error (set_color normal) ' '
    end

    echo -n -s $last_status (prompt_pwd) $prompt_sign ' '
end

Delete temp var for prompt sign

function fish_prompt --description 'Compose fish prompt'

    set -l last_status $status

    switch $last_status
        case 0
            set last_status ''
        case '*'
            set last_status (set_color red) $__fish_prompt_sign_error (set_color normal) ' '
    end

    echo -n -s $last_status (prompt_pwd) (__fish_prompt_sign) ' '
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 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'

Use rbenv's new fish support

# 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
# Needs latest rbenv (> 0.4.0; i.e., can't use Homebrew just yet)
set -x PATH $PATH $HOME/.rbenv/bin
. (rbenv init -|psub)

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


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

    aws iam delete-virtual-mfa-device --serial-number (mfa-serial "$user")
end


function fish_mode_prompt --description 'Displays the current mode'
    if test "$fish_key_bindings" = "fish_vi_key_bindings"
        switch $fish_bind_mode
            case default
                set sign_color $__sk_mode_color_normal
                set sign_char $__sk_mode_string_normal
            case insert
                set sign_color $__sk_mode_color_insert
                set sign_char $__sk_mode_string_insert
            case replace-one
                set sign_color $__sk_mode_color_replace
                set sign_char $__sk_mode_string_replace
            case visual
                set sign_color $__sk_mode_color_visual
                set sign_char $__sk_mode_string_visual
        end
        set_color -b $sign_color
        set_color white
        echo -n -s ' ' $sign_char ' '
        set_color $sign_color -b $__sk_prompt_pwd_bg
        echo -n -s ''
        set_color normal
    end
end

Fix vi mode foreground color

function fish_mode_prompt --description 'Displays the current mode'
    if test "$fish_key_bindings" = "fish_vi_key_bindings"
        switch $fish_bind_mode
            case default
                set sign_color $__sk_mode_color_normal
                set sign_char $__sk_mode_string_normal
            case insert
                set sign_color $__sk_mode_color_insert
                set sign_char $__sk_mode_string_insert
            case replace-one
                set sign_color $__sk_mode_color_replace
                set sign_char $__sk_mode_string_replace
            case visual
                set sign_color $__sk_mode_color_visual
                set sign_char $__sk_mode_string_visual
        end
        set_color -b $sign_color
        set_color brwhite
        echo -n -s ' ' $sign_char ' '
        set_color $sign_color -b $__sk_prompt_pwd_bg
        echo -n -s ''
        set_color normal
    end
end


alias l='ls -lah'

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

alias md='mkdir -p'
alias rd=rmdir

alias mv='mv -i'
alias cp='cp -i'

# neovim
if type -q nvim
  alias vim=nvim
  alias vi=nvim
end

# fasd
if type -q fasd
  alias v='fasd -t -e vim -b viminfo'
end

# No more greetings
if set --query fish_greeting
  set --erase fish_greeting
end

Change the way how fish-sensible remove the greeting message

alias l='ls -lah'

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

alias md='mkdir -p'
alias rd=rmdir

alias mv='mv -i'
alias cp='cp -i'

# neovim
if type -q nvim
  alias vim=nvim
  alias vi=nvim
end

# fasd
if type -q fasd
  alias v='fasd -t -e vim -b viminfo'
end

# No more greetings
if set --query fish_greeting
  set fish_greeting
end


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

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

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

Sort results before piping to comm

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

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

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


function fish_title
  if test $_ = 'fish'
    pwd
  else
    echo $_
  end
end

Use a shell title that's friendlier to Kitty tabs

function fish_title
  if test $_ = 'fish'
    prompt_pwd
  else
    echo (echo $_) (prompt_pwd)
  end
end


##
# @param var_name       Name of the environment variable that holds the color information.
# @param set_color_args Arguments to pass to `set_color` when using this color value.
function ensure_color --description 'Ensures that the given color name is set to the supplied set_color argument array'
    set --local var_name $argv[1]
    set --local set_color_args $argv[2..-1]
    set --local var_value $$var_name

    if [ "$var_value" != "$set_color_args" ]
        set --universal $var_name $set_color_args
    end

    return 0
end

Add a little more documentation

##
# @param var_name       Name of the environment variable that holds the color information.
# @param set_color_args Arguments to pass to `set_color` when using this color value.
#
# @example
#     ensure_color fish_color_user -o cyan
#
function ensure_color --description 'Ensures that the given color name is set to the supplied set_color argument array'
    set --local var_name $argv[1]
    set --local set_color_args $argv[2..-1]
    set --local var_value $$var_name

    if [ "$var_value" != "$set_color_args" ]
        set --universal $var_name $set_color_args
    end

    return 0
end


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


abbr -a -- - 'cd -'
abbr -a axel 'axel -a'
abbr -a b 'brew'
abbr -a c 'nix-shell -p clojure --command "clojure -A:rebel -A:cheshire"'
abbr -a c3 'cal -3'
abbr -a dl 'wget -r -l 1 -np -nd'
abbr -a fn 'find . -iname'

abbr -a g git
abbr -a ga git add
abbr -a gap git add --patch
abbr -a gb git branch
abbr -a gc git commit --verbose
abbr -a gco git checkout
abbr -a gd git diff
abbr -a gdc git diff --color-words
abbr -a gds git diff --staged
abbr -a gf git fetch
abbr -a gl git log --graph --decorate
abbr -a gl1 git log -1
abbr -a gll git log \'@\{u\}..\'
abbr -a glr git log \'..@\{u\}\'
abbr -a gr git remote
abbr -a gs git status -sb

abbr -a l 'ls -lahp'
abbr -a le 'less'
abbr -a lx 'less -X'
abbr -a ns 'nix-shell --command fish -p'
abbr -a np 'nix-shell -p'
abbr -a o 'open .'
abbr -a ql 'qlmanage -p'
abbr -a t 'tmux'
abbr -a ta 'type -a'
abbr -a tsp 'tmux show-buffer | pbcopy'
abbr -a v vim

Change clojure abbreviation to prevent accidental usage

abbr -a -- - 'cd -'
abbr -a axel 'axel -a'
abbr -a b 'brew'
abbr -a c3 'cal -3'
abbr -a dl 'wget -r -l 1 -np -nd'
abbr -a fn 'find . -iname'

abbr -a g git
abbr -a ga git add
abbr -a gap git add --patch
abbr -a gb git branch
abbr -a gc git commit --verbose
abbr -a gco git checkout
abbr -a gd git diff
abbr -a gdc git diff --color-words
abbr -a gds git diff --staged
abbr -a gf git fetch
abbr -a gl git log --graph --decorate
abbr -a gl1 git log -1
abbr -a gll git log \'@\{u\}..\'
abbr -a glr git log \'..@\{u\}\'
abbr -a gr git remote
abbr -a gs git status -sb

abbr -a l 'ls -lahp'
abbr -a le 'less'
abbr -a lx 'less -X'
abbr -a ncl 'nix-shell -p clojure --command "clojure -A:rebel -A:cheshire"'
abbr -a ns 'nix-shell --command fish -p'
abbr -a np 'nix-shell -p'
abbr -a o 'open .'
abbr -a ql 'qlmanage -p'
abbr -a t 'tmux'
abbr -a ta 'type -a'
abbr -a tsp 'tmux show-buffer | pbcopy'
abbr -a v vim


function speed_key_repeat
    # delay until key repeat
    defaults write NSGlobalDomain InitialKeyRepeat -int 12
    # key repeat speed
    defaults write NSGlobalDomain KeyRepeat -int 1
    set_color -o yellow
    echo
    echo You must do logout your mac for taking this effect.
    echo
    set_color normal
end

function reset_key_repeat
    defaults delete NSGlobalDomain KeyRepeat
    defaults delete NSGlobalDomain InitialKeyRepeat
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"

Fix sed usage on macos and linux

#! /usr/bin/env fish

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

set newVersion "$argv[1]"
set projectFile "ShopifySharp/ShopifySharp.csproj"

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

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

function sed
    # Sed behaves differently between macos and linux
    # https://stackoverflow.com/a/57766728
    if test (uname -s) = "Darwin"
        command sed -i "" $argv
    else
        command sed -i $argv
    end
end

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


# From https://github.com/jdxcode/gh

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

function gh -d "manage git repos"
  set git_host github.com
  set -l repo ""

  if [ (count $argv) -eq 1 ]
    set repo $argv[1]
  else if [ (count $argv) -eq 2 ]
    set repo $argv[1]/$argv[2]
  else
    echo "USAGE: gh [user] [repo]"
    return -1
  end

  set -l path $GH_BASE_DIR/$git_host/$repo
  if not test -d $path
    git clone git@$git_host:$repo.git $path
    cd $path; and git branch --set-upstream-to=origin/master master
  end

  cd $path
end

Clone from GitHub via HTTPS

# From https://github.com/jdxcode/gh

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

function gh -d "manage git repos"
  set git_host github.com
  set -l repo ""

  if [ (count $argv) -eq 1 ]
    set repo $argv[1]
  else if [ (count $argv) -eq 2 ]
    set repo $argv[1]/$argv[2]
  else
    echo "USAGE: gh [user] [repo]"
    return -1
  end

  set -l path $GH_BASE_DIR/$git_host/$repo
  if not test -d $path
    git clone https://$git_host/$repo.git $path
    cd $path; and git branch --set-upstream-to=origin/master master
  end

  cd $path
end


set -l IFS \t

shark -h | __fisher_complete shark

complete -xc shark -d "Sparkline generator" -a "\t"

Add custom completions avoiding fisherman specific slang.

complete -xc shark -d "Sparkline generator" -a "\t"
complete -c shark -s n -l line -d "Process each line as a record"
complete -c shark -s f -l field -d "=<format> Set field output format"
complete -c shark -s r -l record -d "=<format> Set record output format"
complete -c shark -s m -l min -d "=<number> Set minimum numeric value"
complete -c shark -s M -l max -d "=<number> Set maximum numeric value"
complete -c shark -s d -l delim -d "=<regex> Use <regex> as number separator"
complete -c shark -l null -d "=<string> Use <string> to display null values"
complete -c shark -s h -l help -d "Show usage help"


function fish_prompt
  if status --is-interactive
    # Colorize the CWD depending on permissions
    switch $USER
      case root
        set -g __paradox_prompt_pwd (set_color $fish_color_cwd_root)
        set -g __paradox_prompt_character (echo -s (set_color red) "!")
      case '*'
        set -g __paradox_prompt_pwd (set_color $fish_color_cwd)
        set -g __paradox_prompt_character (echo -s (set_color normal) "\$")
    end

    function __paradox_pwd
      echo -s "$__paradox_prompt_pwd" (prompt_pwd)
    end

    function __paradox_status
      if test $status -ne 0
        echo -s (set_color $fish_color_status) "[$last_status]"
      end
    end

    echo -n -e -s (__paradox_pwd) (__fish_git_prompt) (__paradox_git_hash) (__paradox_status) (set_color normal) "\n$__paradox_prompt_character "
  end
end

Remove unused status line in prompt

function fish_prompt
  if status --is-interactive
    # Colorize the CWD depending on permissions
    switch $USER
      case root
        set -g __paradox_prompt_pwd (set_color $fish_color_cwd_root)
        set -g __paradox_prompt_character (echo -s (set_color red) "!")
      case '*'
        set -g __paradox_prompt_pwd (set_color $fish_color_cwd)
        set -g __paradox_prompt_character (echo -s (set_color normal) "\$")
    end

    function __paradox_pwd
      echo -s "$__paradox_prompt_pwd" (prompt_pwd)
    end

    echo -n -e -s (__paradox_pwd) (__fish_git_prompt) (__paradox_git_hash) (set_color normal) "\n$__paradox_prompt_character "
  end
end


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

Revert "Add path to magic symlink"

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


type -t gls > /dev/null
switch $status

  case 0
    function ls
      command gls -FBh $argv
    end

    function dir
      command gls -lFBh $argv
    end

  case '*'
    function ls
      command ls -FBh $argv
    end

    function dir
      command ls -lFBh $argv
    end

end

# Remove greeting
set fish_greeting

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

Set a few more environment variables

# -*- sh -*-

set -g GITROOT "git@github.com:ithinkihaveacat"
set -g GREP_OPTIONS "--exclude=.svn --exclude=.git --binary-files=without-match"
set -g TZ "Europe/London"

# Create ls and dir aliases
type -t gls > /dev/null
switch $status

  case 0
    function ls
      command gls -FBh $argv
    end

    function dir
      command gls -lFBh $argv
    end

  case '*'
    function ls
      command ls -FBh $argv
    end

    function dir
      command ls -lFBh $argv
    end

end

# Remove greeting
set fish_greeting

# Configure git prompt
# 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"


# 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-inc -d "Find a string in a file with color always on"
    switch (count $argv)
        case 2
            find $argv[2] -type f -exec grep -Hns --color=always $argv[1] '{}' \;
        case 3
            find $argv[3] -type f -exec grep -Hns --color=always $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


# Turn off greeting on start
set -g -x fish_greeting ''

# Environment Variables
set -x EDITOR nvim
set -x NVIM_TUI_ENABLE_TRUE_COLOR 1
set -x GOPATH "$HOME/gocode"

# Aliases
alias rdp "xfreerdp +compression +clipboard +fonts /home-drive /cert-ignore /size:1400x1050"
alias rsyncg "rsync -a --exclude='.git/' --exclude-from='.gitignore'"

source ~/.config/fish/fish_prompt.fish

# Allow extension via local configuration
if test -f ~/.config/fish/config_local.fish
    source ~/.config/fish/config_local.fish
end

Fix the delete key in fish when using st

# Turn off greeting on start
set -g -x fish_greeting ''

# Environment Variables
set -x EDITOR nvim
set -x NVIM_TUI_ENABLE_TRUE_COLOR 1
set -x GOPATH "$HOME/gocode"

# Aliases
alias rdp "xfreerdp +compression +clipboard +fonts /home-drive /cert-ignore /size:1400x1050"
alias rsyncg "rsync -a --exclude='.git/' --exclude-from='.gitignore'"

# Fix the delete key when using st
# https://github.com/fish-shell/fish-shell/issues/2139#issuecomment-137228149
tput smkx ^/dev/null
function fish_enable_keypad_transmit --on-event fish_postexec
    tput smkx ^/dev/null
end

function fish_disable_keypad_transmit --on-event fish_preexec
    tput rmkx ^/dev/null
end
# end of - Fix the delete key when using st

source ~/.config/fish/fish_prompt.fish

# Allow extension via local configuration
if test -f ~/.config/fish/config_local.fish
    source ~/.config/fish/config_local.fish
end


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

set -U EDITOR mvim
set RUBY_GC_MALLOC_LIMIT 60000000
set RUBY_FREE_MIN 200000

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

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

Add new rtest command and add postgress path

set -x PATH /usr/local/bin $PATH
set -x PATH /usr/local/heroku/bin $PATH
set -x PATH /usr/local/share/npm/bin $PATH
set -x PATH /Applications/Postgres.app/Contents/Versions/9.4/bin $PATH

set -U EDITOR mvim
set RUBY_GC_MALLOC_LIMIT 60000000
set RUBY_FREE_MIN 200000

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

#aliases
alias rake='bundle exec rake'
alias spec='bundle exec spec'
alias rspec='bundle exec rspec'
alias brails='bundle exec rails'
alias clear_drive='rm -rf .fseventsd ._.Trashes .Trashes .Spotlight-V100'
alias rtest='env SPEC=true ruby -Itest'


# For ClojureScript development:

# Need to set this here, as this env.fish file is run before the Java one.
# set -x JAVA_HOME (/usr/libexec/java_home -v 1.8)
set -x JAVA_HOME "/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home"

set -x SPIDERMONKEY_HOME "$HOME/Developer/js-engines/jsshell-mac"
set -x NASHORN_HOME "$JAVA_HOME/bin"
set -x V8_HOME "/usr/local/bin"

Set JAVA_HOME via libexec again

# For ClojureScript development:

# Need to set this here, as this env.fish file is run before the Java one.
set -x JAVA_HOME (/usr/libexec/java_home -v 1.8)
#set -x JAVA_HOME "/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home"

set -x SPIDERMONKEY_HOME "$HOME/Developer/js-engines/jsshell-mac"
set -x NASHORN_HOME "$JAVA_HOME/bin"
set -x V8_HOME "/usr/local/bin"


if not status --is-login
  exit
end

test -f "$HOME/.config/dotfile/init.fish"; and source "$HOME/.config/dotfile/init.fish"
dotfile::load_if_exists "$HOME/.config/env/init.fish"
dotfile::load_if_exists "$HOME/.config/shell/init.fish"
dotfile::load_if_exists "$HOME/.config/tmux/init.fish"

dotfile::load_if_exists "$HOME/.profile"

if not status --is-interactive
  exit
end

fish_vi_key_bindings

dotfile::load_if_exists "$HOME/.config/dotfile/config.local.fish"
dotfile::load_if_exists "$HOME/.config/dotfile/shrc"

Use correct directory for local fish overrides

if not status --is-login
  exit
end

test -f "$HOME/.config/dotfile/init.fish"; and source "$HOME/.config/dotfile/init.fish"
dotfile::load_if_exists "$HOME/.config/env/init.fish"
dotfile::load_if_exists "$HOME/.config/shell/init.fish"
dotfile::load_if_exists "$HOME/.config/tmux/init.fish"

dotfile::load_if_exists "$HOME/.profile"

if not status --is-interactive
  exit
end

fish_vi_key_bindings

dotfile::load_if_exists "$HOME/.config/dotfile/config/fish/config.local.fish"
dotfile::load_if_exists "$HOME/.config/dotfile/shrc"


function find-policies --argument-names type target
  print-status iam/find-policies "$type $target"
  test -d iam/$type-policy/$target
  and find iam/$type-policy/$target -type f -name \*.json | rev | cut -d / -f 1 | rev | cut -d . -f 1
end


function fish_prompt
    set_color yellow
    prompt_pwd | tr -d '\n'
    set_color normal
    git_status
end

Make prompt better for copy/pasting

function fish_prompt
    set_color yellow
    prompt_pwd | tr -d '\n'
    set_color normal
    git_status
    printf "\$ "
end


function account-id
    aws ec2 describe-security-groups --filters Name=vpc-id,Values=(default-vpc) Name=group-name,Values=default | jq --raw-output .SecurityGroups[].OwnerId
end


Add function to delete a user from a group

function delete-from-group --argument group user
    if empty "$group" "$user"
        usage delete-from-group '<group>' '<user>'
        return (false)
    end

    print-status delete-from-group "$argv"

    aws iam remove-user-from-group --group-name "$group" --user-name "$user"
end


function prompt_pwd --description 'Print the current working directory, shortend to fit the prompt'
    set p (echo $PWD | sed -e "s|^$HOME|~|")
    # Provide customization possibilities for local machines.
    if functions -q prompt_pwd_after
        prompt_pwd_after $p
    else
        echo "$p "
    end
end

Improve by using a ZWNJ

function prompt_pwd --description 'Print the current working directory, shortend to fit the prompt'
    set p (echo $PWD | sed -e "s|^$HOME|~|")
    # Provide customization possibilities for local machines.
    if functions -q prompt_pwd_after
        prompt_pwd_after $p
    else
        # u200C is a Zero-Width non-joining character to prevent ligatures.
        printf "$p\u200C"
    end
end


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

# emacs alias
alias e="emacs -nw"

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

function fish_user_key_bindings
    bind \cr peco_select_history
end

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

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

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

Fix gacp function with count command

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

# emacs alias
alias e="emacs -nw"

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

function fish_user_key_bindings
    bind \cr peco_select_history
end

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

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

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


# New Start: A modern Arch workflow built with an emphasis on functionality.
# Copyright (C) 2017-2018 Donovan Glover

function fish_prompt

    # Use a more informative and non-unicode prompt for ttys
    if status --is-login; and test -z "$DISPLAY"
        set_color yellow;   echo -n "$USER@$hostname"
        set_color normal;   echo -n " "
        set_color magenta;  echo -n "($PWD)"
    else
        set pwd (basename $PWD)
        set branch (git branch ^/dev/null | sed -n '/\* /s///p')

        if [ $PWD = "/home/$USER" ]
            set pwd "~"
        end

        set_color magenta;  echo -n "$pwd"

        if [ "$branch" ]
            set_color normal;   echo -n " on "
            set_color yellow;   echo -n "$branch"

            set tag (git describe ^/dev/null | sed 's/-\w*$//')

            if [ "$tag" ]
                set_color normal;   echo -n "/"
                set_color cyan;     echo -n "$tag"
            end
        end

        set_color normal;   echo -n " "
        set_color red;      echo -n "➤"
        set_color green;    echo -n "➤"
        set_color blue;     echo -n "➤"
    end

    set_color normal;   echo -n " "
end

Remove git branch from prompt

# New Start: A modern Arch workflow built with an emphasis on functionality.
# Copyright (C) 2017-2021 Donovan Glover

function fish_prompt

    # Use a more informative and non-unicode prompt for ttys
    if status --is-login; and test -z "$DISPLAY"
        set_color yellow;   echo -n "$USER@$hostname"
        set_color normal;   echo -n " "
        set_color magenta;  echo -n "($PWD)"
    else
        set pwd (basename $PWD)

        if [ $PWD = "/home/$USER" ]
            set pwd "~"
        end

        set_color magenta;  echo -n "$pwd"

        set_color normal;   echo -n " "
        set_color red;      echo -n "➤"
        set_color green;    echo -n "➤"
        set_color blue;     echo -n "➤"
    end

    set_color normal;   echo -n " "
end


function init -a path --on-event init_git-flow
  for prefix in /usr /usr/local /opt/local
    if test -f $prefix/share/fish/completions/git.fish
      source $prefix/share/fish/completions/git.fish
      break
    end
  end

  if not available __fish_git_branches
    echo "Error: git completion not found!" >&2; return 1
  end
end

Replace `available` usage with `type -q`

function init -a path --on-event init_git-flow
  for prefix in /usr /usr/local /opt/local
    if test -f $prefix/share/fish/completions/git.fish
      source $prefix/share/fish/completions/git.fish
      break
    end
  end

  if not type -q __fish_git_branches
    echo "Error: git completion not found!" >&2; return 1
  end
end


## SETTINGS

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

# fish greeting
set -gx fish_greeting ""

## ALIASES

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

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

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

## RBENV

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

Add aliases for node and npm

## SETTINGS

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

# fish greeting
set -gx fish_greeting ""

## ALIASES

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

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

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

## RBENV

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


# Defined in - @ line 1
function gpb --description 'alias gpb git push --set-upstream origin (git branch --show-current)'
	git push --set-upstream origin (git branch --show-current) $argv;
end


function colors -d "This function does nothing other then load all the other color functions (red, blue, green, yellow etc)"

end

function blue -d "The color blue"
    echo "#3498D8"
end

function green -d "The color green"
    echo "#2ECC71"
end

function yellow -d "The color yellow"
    echo "#F1C40F"
end

function red -d "The color red"
    echo "#E74C3C"
end

function purple -d "The color purple"
    echo "#9B59B6"
end

function orange -d "The color orange"
    echo "#E67E22"
end

function cyan -d "The color cyan"
    echo "#1ABC9C"
end

function dark -d "The color dark"
    echo "#34495E"
end

function white -d "The color white"
    echo "#ECF0F1"
end

function offwhite -d "The color offwhite"
    echo "#95A5A6"
end

function offwhite_alt -d "The color offwhite"
    echo "#7F8C8D"
end


function shell::termcolor
  if not string match --quiet "256color" $TERM
    set --export --global TERM $argv[1]
  end
end

function shell::color
  if test -f "$HOME/.config/shell/$argv[1]"
    eval sh "$HOME/.config/shell/$argv[1]"
  end
end

function shell::dircolors
  if not test -f "$HOME/.config/shell/$argv[1]"
    return
  end

  set try_cmds "dircolors" "gdircolors"
  set cmd

  for try_cmd in $try_cmds
    if command --search --quiet $try_cmd
      set cmd $try_cmd
      break
    end
  end

  bass (eval $cmd "$HOME/.config/shell/$argv[1]")
end

function shell::cleanup
  functions --erase shell::termcolor
  functions --erase shell::color
  functions --erase shell::dircolors
  functions --erase shell::cleanup
end

Fix TERM override bug in fish.

function shell::termcolor
  if not string match --quiet "*256color*" $TERM
    set --export --global TERM $argv[1]
  end
end

function shell::color
  if test -f "$HOME/.config/shell/$argv[1]"
    eval sh "$HOME/.config/shell/$argv[1]"
  end
end

function shell::dircolors
  if not test -f "$HOME/.config/shell/$argv[1]"
    return
  end

  set try_cmds "dircolors" "gdircolors"
  set cmd

  for try_cmd in $try_cmds
    if command --search --quiet $try_cmd
      set cmd $try_cmd
      break
    end
  end

  bass (eval $cmd "$HOME/.config/shell/$argv[1]")
end

function shell::cleanup
  functions --erase shell::termcolor
  functions --erase shell::color
  functions --erase shell::dircolors
  functions --erase shell::cleanup
end


# initialize rbenv
if test -d ~/.rbenv/shims
  if test -d ~/.rbenv/bin
    set PATH ~/.rbenv/bin $PATH
  end

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

# initialize nodenv
if test -d ~/.nodenv/shims
  if test -d ~/.nodenv/bin
    set PATH ~/.nodenv/bin $PATH
  end

  status --is-interactive; and source (nodenv init - --no-rehash|psub)
end

# add camp binaries to path
if test -d /home/camp/bin
  set PATH /home/camp/bin $PATH
end

# add locally-installed binaries to path
if test -d ~/bin
  set PATH ~/bin $PATH
end

# configure fzf to use ripgrep if available
if type -q rg
  set -x FZF_DEFAULT_COMMAND 'rg --files'
end

Set vim as default editor

# initialize rbenv
if test -d ~/.rbenv/shims
  if test -d ~/.rbenv/bin
    set PATH ~/.rbenv/bin $PATH
  end

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

# initialize nodenv
if test -d ~/.nodenv/shims
  if test -d ~/.nodenv/bin
    set PATH ~/.nodenv/bin $PATH
  end

  status --is-interactive; and source (nodenv init - --no-rehash|psub)
end

# add camp binaries to path
if test -d /home/camp/bin
  set PATH /home/camp/bin $PATH
end

# add locally-installed binaries to path
if test -d ~/bin
  set PATH ~/bin $PATH
end

# configure fzf to use ripgrep if available
if type -q rg
  set -x FZF_DEFAULT_COMMAND 'rg --files'
end

set -x EDITOR vim
set -x VISUAL $EDITOR


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

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

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

# T(he )tmux session

if status --is-interactive
  # When in a sudo starting tmux is almost always unintended
  and not test "$SUDO_USER"
  if not tmux has -t "default" 2> /dev/null
    tmux new -d -s "default"
  end
  if test -z "$TMUX"
    set default_is_attached (string split ' ' (tmux ls -F '#{session_name} #{session_attached}' 2> /dev/null | grep "default"))[2]
    if test "$default_is_attached" = "0"
      exec tmux attach -t "default"
    end
  end
end

Remove platform dependent ssh-agent setting


# Shortcuts
alias reload! "source ~/.config/fish/config.fish"
alias ... "cd ../.."
alias dl "cd ~/Downloads"
alias dt "cd ~/Desktop"
alias c "cd ~/code"
alias storm="open -a (mdfind -name 'kMDItemFSName==\"*.app\"' -onlyin /Applications/ | grep 'WebStorm.')"
alias pubkey="more ~/.ssh/id_rsa.pub | pbcopy | echo '=> Public key copied to pasteboard.'"

Use modern way of retrieving pubkey

# Shortcuts
alias reload! "source ~/.config/fish/config.fish"
alias ... "cd ../.."
alias dl "cd ~/Downloads"
alias dt "cd ~/Desktop"
alias c "cd ~/code"
alias storm="open -a (mdfind -name 'kMDItemFSName==\"*.app\"' -onlyin /Applications/ | grep 'WebStorm.')"
alias pubkey="pbcopy < ~/.ssh/id_ed25519.pub | echo '=> Public key copied to pasteboard.'"


function dir
  ls -l $argv
end

# Remove greeting
set fish_greeting

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

Add ls and dir functions

type -t gls > /dev/null
switch $status

  case 0
    function ls
      command gls -FBh $argv
    end

    function dir
      command gls -lFBh $argv
    end

  case '*'
    function ls
      command ls -FBh $argv
    end

    function dir
      command ls -lFBh $argv
    end

end

# Remove greeting
set fish_greeting

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


#!/usr/bin/fish

ssh novaember.com "uptime | grep -oE '[0-9.]+, [0-9.]+, [0-9.]+' | cut -d',' -f2 | xargs" > /tmp/vps_load

Fix VPS load disappearing when refreshing

#!/usr/bin/fish

set load (ssh novaember.com "uptime | grep -oE '[0-9.]+, [0-9.]+, [0-9.]+' | cut -d',' -f2 | xargs")
echo "$load" > /tmp/vps_load


set -xp PATH "$DOTFILES/bin" "$HOME/bin" /usr/local/bin /usr/local/sbin

# Maid
set -xp PATH "$HOME/.maid/bin"

# Use GNU coreutils before system coreutils
set -xp PATH /usr/local/opt/coreutils/libexec/gnubin

#
# emacs / doom-emacs
#

set -xp PATH "$HOME/.emacs.d/bin"

#
# Golang
#

set -x GOPATH $HOME/gocode
set -xp PATH /usr/local/opt/go/libexec/bin
set -xp PATH $GOPATH/bin

#
# Haskell
#

set -xp PATH "$HOME/.cabal/bin"

#
# Node
#

# Add local npm bin
set -xp PATH (npm bin)
# Include the dotfiles npm bin for some "global" modules
set -xp PATH $DOTFILES/node_modules/.bin
# Yarn bin
set -xp PATH "$HOME/.yarn/bin" "$HOME/.config/yarn/global/node_modules/.bin"

#
# PHP
#

set -xp PATH "(brew --prefix php)/bin"
set -xp PATH "$HOME/.wp-cli/bin"

#
# Python
#

set -xp PATH /usr/local/opt/python/libexec/bin

#
# Ruby
#

set -xp PATH $HOME/.rbenv/shims

Add global Composer bin to PATH

set -xp PATH "$DOTFILES/bin" "$HOME/bin" /usr/local/bin /usr/local/sbin

# PHP
set -xp PATH "$HOME/.composer/vendor/bin"

# Maid
set -xp PATH "$HOME/.maid/bin"

# Use GNU coreutils before system coreutils
set -xp PATH /usr/local/opt/coreutils/libexec/gnubin

#
# emacs / doom-emacs
#

set -xp PATH "$HOME/.emacs.d/bin"

#
# Golang
#

set -x GOPATH $HOME/gocode
set -xp PATH /usr/local/opt/go/libexec/bin
set -xp PATH $GOPATH/bin

#
# Haskell
#

set -xp PATH "$HOME/.cabal/bin"

#
# Node
#

# Add local npm bin
set -xp PATH (npm bin)
# Include the dotfiles npm bin for some "global" modules
set -xp PATH $DOTFILES/node_modules/.bin
# Yarn bin
set -xp PATH "$HOME/.yarn/bin" "$HOME/.config/yarn/global/node_modules/.bin"

#
# PHP
#

set -xp PATH "(brew --prefix php)/bin"
set -xp PATH "$HOME/.wp-cli/bin"

#
# Python
#

set -xp PATH /usr/local/opt/python/libexec/bin

#
# Ruby
#

set -xp PATH $HOME/.rbenv/shims


# 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

# FZF
set --export FZF_DEFAULT_COMMAND 'fd --color always --exclude "*.enc" --ignore-file .pijulignore --hidden'
set --export FZF_DEFAULT_OPTS '--ansi --info inline --layout reverse --preview-window noborder'
set --export FZF_PREVIEW_COMMAND 'bat {}'

# 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 plain-old Neovim as $EDITOR

set --export EDITOR nvim

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

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

# FZF
set --export FZF_DEFAULT_COMMAND 'fd --color always --exclude "*.enc" --ignore-file .pijulignore --hidden'
set --export FZF_DEFAULT_OPTS '--ansi --info inline --layout reverse --preview-window noborder'
set --export FZF_PREVIEW_COMMAND 'bat {}'

# 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 z -d "jump around"
  set -lx Z_SCRIPT_PATH (dirname (status -f))/../z/z.sh

  # Start a Bash process, source z, run the _z function, and capture the working directory and exit status.
  bash -c '
    source $Z_SCRIPT_PATH
    _z "$@" 2>&1
    Z_STATUS=$?
    echo "$PWD" >&2
    exit $Z_STATUS
  ' bash $argv ^| read -l Z_PWD
  set -l Z_STATUS $status

  # If z changed directories, reflect that in the current process.
  if test $Z_PWD != $PWD
    builtin cd $Z_PWD
  end

  return $Z_STATUS
end

Make stderr redirection compatible with Fish 3.0.

function z -d "jump around"
  set -lx Z_SCRIPT_PATH (dirname (status -f))/../z/z.sh

  # Start a Bash process, source z, run the _z function, and capture the working directory and exit status.
  bash -c '
    source $Z_SCRIPT_PATH
    _z "$@" 2>&1
    Z_STATUS=$?
    echo "$PWD" >&2
    exit $Z_STATUS
  ' bash $argv 2>| read -l Z_PWD
  set -l Z_STATUS $status

  # If z changed directories, reflect that in the current process.
  if test $Z_PWD != $PWD
    builtin cd $Z_PWD
  end

  return $Z_STATUS
end


# Turn off greeting on start
set -g -x fish_greeting ''

# Environment Variables
set -x EDITOR nvim
set -x NVIM_TUI_ENABLE_TRUE_COLOR 1
set -x GOPATH "$HOME/gocode"

# Aliases
alias rdp "xfreerdp +compression +clipboard +fonts /home-drive /cert-ignore /size:1400x1050"

source ~/.config/fish/fish_prompt.fish

# Allow extension via local configuration
if test -f ~/.config/fish/config_local.fish
    source ~/.config/fish/config_local.fish
end

Add alias to sync a git project

# Turn off greeting on start
set -g -x fish_greeting ''

# Environment Variables
set -x EDITOR nvim
set -x NVIM_TUI_ENABLE_TRUE_COLOR 1
set -x GOPATH "$HOME/gocode"

# Aliases
alias rdp "xfreerdp +compression +clipboard +fonts /home-drive /cert-ignore /size:1400x1050"
alias rsyncg "rsync -a --exclude='.git/' --exclude-from='.gitignore'"

source ~/.config/fish/fish_prompt.fish

# Allow extension via local configuration
if test -f ~/.config/fish/config_local.fish
    source ~/.config/fish/config_local.fish
end


function __fisher_path_make -a path
    if test ! -s $path/Makefile -o ! -s $path/makefile
        return
    end

    pushd $path

    set -e argv[1]

    if not make $argv
        popd
        return 1
    end

    popd
end

Fix bug introduced in 83b84b causing make to not get called.

function __fisher_path_make -a path
    if test ! -s $path/Makefile -a ! -s $path/makefile
        return
    end

    pushd $path

    set -e argv[1]

    if not make $argv
        popd
        return 1
    end

    popd
end


#
# Loads the Node Version Manager
#

# Return if requirements are not found.
if not type -q node
  exit
end

# Load package manager installed NVM into the shell session.
if type -q brew; and test -f (brew --prefix nvm)/nvm.sh

  mkdir -p "$HOME/.nvm"
  and set -x NVM_DIR "$HOME/.nvm"

  function nvm
    bass source (brew --prefix nvm)/nvm.sh --no-use ';' nvm $argv
  end
end

Change node setup script requirements

#
# Loads the Node Version Manager
#

# Return if requirements are not found.
if not type -q node; and not brew list | grep -q "nvm"
  exit
end

# Load package manager installed NVM into the shell session.
if type -q brew; and test -f (brew --prefix nvm)/nvm.sh

  mkdir -p "$HOME/.nvm"
  and set -x NVM_DIR "$HOME/.nvm"

  function nvm
    bass source (brew --prefix nvm)/nvm.sh --no-use ';' nvm $argv
  end
end


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

Remove date from right prompt


function context
  echo " $argv"
end

function it
  echo -n "  $argv..."
end

function pass
  set_color green
  echo PASS
  set_color normal
end

function fail
  set_color red
  echo FAIL
  set_color normal
end

function stub
  set -l out $argv
  set -l cmd $argv[1]
  set -e out[1]

  eval "function $cmd; echo $out; end"
end

set -l test_path (pwd)

set -e fry_auto_switch
set -xg fry_path $test_path/../share/fry
set -xg fry_rubies $test_path/dummy-rubies

. $fry_path/fry.fish

Use $PWD instead of (pwd)

function context
  echo " $argv"
end

function it
  echo -n "  $argv..."
end

function pass
  set_color green
  echo PASS
  set_color normal
end

function fail
  set_color red
  echo FAIL
  set_color normal
end

function stub
  set -l out $argv
  set -l cmd $argv[1]
  set -e out[1]

  eval "function $cmd; echo $out; end"
end

set -e fry_auto_switch
set -xg fry_path $PWD/../share/fry
set -xg fry_rubies $PWD/dummy-rubies

. $fry_path/fry.fish


set source_dir $argv[1]

if not contains $source_dir $fish_function_path
  set --universal fish_function_path $fish_function_path $source_dir
  printf "+ %s\n" $source_dir
else
  printf "- %s (already installed)\n" $source_dir
end

Add new directories to the top of the list

set source_dir $argv[1]

if not contains $source_dir $fish_function_path
  set --universal fish_function_path $source_dir $fish_function_path
  printf "+ %s\n" $source_dir
else
  printf "- %s (already installed)\n" $source_dir
end


function print
    trace (status --current-filename) $argv

    for arg in $argv
        if echo $arg | grep -qE '^-+'
            set opts $opts (echo $arg | sed -E 's/^-+//')
        else
            set args $args $arg
        end
    end

    set color normal

    for opt in $opts
        switch $opt
            case p pass success
                set color green
                set state success
            case f fail failure
                set color red
                set state failure
            case w warn warning
                set color yellow
                set state warning
            case b bold
                set color_flags '-o'
            case 't=*' 'tag=*'
                set tag (echo $opt | awk -F = '{ print $2 }')
            case '*'
                set color cyan
        end
    end

    if test -z "$tag"
        set tag $state
    end

    if test -z "$tag"
        echo "$args" >& 2
    else
        printf "[%s] $args\n" (set_color $color_flags $color)$tag(set_color normal) >& 2
    end
end

Print shoud return non-zero on failure

function print
    trace (status --current-filename) $argv

    for arg in $argv
        if echo $arg | grep -qE '^-+'
            set opts $opts (echo $arg | sed -E 's/^-+//')
        else
            set args $args $arg
        end
    end

    set color normal

    for opt in $opts
        switch $opt
            case p pass success
                set color green
                set state success
            case f fail failure
                set color red
                set state failure
            case w warn warning
                set color yellow
                set state warning
            case b bold
                set color_flags '-o'
            case 't=*' 'tag=*'
                set tag (echo $opt | awk -F = '{ print $2 }')
            case '*'
                set color cyan
        end
    end

    if test -z "$tag"
        set tag $state
    end

    if test -z "$tag"
        echo "$args" >& 2
    else
        printf "[%s] $args\n" (set_color $color_flags $color)$tag(set_color normal) >& 2
    end

    test "$state" != failure
end


if not status --is-interactive
    exit
end

# Ensure directories exist
if not test -d "$XDG_CONFIG_HOME"
    mkdir -p "$XDG_CONFIG_HOME"
end
if not test -d "$XDG_DATA_HOME"
    mkdir -p "$XDG_DATA_HOME"
end

# colours
set -gx fish_color_autosuggestion "brblack"
set -gx fish_color_command "purple"
set -gx fish_color_comment "yellow"
set -gx fish_color_end "purple"
set -gx fish_color_error "red"
set -gx fish_color_param "blue"
set -gx fish_color_quote "green"
set -gx fish_color_redirection "cyan"

# autojump
complete -x -c j -a '(autojump --complete (commandline -t))'

# gpg
if command -sq gpgconf
    set -gx GPG_TTY (tty)
    set -gx SSH_AUTH_SOCK (gpgconf --list-dirs agent-ssh-socket)
    gpgconf --launch gpg-agent
end

switch (uname)
    case Linux
        set -gx RUST_SRC_PATH "$RUSTUP_HOME/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src"
        set -gx JAVA_HOME "/opt/java/jdk"
        append_to_path "$JAVA_HOME/bin"
    case Darwin
        set -gx RUST_SRC_PATH "$RUSTUP_HOME/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src"
        append_to_path "$HOME/Library/Python/3.7/bin"
end

Remove unused mkdir from config

if not status --is-interactive
    exit
end

# colours
set -gx fish_color_autosuggestion brblack
set -gx fish_color_command purple
set -gx fish_color_comment yellow
set -gx fish_color_end purple
set -gx fish_color_error red
set -gx fish_color_param blue
set -gx fish_color_quote green
set -gx fish_color_redirection cyan

# autojump
complete -x -c j -a '(autojump --complete (commandline -t))'

# gpg
if command -sq gpgconf
    set -gx GPG_TTY (tty)
    set -gx SSH_AUTH_SOCK (gpgconf --list-dirs agent-ssh-socket)
    gpgconf --launch gpg-agent
end

switch (uname)
    case Linux
        set -gx RUST_SRC_PATH "$RUSTUP_HOME/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src"
        set -gx JAVA_HOME "/opt/java/jdk"
        append_to_path "$JAVA_HOME/bin"
    case Darwin
        set -gx RUST_SRC_PATH "$RUSTUP_HOME/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src"
        append_to_path "$HOME/Library/Python/3.7/bin"
end


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

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

  echo -n ' in '

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

  __terlar_git_prompt
  echo

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

  echo -n '∫ '
  set_color normal
end

Use tilde for home directory in fish prompt

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

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

  echo -n ' in '

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

  __terlar_git_prompt
  echo

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

  echo -n '∫ '
  set_color normal
end


set -q FZF_LEGACY_KEYBINDINGS
or set -l FZF_LEGACY_KEYBINDINGS 1

if test "$FZF_LEGACY_KEYBINDINGS" -eq 1
    bind \ct '__fzf_find_file'
    bind \cr '__fzf_reverse_isearch'
    bind \cx '__fzf_find_and_execute'
    bind \ec '__fzf_cd'
    bind \eC '__fzf_cd_with_hidden'

    if bind -M insert >/dev/null ^/dev/null
        bind -M insert \ct '__fzf_find_file'
        bind -M insert \cr '__fzf_reverse_isearch'
        bind -M insert \cx '__fzf_find_and_execute'
        bind -M insert \ec '__fzf_cd'
        bind -M insert \eC '__fzf_cd_with_hidden'
    end
else
    bind \cf '__fzf_find_file'
    bind \cr '__fzf_reverse_isearch'
    bind \ex '__fzf_find_and_execute'
    bind \ed '__fzf_cd'
    bind \eD '__fzf_cd_with_hidden'

    if bind -M insert >/dev/null ^/dev/null
        bind -M insert \cf '__fzf_find_file'
        bind -M insert \cr '__fzf_reverse_isearch'
        bind -M insert \ex '__fzf_find_and_execute'
        bind -M insert \ed '__fzf_cd'
        bind -M insert \eD '__fzf_cd_with_hidden'
    end
end

Remove __fzf_cd bind conflict with forward-delete

set -q FZF_LEGACY_KEYBINDINGS
or set -l FZF_LEGACY_KEYBINDINGS 1

if test "$FZF_LEGACY_KEYBINDINGS" -eq 1
    bind \ct '__fzf_find_file'
    bind \cr '__fzf_reverse_isearch'
    bind \cx '__fzf_find_and_execute'
    bind \ec '__fzf_cd'
    bind \eC '__fzf_cd_with_hidden'

    if bind -M insert >/dev/null ^/dev/null
        bind -M insert \ct '__fzf_find_file'
        bind -M insert \cr '__fzf_reverse_isearch'
        bind -M insert \cx '__fzf_find_and_execute'
        bind -M insert \ec '__fzf_cd'
        bind -M insert \eC '__fzf_cd_with_hidden'
    end
else
    bind \cf '__fzf_find_file'
    bind \cr '__fzf_reverse_isearch'
    bind \ex '__fzf_find_and_execute'
    bind \eo '__fzf_cd'
    bind \eO '__fzf_cd_with_hidden'

    if bind -M insert >/dev/null ^/dev/null
        bind -M insert \cf '__fzf_find_file'
        bind -M insert \cr '__fzf_reverse_isearch'
        bind -M insert \ex '__fzf_find_and_execute'
        bind -M insert \eo '__fzf_cd'
        bind -M insert \eO '__fzf_cd_with_hidden'
    end
end


function maintenance
  echo "Failed systemd services..."
  sudo systemctl --failed

  echo "Errors in logfiles..."
  sudo journalctl -p 3 -xb --no-pager

  echo "Removing orphan packages..."
  sudo pacman -Rns (pacman -Qtdq)

  echo "Clear pacman cache..."
  sudo paccache -r
  sudo paccache -ruk0
end

Cut down the journal error lines

function maintenance
  echo "Failed systemd services..."
  sudo systemctl --failed

  echo "Recent errors in logfiles (journalctl -p 3 -xb)..."
  sudo journalctl -p 3 -xb --no-pager | tail -15

  echo "Removing orphan packages..."
  sudo pacman -Rns (pacman -Qtdq)

  echo "Clear pacman cache..."
  sudo paccache -r
  sudo paccache -ruk0
end


set -x TERM screen-256color
set -x EDITOR nano

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

alias p project

Set fish PATH to include NPM binaries

set -x TERM screen-256color
set -x EDITOR nano

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

set PATH /usr/local/share/npm/bin $PATH

alias p project


function __fasd_run -e fish_preexec -d "fasd takes record of the directories changed into"
    command fasd --proc (command fasd --sanitize "$argv") > "/dev/null" 2>&1 &
  end

Add argument separation for fasd preexec event

function __fasd_run -e fish_preexec -d "fasd takes record of the directories changed into"
    command fasd --proc (command fasd --sanitize "$argv" | tr -s ' ' \n) > "/dev/null" 2>&1 &
  end


function init --on-event init_gem
  if test -n "$GEM_ROOT"
    set -gx GEM_HOME $GEM_ROOT
    if not contains $GEM_ROOT/bin $PATH
      set -x PATH $GEM_ROOT/bin $PATH
    end
  end
end

Initialize immediately, rather than waiting for an event.


function __fish_prompt_timing
    if set -q CMD_DURATION
        set -l seconds ''
        set -l minutes ''
        set -l hours ''
        set -l days ''
        set -l cmd_duration (math $CMD_DURATION/1000)
        if test $cmd_duration -gt 0
            set seconds (math $cmd_duration%68400%3600%60)'s'
            if test $cmd_duration -ge 60
                set minutes (math $cmd_duration%68400%3600/60)'m '
                if test $cmd_duration -ge 3600
                    set hours (math $cmd_duration%68400/3600)'h '
                    if test $cmd_duration -ge 68400
                        set days (math $cmd_duration/68400)'d '
                    end
                end
            end
            echo -n -s '(' $days $hours $minutes $seconds ')'
        end
    end
end

Remove whitespace from timing display

function __fish_prompt_timing
    if set -q CMD_DURATION
        set -l seconds ''
        set -l minutes ''
        set -l hours ''
        set -l days ''
        set -l cmd_duration (math $CMD_DURATION/1000)
        if test $cmd_duration -gt 0
            set seconds (math $cmd_duration%68400%3600%60)'s'
            if test $cmd_duration -ge 60
                set minutes (math $cmd_duration%68400%3600/60)'m'
                if test $cmd_duration -ge 3600
                    set hours (math $cmd_duration%68400/3600)'h'
                    if test $cmd_duration -ge 68400
                        set days (math $cmd_duration/68400)'d'
                    end
                end
            end
            echo -n -s '(' $days $hours $minutes $seconds ')'
        end
    end
end


# Set environment variables.
set -x GOPATH           "$XDG_DATA_HOME/go"
set -x GOROOT           "/usr/lib/go"
set -x EDITOR           "nvim"
set -x BROWSER          "firefox"
set -x STEAM_RUNTIME    1

# Japanese keyboard.
set -x XMODIFIERS       @im=fcitx
set -x GTK_IM_MODULE    fcitx
set -x QT_IM_MODULE     fcitx

# Set locale.
set -x LC_ALL "en_US.UTF-8"
set -x LC_CTYPE "en_US.UTF-8"

# Remove greeting.
set fish_greeting ""

Use nvim as default MANPAGER

# Set environment variables.
set -x GOPATH           "$XDG_DATA_HOME/go"
set -x GOROOT           "/usr/lib/go"
set -x EDITOR           "nvim"
set -x BROWSER          "firefox"
set -x STEAM_RUNTIME    1
set -x MANPAGER			'nvim +Man!'

# Japanese keyboard.
set -x XMODIFIERS       @im=fcitx
set -x GTK_IM_MODULE    fcitx
set -x QT_IM_MODULE     fcitx

# Set locale.
set -x LC_ALL "en_US.UTF-8"
set -x LC_CTYPE "en_US.UTF-8"

# Remove greeting.
set fish_greeting ""


function fonts.install -a name

  if not contains $name (__fonts.repo.list)
    echo "Font $name not available for installing"
    return 1
  end

  if set tmpdir (mktemp -d "/tmp/font-$name.XXXXXX" ^&-)
    if wget -P $tmpdir -q --show-progress -- (__fonts.repo.urls "$name")
      echo 'Fonts downloaded with success'
    else
      echo 'Failed downloading font file'
      return 1
    end

    basename $tmpdir/* > $FONTS_CONFIG/$name

    mkdir -p $FONTS_PATH

    if not mv $tmpdir/* $FONTS_PATH
      #rm -rf $FONTS_CONFIG/$name
      echo 'Error installing font files'
    end

    rm -rf $tmpdir
  end

end

Remove font config file on error

function fonts.install -a name

  if not contains $name (__fonts.repo.list)
    echo "Font $name not available for installing"
    return 1
  end

  if set tmpdir (mktemp -d "/tmp/font-$name.XXXXXX" ^&-)
    if wget -P $tmpdir -q --show-progress -- (__fonts.repo.urls "$name")
      echo 'Fonts downloaded with success'
    else
      echo 'Failed downloading font file'
      return 1
    end

    basename $tmpdir/* > $FONTS_CONFIG/$name

    mkdir -p $FONTS_PATH

    if not mv $tmpdir/* $FONTS_PATH
      rm -rf $FONTS_CONFIG/$name
      echo 'Error installing font files'
    end

    rm -rf $tmpdir
  end

end


function toggle-screen
  set -l IN "eDP1"
  set -l EXT "DP1"

  if xrandr | grep "$EXT disconnected"
    xrandr --output $IN --auto --output $EXT --off
  else
    xrandr --output $IN --auto --primary --output $EXT --auto --above $IN
  end
end

Make big screen primary if plugged in

function toggle-screen
  set -l IN "eDP1"
  set -l EXT "DP1"

  if xrandr | grep "$EXT disconnected"
    xrandr --output $IN --primary --auto --output $EXT --off
  else
    xrandr --output $IN --auto --output $EXT --primary --auto --above $IN
  end
end


test "description"
	-n "expression"
end

Add tests for the default colorscheme

set -l old_fish_color_end $fish_color_end
set -l old_fish_color_match $fish_color_match
set -l old_fish_color_escape $fish_color_escape
set -l old_fish_color_selection $fish_color_selection

vimcolor default >/dev/null ^/dev/null

test "fish_color_end"
    "$old_fish_color_end" = "$fish_color_end"
end

test "fish_color_match"
    "$old_fish_color_match" = "$fish_color_match"
end

test "fish_color_escape"
    "$old_fish_color_escape" = "$fish_color_escape"
end

test "fish_color_selection"
    "$old_fish_color_selection" = "$fish_color_selection"
end

test "fish_color_command"
    "ffff60 --bold" = "$fish_color_command"
end

test "fish_color_quote"
    "ffa0a0" = "$fish_color_quote"
end

test "fish_color_redirection"
    "Cyan" = "$fish_color_redirection"
end

test "fish_color_error"
    "White --background=Red" = "$fish_color_error"
end

test "fish_color_param"
    "40ffff" = "$fish_color_param"
end

test "fish_color_comment"
    "80a0ff" = "$fish_color_comment"
end

test "fish_color_search_match"
    "Black --background=Yellow" = "$fish_color_search_match"
end

test "fish_color_operator"
    "ffff60 --bold" = "$fish_color_operator"
end

test "fish_color_autosuggestion"
    "80a0ff" = "$fish_color_autosuggestion"
end

test "fish_color_valid_path"
    "80a0ff --underline" = "$fish_color_valid_path"
end

test "fish_color_history_current"
    "Cyan" = "$fish_color_history_current"
end


fish_vi_key_bindings

for word in "$HOME/"{bin,.local/bin,go/bin,node_modules/.bin}
    if not contains $word $PATH
        set PATH $word $PATH
    end
end

set -x GOPATH "$HOME/go"

set fish_complete_path "$HOME/git/github.fish-pip-completion" $fish_complete_path

switch (uname)
    case Linux
        source /usr/share/autojump/autojump.fish
    case Darwin
        source /usr/local/share/autojump/autojump.fish
        for word in {"$HOME/Library/Python/3.5/bin",/usr/local/sbin}
            if not contains $word $PATH
                set PATH $word $PATH
            end
        end
end
source (pew shell_config)

Add ruby user gem bin

fish_vi_key_bindings

for word in "$HOME/"{bin,.local/bin,go/bin,node_modules/.bin,.gem/ruby/*/bin}
    if not contains $word $PATH
        set PATH $word $PATH
    end
end

set -x GOPATH "$HOME/go"

set fish_complete_path "$HOME/git/github.fish-pip-completion" $fish_complete_path

switch (uname)
    case Linux
        source /usr/share/autojump/autojump.fish
    case Darwin
        source /usr/local/share/autojump/autojump.fish
        for word in {"$HOME/Library/Python/3.5/bin",/usr/local/sbin}
            if not contains $word $PATH
                set PATH $word $PATH
            end
        end
end
source (pew shell_config)


function ip
  set wan (curl -s http://ipecho.net/plain)
  set lan (ipconfig getifaddr en0)

  printf '%sLAN : %s%s%s\n' (set_color red) (set_color cyan) $lan (set_color normal)
  printf '%sWAN : %s%s%s\n' (set_color red) (set_color green) $wan (set_color normal)
end


function osx-update --description "Update Homebrew, vim plugins, tmux plugins, rvm, npm, OSX"
  # homebrew
  /usr/local/dotfiles/brew.sh

  # Oh my fish! update
  omf update

  # vim plugins
  vim +PluginClean +qall
  vim +PluginUpdate +qall

  # tmux plugin manager
  ~/.tmux/plugins/tpm/bin/clean_plugins
  ~/.tmux/plugins/tpm/bin/update_plugins all

  # rvm
  rvm get stable

  # node packages
  npm update -g --cache-min 60

  # OSX update
  reattach-to-user-namespace mas upgrade
  sudo softwareupdate -i -a
  echo "To reboot: sudo shutdown -r now"
end

Install golang binaries for vim-go

function osx-update --description "Update Homebrew, vim plugins, tmux plugins, rvm, npm, OSX"
  # homebrew
  /usr/local/dotfiles/brew.sh

  # Oh my fish! update
  omf update

  # vim plugins
  vim +PluginClean +qall
  vim +PluginUpdate +qall
  vim +GoInstallBinaries +qall

  # tmux plugin manager
  ~/.tmux/plugins/tpm/bin/clean_plugins
  ~/.tmux/plugins/tpm/bin/update_plugins all

  # rvm
  rvm get stable

  # node packages
  npm update -g --cache-min 60

  # OSX update
  reattach-to-user-namespace mas upgrade
  sudo softwareupdate -i -a
  echo "To reboot: sudo shutdown -r now"
end


# Always installs bindings for insert and default mode for simplicity and b/c it has almost no side-effect
# https://gitter.im/fish-shell/fish-shell?at=60a55915ee77a74d685fa6b1
function fzf_configure_bindings --description "Installs the default key bindings for fzf.fish with user overrides passed as options."
    # no need to install bindings if not in interactive mode or running tests
    status is-interactive || test "$CI" = true; or return

    set options_spec h/help 'directory=?' 'git_log=?' 'git_status=?' 'history=?' 'variables=?'
    argparse --max-args=0 --ignore-unknown $options_spec -- $argv 2>/dev/null
    if test $status -ne 0
        echo "Invalid option or a positional argument was provided." 1>&2
        _fzf_configure_bindings_help
        return 22
    else if set --query _flag_help
        _fzf_configure_bindings_help
        return
    else
        # Initialize with default key sequences and then override or disable them based on flags
        # index 1 = directory, 2 = git_log, 3 = git_status, 4 = history, 5 = variables
        set key_sequences \e\cf \e\cl \e\cs \cr \cv # \c = control, \e = escape
        set --query _flag_directory && set key_sequences[1] "$_flag_directory"
        set --query _flag_git_log && set key_sequences[2] "$_flag_git_log"
        set --query _flag_git_status && set key_sequences[3] "$_flag_git_status"
        set --query _flag_history && set key_sequences[4] "$_flag_history"
        set --query _flag_variables && set key_sequences[5] "$_flag_variables"

        # If fzf bindings already exists, uninstall it first for a clean slate
        if functions --query _fzf_uninstall_bindings
            _fzf_uninstall_bindings
        end

        for mode in default insert
            test -n $key_sequences[1] && bind --mode $mode $key_sequences[1] _fzf_search_directory
            test -n $key_sequences[2] && bind --mode $mode $key_sequences[2] _fzf_search_git_log
            test -n $key_sequences[3] && bind --mode $mode $key_sequences[3] _fzf_search_git_status
            test -n $key_sequences[4] && bind --mode $mode $key_sequences[4] _fzf_search_history
            test -n $key_sequences[5] && bind --mode $mode $key_sequences[5] "$_fzf_search_vars_command"
        end

        function _fzf_uninstall_bindings --inherit-variable key_sequences
            bind --erase -- $key_sequences
            bind --erase --mode insert -- $key_sequences
        end
    end
end


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

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

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

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

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

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

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

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

Check if chruby is installed befoure sourcing

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

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

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

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

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

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

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

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


# Set fish_custom to the path where your custom config files
# and plugins exist, or use the default custom instead.
if not set -q fish_custom
  set -g fish_custom $fish_path/custom
end

# Extract user defined functions from path and prepend later to
# avoid collisions with oh-my-fish internal functions and allow
# users to override/customize plugins, themes, etc.
set user_function_path $fish_function_path[1]
set -e fish_function_path[1]

# Add functions defined in oh-my-fish/functions to the path.
if not contains $fish_path/functions/ $fish_function_path
  set fish_function_path $fish_path/functions/ $fish_function_path
end

# Add imported plugins, completions and themes. Customize imported
# commands via the $fish_path/custom directory, for example create
# a directory under $fish_path/custom/themes with the same name as
# the theme and override any functions/variables there. Rinse and
# repeat for plugins.
import plugins/$fish_plugins themes/$fish_theme

# Source all files inside custom directory.
for load in $fish_custom/*.load
  . $load
end

# Prepend extracted user functions so they have the highest priority.
set fish_function_path $user_function_path $fish_function_path

Make sure to exit with 0 of 1 when reloading the framework

# Set fish_custom to the path where your custom config files
# and plugins exist, or use the default custom instead.
if not set -q fish_custom
  set -g fish_custom $fish_path/custom
end

# Extract user defined functions from path and prepend later to
# avoid collisions with oh-my-fish internal functions and allow
# users to override/customize plugins, themes, etc.
set user_function_path $fish_function_path[1]
set -e fish_function_path[1]

# Add functions defined in oh-my-fish/functions to the path.
if not contains $fish_path/functions/ $fish_function_path
  set fish_function_path $fish_path/functions/ $fish_function_path
end

# Add imported plugins, completions and themes. Customize imported
# commands via the $fish_path/custom directory, for example create
# a directory under $fish_path/custom/themes with the same name as
# the theme and override any functions/variables there. Rinse and
# repeat for plugins.
import plugins/$fish_plugins themes/$fish_theme

# Source all files inside custom directory.
for load in $fish_custom/*.load
  . $load
end

# Prepend extracted user functions so they have the highest priority.
set fish_function_path $user_function_path $fish_function_path

# Make sure to exit with $status of 1 when reloading the framework.
or true


abbr -a g 'git'
abbr -a gd 'git diff'
abbr -a gco 'git checkout'
abbr -a vv 'git branches -vv'

abbr -a chex 'chmod +x'
abbr -a md 'mkdir -p'
abbr -a rf 'rm -rfIv'
abbr -a rl 'source ~/.config/fish/config.fish'
abbr -a s 'ls'
abbr -a cinnamon-restart='cinnamon –replace -d :0.0> /dev/null 2>&1 &'
abbr -a unset 'set --erase'

Add abbr for nvim in fish

# git
abbr -a g 'git'
abbr -a gd 'git diff'
abbr -a gco 'git checkout'
abbr -a vv 'git branches -vv'

abbr -a chex 'chmod +x'
abbr -a md 'mkdir -p'
abbr -a n 'nvim'
abbr -a rf 'rm -rfv'
abbr -a rl 'source ~/.config/fish/config.fish'
abbr -a s 'ls'
abbr -a cinnamon-restart='cinnamon –replace -d :0.0> /dev/null 2>&1 &'
abbr -a unset 'set --erase'


abbr -a g 'git'
abbr -a gco 'git checkout'
abbr -a rf 'rm -rfI'
abbr -a s 'ls'
abbr -a vv 'git branches -vv'

Add abbr for reloading config and verbose rf

abbr -a g 'git'
abbr -a gco 'git checkout'
abbr -a rf 'rm -rfIv'
abbr -a rl 'source ~/.config/fish/config.fish'
abbr -a s 'ls'
abbr -a vv 'git branches -vv'


Add fish function to verify a sha256 sum

function verifySHA256 --argument-names $shafile --description "Verify a SHA256 checksum from file"
    echo (cat $shafile.sha256)"  $shafile" | shasum -a 256 -c
end


#!/usr/bin/env fish

set -x DOTROOT "$HOME/.dotfiles"

for file in (find $DOTROOT -maxdepth 2 -name "*.fish" -not -path "$DOTROOT/fish/*.fish")
  source $file
end

Add DOTROOT/bin to the path list

#!/usr/bin/env fish

set -x DOTROOT "$HOME/.dotfiles"

for file in (find $DOTROOT -maxdepth 2 -name "*.fish" -not -path "$DOTROOT/fish/*.fish")
  source $file
end

# Append bin to the path list.
set PATH $PATH $DOTROOT/bin


set LS_COLORS dxfxcxdxbxegedabagacad

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

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

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

alias pm 'python manage.py'
alias pms 'python manage.py shell_plus'
alias pmr 'python manage.py runserver'

alias git hub
alias top 'glances'

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

Add alias for IPython notebook.

set LS_COLORS dxfxcxdxbxegedabagacad

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

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

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

alias pm 'python manage.py'
alias pms 'python manage.py shell_plus'
alias pmr 'python manage.py runserver'
alias ipn 'ipython notebook'

alias git hub
alias top 'glances'

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


function __sk_history
    history | sk --tiebreak index -q (commandline) | read -l command

    if test -n "$command"
        commandline -rb (printf $command)
    end

    commandline -f repaint
end

set fish_user_paths ~/.cargo/bin /usr/local/bin

function fish_user_key_bindings
    command --search sk >/dev/null; and begin
        bind \cr __sk_history
    end
end

function dus
    du -had1 $argv | sort -hk1
end

set fish_greeting

alias vim=nvim
alias df="df -h"
alias du="du -h"
alias la="ls -alh"
alias mv="mv -i"
alias cp="cp -r"

set -x LESS "-FX -Ri"
set -x EDITOR nvim
set -x DIFFPROG "nvim -d"

Use --exact for skim reverse search integration

function __sk_history
    set -l query (commandline)
    set -l command

    if test -n $query
        history --search $query | sk --exact --tiebreak index -q $query | read command
    else
        history | sk --exact --tiebreak index | read command
    end

    if test -n "$command"
        commandline -rb (printf $command)
    end

    commandline -f repaint
end

set fish_user_paths ~/.cargo/bin /usr/local/bin

function fish_user_key_bindings
    command --search sk >/dev/null; and begin
        bind \cr __sk_history
    end
end

function dus
    du -had1 $argv | sort -hk1
end

set fish_greeting

alias vim=nvim
alias df="df -h"
alias du="du -h"
alias la="ls -alh"
alias mv="mv -i"
alias cp="cp -r"

set -x LESS "-FX -Ri"
set -x EDITOR nvim
set -x DIFFPROG "nvim -d"


function vcs.touched
  count (command svn status 2>/dev/null | grep -Ev 'Performing|$\s*^' | cut -c1) >/dev/null ^&1
end

Replace remaining ^ stderr redirection with 2>

function vcs.touched
  count (command svn status 2>/dev/null | grep -Ev 'Performing|$\s*^' | cut -c1) >/dev/null 2>&1
end


Add script to install latest version of rclone

function rclone-install-latest -d "Install latest version of rclone"

  unzip -oj (curl -s https://downloads.rclone.org/rclone-current-osx-amd64.zip | psub) -d $HOME/local/bin '*/rclone'
  unzip -oj (curl -s https://downloads.rclone.org/rclone-current-osx-amd64.zip | psub) -d $HOME/local/share/man/man1 '*/rclone.1'

end


function app-update --description 'Update with Homebrew and Nodejs'
  set os (uname)

  if test $os = 'Linux'
    if type -q apt
      log info 'Updating Advanced Package Tool (APT) packages...'
      sudo apt update
      sudo apt dist-upgrade -y
      sudo apt upgrade -y
      sudo apt autoremove -y
    end
  end

  if type -q brew
    log info 'Updating Homebrew modules...'
    brew update
    brew upgrade --cleanup
    brew cleanup
  end

  if type -q yarn >/dev/null
    log info 'Updating yarn modules...'
    yarn global upgrade --latest --caret --slient --no-progress >/dev/null
  end

  if type -q npm >/dev/null
    log info 'Updating NPM modules...'
    npm -g install npm
    npm -g update
  end

  if type -q fisher >/dev/null
    log info 'Updating fisherman modules...'
    fisher
  end
end

Remove deprecate parameter `--cleanup` for `brew upgrade`

function app-update --description 'Update with Homebrew and Nodejs'
  set os (uname)

  if test $os = 'Linux'
    if type -q apt
      log info 'Updating Advanced Package Tool (APT) packages...'
      sudo apt update
      sudo apt dist-upgrade -y
      sudo apt upgrade -y
      sudo apt autoremove -y
    end
  end

  if type -q brew
    log info 'Updating Homebrew modules...'
    brew update
    brew upgrade
    brew cleanup
  end

  if type -q yarn >/dev/null
    log info 'Updating yarn modules...'
    yarn global upgrade --latest --caret --slient --no-progress >/dev/null
  end

  if type -q npm >/dev/null
    log info 'Updating NPM modules...'
    npm -g install npm
    npm -g update
  end

  if type -q fisher >/dev/null
    log info 'Updating fisherman modules...'
    fisher
  end
end


function apv \
        --description='Quick nav to ApplePlatformVersions dir.'
    nav ~/dev/markdown/ApplePlatformVersions
    pull
    lg10
end

Clone APV when not present. Moved to ~/dev

function apv \
        --description='Quick nav to ApplePlatformVersions dir.'

    set -l apv_dir ~/dev/ApplePlatformVersions

    if not test -d $apv_dir
        nav ~/dev
        clone git@github.com:phatblat/ApplePlatformVersions.git
    else
        nav $apv_dir
        pull
    end

    lg10
end


Add a function for post-processing stuff

function postprocess-torrent
  set -l tordir $argv[1]
  set -l heredir (pwd)

  printf "Post-Processing: %s\n" $tordir

  if not test -d "$tordir"
    printf "Unable to find torrent directory: %s\n" $tordir
    return 1
  end

  filebot \
    -script fn:amc \
    --output "/Volumes/estore1/Media Drive/Sorted" \
    --action duplicate \
    --conflict auto \
    -non-strict \
    --log-file "/Volumes/estore1/Media Drive/Torrents/Completed/amc.log" \
    --def \
    unsorted=y \
    music=y \
    artwork=n \
    excludeList=".excludes" \
    subtitles=en \
    ut_dir="$heredir/$tordir" \
    ut_kind="multi" \
    ut_title="$tordir" \
    ut_label="N/A"

  if test $status -eq 0
    terminal-notifier -title "Torrent Post-Processing Complete" -subtitle "$tordir" -message "Successfully post-processed $tordir"
  end
end


set --global --export PROFILE (status --current-filename)
set --global --export SCRIPT_DIR (dirname (dirname $PROFILE))
set --global --export SOURCE_DIR (dirname $SCRIPT_DIR)

if not contains $SCRIPT_DIR/fish/functions $fish_function_path
    set fish_function_path $SCRIPT_DIR/fish/functions $fish_function_path
end

if [ -n $fish_greeting ]
    set --universal fish_greeting ''
end

for script in (ls -d $SCRIPT_DIR/fish/init/*.fish)
    if set -q test_login_debug
        echo "Loading: $script"
    end

    . $script
end

Standardize on long option names and clean up debug variable name

set --global --export PROFILE (status --current-filename)
set --global --export SCRIPT_DIR (dirname (dirname $PROFILE))
set --global --export SOURCE_DIR (dirname $SCRIPT_DIR)

if not contains $SCRIPT_DIR/fish/functions $fish_function_path
    set fish_function_path $SCRIPT_DIR/fish/functions $fish_function_path
end

if [ -n $fish_greeting ]
    set --universal fish_greeting ''
end

for script in (ls -d $SCRIPT_DIR/fish/init/*.fish)
    if set --query debug_fish_login
        echo "Loading: $script"
    end

    . $script
end


# Note: If query contains spaces, make sure to escape them manually.
function ffind -d "Searches recursively from cwd for files containing the query"
  find . -iname "*"$argv"*" ^/dev/null
end