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 npm >/dev/null
    log info 'Updating NPM modules...'
    npm -g install npm
    npm -g update
  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 fisher >/dev/null
    log info 'Updating fisherman modules...'
    fisher update
  end

  if type -q nvm >/dev/null
    log info 'Updating Node.js...'
    nvm list-remote latest
    nvm install latest
  end
end

Make Node.js upgrade earlier than NPM module updates

function app-update --description 'Update with Homebrew and Nodejs'

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

  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

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

  if type -q nvm >/dev/null
    log info 'Upgrading Node.js...'
    nvm list-remote latest
    nvm install latest
  end

  if type -q npm >/dev/null
    log info 'Updating NPM modules...'
    npm -g install npm
    npm -g update
  end
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 hostname (hostname)

        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 = $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

Add git branch information to fish prompt

# 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 hostname (hostname)

        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 = $USER ]
            set pwd "~"
        end

        set_color magenta;  echo -n "$pwd"

        if [ "$branch" ]
            set_color normal;   echo -n " on "
            set_color yellow;   echo -n "$branch"
        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


Add fish function to retrieve lxc ip address

function lxcip --description "Retrieve IP address of a lxc container based on container name and network interface"

    # Set command line options for parsing
    # -h/--help: Print help
    # -i/--interface: specify network interface
    # -c/--container: specify container name
    set -l options (fish_opt -s h -l help)
    set options $options (fish_opt --short i --long interface --required-val)
    set options $options (fish_opt --short c --long container --required-val)

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

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

    # If -i or --interface is given, get the interface from one or the other
    # otherwise return with non-zero exit code as this is required.
    if set -q _flag_interface
        set interface $_flag_interface
    else if set -q _flag_i
        set interface $_flag_i
    else
        echo "Interface is required"
        printHelp
        return 1
    end

    # If -c or --container is given, get the container name from one or the other
    # otherwise return with non-zero exit code as this is required.
    if set -q _flag_container
        set container $_flag_container
    else if set -q _flag_c
        set container $_flag_c
    else
        echo "Container is required"
        printHelp
        return 1
    end

    set -l searchResults (lxc list $container | grep -E -o "[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}[[:space:]]*\($interface" | awk '{print $1}')

    if set -q searchResults
        echo $searchResults
    else
        echo "No results"
        return 0
    end
end

function printHelp
    echo "Usage:"
    echo "lxcip (-i/--interface INTERFACE) (-c/--container CONTAINER_NAME)"
end


#!/usr/bin/env fish

set -x ASDF_DIR (dirname (status -f))
set -l asdf_data_dir (
  if test -n "$ASDF_DATA_DIR"; echo $ASDF_DATA_DIR;
  else; echo $HOME/.asdf; end)

# Add asdf to PATH
set -l asdf_bin_dirs $ASDF_DIR/bin $ASDF_DIR/shims $asdf_data_dir/shims

for x in $asdf_bin_dirs
  if begin not contains $x $fish_user_paths; and test -d $x; end
    set -gx fish_user_paths $fish_user_paths $x
  end
end

Update fish_user_paths only if it is defined

#!/usr/bin/env fish

set -x ASDF_DIR (dirname (status -f))
set -l asdf_data_dir (
  if test -n "$ASDF_DATA_DIR"; echo $ASDF_DATA_DIR;
  else; echo $HOME/.asdf; end)

# Add asdf to PATH
set -l asdf_bin_dirs $ASDF_DIR/bin $ASDF_DIR/shims $asdf_data_dir/shims

for x in $asdf_bin_dirs
  if begin not contains $x $PATH; and test -d $x; end
    if set -q fish_user_paths
      set -gx fish_user_paths $fish_user_paths $x
    else
      set PATH $PATH $x
    end
  end
end


# based on Simple by Sota Yamashita: https://github.com/sotayamashita/simple

function __git_upstream_configured
    git rev-parse --abbrev-ref @"{u}" > /dev/null 2>&1
end

function __print_color
    set -l color  $argv[1]
    set -l string $argv[2]

    set_color $color
    printf $string
    set_color normal
end

function fish_prompt -d "Simple Fish Prompt"
    # notify
    echo -e ""

    # Host
    # set -l host_name (hostname -s)
    # __print_color e88388 "$host_name"

    # Current working directory
    # set -l pwd_glyph " in "
    set -l pwd_string (echo $PWD | sed 's|^'$HOME'\(.*\)$|~\1|')
    __print_color cccccc "$pwd_glyph"
    __print_color a7cc8c "$pwd_string"

    # >
    __print_color e88388 "\n❯ "
end

Add git status to prompt

# based on Simple by Sota Yamashita: https://github.com/sotayamashita/simple

function __git_upstream_configured
    git rev-parse --abbrev-ref @"{u}" >/dev/null 2>&1
end

function __print_color
    set -l color $argv[1]
    set -l string $argv[2]

    set_color $color
    printf $string
    set_color normal
end

function fish_prompt -d "Simple Fish Prompt"
    # notify
    echo -e ""

    # Host
    # set -l host_name (hostname -s)
    # __print_color e88388 "$host_name"

    # Git
    if not set -q __git_cb
        set __git_cb (set_color normal)"("(set_color brown)(git branch ^/dev/null | grep \* | sed 's/* //')(set_color normal)")"
    end

    # Current working directory
    # set -l pwd_glyph " in "
    set -l pwd_string (echo $PWD | sed 's|^'$HOME'\(.*\)$|~\1|') $__git_cb
    __print_color cccccc "$pwd_glyph"
    __print_color a7cc8c "$pwd_string"

    # >
    __print_color e88388 "\n❯ "
end


function fish_prompt --description 'Write out the prompt'

    # Use after set_color to reset bold
    if not set -q __fish_prompt_color_normal
        set -g __fish_prompt_color_normal (set_color normal)
    end

    if not set -q __fish_prompt_color_hostname
        set -g __fish_prompt_color_hostname (set_color -o $fish_color_hostname)
    end

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

    if not set -q __fish_prompt_color_git
        set -g __fish_prompt_color_git (set_color $fish_color_git)
    end

    if not set -q __fish_prompt_hostname
        set -g __fish_prompt_hostname (hostname -s |cut -d \- -f 1)
    end

    echo -n -s "$__fish_prompt_color_hostname" "$__fish_prompt_hostname" "$__fish_prompt_color_normal" ':' "$__fish_prompt_color_cwd" (prompt_pwd) "$__fish_prompt_color_git" (__fish_git_prompt "#%s") "$__fish_prompt_color_normal" '$ '

end

Add @goobuntu to prompt when on my goobuntu

function fish_prompt --description 'Write out the prompt'

    # Use after set_color to reset bold
    if not set -q __fish_prompt_color_normal
        set -g __fish_prompt_color_normal (set_color normal)
    end

    if not set -q __fish_prompt_color_hostname
        set -g __fish_prompt_color_hostname (set_color -o $fish_color_hostname)
    end

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

    if not set -q __fish_prompt_color_git
        set -g __fish_prompt_color_git (set_color $fish_color_git)
    end

    if not set -q __fish_prompt_hostname
        if test "(hostname -d)" = "lon.corp.google.com"
          set -g __fish_prompt_hostname (hostname -s|cut -d \- -f 1)
        else
          set -g __fish_prompt_hostname (hostname -s|cut -d \- -f 1)@goobuntu
        end
    end

    echo -n -s "$__fish_prompt_color_hostname" "$__fish_prompt_hostname" "$__fish_prompt_color_normal" ':' "$__fish_prompt_color_cwd" (prompt_pwd) "$__fish_prompt_color_git" (__fish_git_prompt "#%s") "$__fish_prompt_color_normal" '$ '

end


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

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

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

Fix rounding errors in printf

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

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

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


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

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

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

    # Prompt to add required values

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

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

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

    echo $global_config
    cat $global_config
end

Fix check for missing name and email

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

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

    # Just print the current config when values are set.
    if begin
            test -n (git config --file $global_config user.name)
            and test -n (git config --file $global_config user.email)
        end
        cat $global_config
        return 0
    end

    # Prompt to add required values

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

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

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

    echo $global_config
    cat $global_config
end


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

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

    # Just print the current config when values are set.
    if test -n "(git config --file $global_config user.name)" -a \
            -n "(git config --file $global_config user.email)"
        cat $global_config
        return 0
    end

    # Prompt to add required values

    if test -z $name
        echo -n "Git user.name: "
        read name
    end

    if test -z $email
        echo -n "Git user.email: "
        read email
    end

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

    echo $global_config
    cat $global_config
end

Fix __gitconfig when machine hasn't been set up yet

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

    echo "🗄  Git configuration"
    echo

    createdirs ~/.config/git
    set -l global_config ~/.config/git/config
    if not test -d $global_config
        touch $global_config
    end

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

    # Prompt to add required values

    if test -z $name
        echo -n "Git user.name: "
        read name
    end

    if test -z $email
        echo -n "Git user.email: "
        read email
    end

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

    echo $global_config
    cat $global_config
end


test "prints help when given -h option"
  "Usage: gh [--help] USER REPO" \
  "" \
  "Description:" \
  "    Quickly navigate across git repositories cloned from GitHub." \
  "    Searches within $HOME/github.com/. Clones repo if not found." \
  "" \
  "Examples:" \
  "    gh dideler fish-cd-git" = (gh -h)
end

Add test for --help option

test "prints help when given -h option"
  "Usage: gh [--help] USER REPO" \
  "" \
  "Description:" \
  "    Quickly navigate across git repositories cloned from GitHub." \
  "    Searches within $HOME/github.com/. Clones repo if not found." \
  "" \
  "Examples:" \
  "    gh dideler fish-cd-git" = (gh -h)
end

test "prints help when given --help option"
  "Usage: gh [--help] USER REPO" \
  "" \
  "Description:" \
  "    Quickly navigate across git repositories cloned from GitHub." \
  "    Searches within $HOME/github.com/. Clones repo if not found." \
  "" \
  "Examples:" \
  "    gh dideler fish-cd-git" = (gh -h)
end


function init -a path --on-event init_homebrew-command-not-found
  if not available brew
    echo "Please install 'brew' first"
    return 1
  end

  if not available brew command command-not-found-init
    echo "Please install 'hombrew-command-not-found' first"
    return 1
  end

  brew command command-not-found-init > /dev/null; and . (brew command-not-found-init)

end

Send error output to /dev/null

function init -a path --on-event init_homebrew-command-not-found
  if not available brew
    echo "Please install 'brew' first"
    return 1
  end

  set -l brew_cmd (command brew command command-not-found-init 2> /dev/null)

  if test -eq status 1
    echo "Please install 'hombrew-command-not-found' first."
    echo "Check out https://github.com/Homebrew/homebrew-command-not-found"
    return 1
  end

  brew command command-not-found-init > /dev/null; and . (brew command-not-found-init)

end


function fish_right_prompt -d "Displays git branch and dirty state on the right"
  set -l cyan (set_color cyan)
  set -l red (set_color red)
  set -l normal (set_color normal)
  set -l yellow (set_color cccc00)
  set -l git_branch (git_branch_name)

  if test $git_branch
    if test git_is_dirty
      echo -n -s $cyan '‹' $yellow $git_branch $red '*' $cyan '›' $normal
    else
      echo -n -s $cyan '‹' $yellow $git_branch $cyan '›' $normal
    end
  end
end

Fix bug in git prompt

function fish_right_prompt -d "Displays git branch and dirty state on the right"
  set -l cyan (set_color cyan)
  set -l red (set_color red)
  set -l normal (set_color normal)
  set -l yellow (set_color cccc00)
  set -l git_branch (git_branch_name)

  if test $git_branch
    git_is_dirty; and begin
      echo -ns $cyan '‹' $yellow $git_branch $red '*' $cyan '›' $normal
    end; or begin
      echo -ns $cyan '‹' $yellow $git_branch $cyan '›' $normal
    end
  end
end


Add fish function to show manpage as pdf

function pman --description "Show a man page as a pdf document"
    man -w $argv[1] 2>&1 >/dev/null && begin;
        man -t $argv[1] | ps2pdf - | zathura -
    end
end


function update-vpcs
    for name in (get vpcs)
        set vpc (lookup vpc $name)

        vpc-exists $name
        or set vpc (create-vpc)
        and begin
            add-tag-to-vpc $vpc Name $name

            for tag in (get vpcs/$name/tags)
                add-tag-to-vpc $vpc $tag (get vpcs/$name/tags/$tag)
            end
        end
    end
end


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

    if user-has-password $user
        aws iam update-login-profile --user-name $user --password $password --password-reset-required
    else
        aws iam create-login-profile --user-name $user --password $password --password-reset-required
    end
end


# don't show annoying welcome message
set fish_greeting ""

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

# permissions
umask 077

Add /usr/local/sbin to path per brew's advice

# don't show annoying welcome message
set fish_greeting ""

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

# permissions
umask 077


function create-route --argument cidr gateway table
    trace (status --current-filename) $argv

    if empty "$cidr" "$gateway" "$table"
        usage create-route '<cidr>' '<gateway>' '<route-table>'
        return 23
    end

    set vpc (route-table vpc-id $table)

    switch $gateway
        case 'igw'
            set gateway --gateway (vpc internet-gateway $vpc)
        case 'igw-*'
            set gateway --gateway $gateway
    end

    aws ec2 create-route --route-table-id $table --destination-cidr-block $cidr $gateway | jq --exit-status .Return
end


set fvim /Applications/FVim.app/Contents/MacOS/FVim
if [ -e $fvim ]
	set --export EDITOR $fvim
else
	set --export EDITOR nvim
end

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

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

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

# Postgres
set --export PSQLRC $XDG_CONFIG_HOME/psqlrc

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

Add goneovim as available editor

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

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

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

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

# Postgres
set --export PSQLRC $XDG_CONFIG_HOME/psqlrc

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


#!/usr/bin/env fish
# This script generates the AUTHORS file from Git history.

echo '# This file lists all individuals having contributed content to the repository.'
echo '# This list was auto-generated from Git history.'
echo

git log --format='%aN <%aE>' | awk '
{
    pos = index($0, "<");
    name = substr($0, 0, pos - 2);
    email = substr($0, pos + 1, length($0) - pos - 1);
    names[name]++;
    emails[email]++;
    if (names[name] == 1 && emails[email] == 1) {
        print $0;
    }
}
' | env LC_ALL=C.UTF-8 sort -uf

Update author generation script to retain existing ones.

#!/usr/bin/env fish
# This script generates the AUTHORS file from Git history.

echo '# This file lists all individuals having contributed content to the repository.'
echo '# This list was auto-generated from Git history.'
echo

function list_authors
    # List existing authors
    git show HEAD:AUTHORS | sed -e '/^$/d' -e '/^#/d'

    # List any new authors
    git log --format='%aN <%aE>' | awk '
    {
        pos = index($0, "<");
        name = substr($0, 0, pos - 2);
        email = substr($0, pos + 1, length($0) - pos - 1);
        names[name]++;
        emails[email]++;
        if (names[name] == 1 && emails[email] == 1) {
            print $0;
        }
    }
    '
end

list_authors | env LC_ALL=C.UTF-8 sort -uf


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

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

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

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

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

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

Fix where it shows extra a space

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

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

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

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

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

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

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

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


function create-bucket --argument name
    if empty "$name"
        usage create-bucket '<name>'
        return (false)
    end

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

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

    has acl s3/buckets/$name
    and set -- options $options --acl (get s3/buckets/$name/acl)

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

Remove s3 from create bucket

function create-bucket --argument name
    if empty "$name"
        usage create-bucket '<name>'
        return (false)
    end

    print-status create-bucket $name
    set --local options

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

    has acl buckets/$name
    and set -- options $options --acl (get buckets/$name/acl)

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


set --export EDITOR atom
set --export VISUAL $EDITOR

set --export ATOM_DEV_RESOURCE_PATH ~/Source/atom/atom
set --export ATOM_REPOS_HOME ~/Source

Add aliases to launch different versions of Atom

set --export EDITOR atom
set --export VISUAL $EDITOR

set --export ATOM_DEV_RESOURCE_PATH ~/Source/atom/atom
set --export ATOM_REPOS_HOME ~/Source

alias a='atom'
alias aa='atom-dev'
alias ab='atom-beta'
alias ad='atom-dev'


function __fresco_wait
    if test (count $argv) != 0
        while true
            set -l remain 0

            for j in $argv
                if contains $j (jobs -p)
                    set remain 1
                    break
                end
            end

            if test $remain = 0
                break
            end

            for c in ⣾ ⣽ ⣻ ⢿ ⡿ ⣟ ⣯ ⣷
                echo -en "  $c\r"
                sleep 0.1
            end
        end
    end
end

Exit wait loop if it exceeds timeout

function __fresco_wait
    # Set default wait timeout [sec]
    set -l timeout 30
    if set -q fresco_timeout
        set -l timeout $fresco_timeout
    end
    set -l start_time (date +%s)
    set -l end_time $start_time

    if test (count $argv) != 0
        while true
            set -l remain 0

            for j in $argv
                if contains $j (jobs -p)
                    set remain 1
                    break
                end
            end

            if test $remain = 0
                break
            end

            if test (math $end_time - $start_time) -gt $timeout
                break
            end

            for c in ⣾ ⣽ ⣻ ⢿ ⡿ ⣟ ⣯ ⣷
                echo -en "  $c\r"
                set end_time (date +%s)
                sleep 0.1
            end
        end
    end
end


if not status --is-interactive
    exit
end

alias g git

alias vi nvim
alias vim nvim

alias mux tmuxinator

alias gpg gpg2
alias scramble 'gpg --encrypt --recipient me@rdavis.xyz --armour'
alias unscramble 'gpg --decrypt --quiet'

alias nstack 'stack --resolver nightly'

alias vscode code

switch (uname)
    case Linux
        alias pip-upgrade "pip3 list --outdated --user --format=legacy | cut -d ' ' -f 1 | xargs -n 1 pip3 install --upgrade --user"
        alias code "code --user-data-dir "$XDG_CONFIG_HOME/vscode" --extensions-dir "$XDG_CONFIG_HOME/vscode/extensions""
    case Darwin
        alias pip-upgrade "pip3 list --outdated --format=legacy | cut -d ' ' -f 1 | xargs -n 1 pip3 install --upgrade"
end

Use better names for gpg aliases

if not status --is-interactive
    exit
end

alias g git

alias vi nvim
alias vim nvim

alias mux tmuxinator

alias gpg gpg2
alias encrypt 'gpg --encrypt --recipient me@rdavis.xyz --armour --output -'
alias decrypt 'gpg --decrypt --quiet'

alias nstack 'stack --resolver nightly'

alias vscode code

switch (uname)
    case Linux
        alias pip-upgrade "pip3 list --outdated --user --format=legacy | cut -d ' ' -f 1 | xargs -n 1 pip3 install --upgrade --user"
        alias code "code --user-data-dir "$XDG_CONFIG_HOME/vscode" --extensions-dir "$XDG_CONFIG_HOME/vscode/extensions""
    case Darwin
        alias pip-upgrade "pip3 list --outdated --format=legacy | cut -d ' ' -f 1 | xargs -n 1 pip3 install --upgrade"
end


function ql -d "Quick Look a specified file or directory"
  if [ (count $argv) -gt 0 ]
    qlmanage >/dev/null ^/dev/null -p $argv &
  else
    echo "No arguments given"
  end
end

Make stderr redirection compatible with Fish 3.0.

function ql -d "Quick Look a specified file or directory"
  if [ (count $argv) -gt 0 ]
    qlmanage >/dev/null 2> /dev/null -p $argv &
  else
    echo "No arguments given"
  end
end


#!fish
fundle plugin 'edc/bass'
fundle plugin 'lethalpaga/deadlygoldfish-theme'
fundle init

# Setup PATH
set -g -x PATH $PATH ~/.local/bin ~/bin

# Load all scripts in config.d
if [ -z $FISH_CONFIG_DIR ]
  set FISH_CONFIG_DIR (dirname (status -f))/config.d
end

for FILE in (find $FISH_CONFIG_DIR -name "*.fish")
  source $FILE
end

Add aws-cli autocompletion for fish

#!fish
fundle plugin 'edc/bass'
fundle plugin 'lethalpaga/deadlygoldfish-theme'
fundle plugin 'oh-my-fish/plugin-aws'
fundle init

# Setup PATH
set -g -x PATH $PATH ~/.local/bin ~/bin

# Load all scripts in config.d
if [ -z $FISH_CONFIG_DIR ]
  set FISH_CONFIG_DIR (dirname (status -f))/config.d
end

for FILE in (find $FISH_CONFIG_DIR -name "*.fish")
  source $FILE
end


function create-vpc
    print-status vpc/create
    aws ec2 create-vpc --cidr-block 10.10.10.0/24 | jq --raw-output .Vpc.VpcId
end


# load solarized colors
. $HOME/.config/fish/solarized.fish
. $HOME/.config/fish/colours.fish

Set fish to use solarized theme

# load solarized colors
set -g theme_color_scheme solarized-dark


if status is-login
    if test -z "$DISPLAY" -a "$XDG_VTNR" = 1
        exec startx -- -keeptty
    end
end

set -x PATH ~/.emacs.d/bin ~/.local/bin ~/.cargo/bin (yarn global bin) $PATH
set -x BROWSER "firefox"
set -x EDITOR "nvim"
set -x PAGER "bat"
set -x MANPAGER "sh -c 'col -bx | bat -l man -p'"

abbr -a -- hm history merge

abbr -a -- cf nvim ~/.config/fish/config.fish
abbr -a -- ck nvim ~/.config/kitty/kitty.conf
abbr -a -- ci nvim ~/.config/i3/config

Store typescript logs in /tmp

if status is-login
    if test -z "$DISPLAY" -a "$XDG_VTNR" = 1
        exec startx -- -keeptty
    end
end

set -x PATH ~/.emacs.d/bin ~/.local/bin ~/.cargo/bin (yarn global bin) $PATH
set -x BROWSER "firefox"
set -x EDITOR "nvim"
set -x PAGER "bat"
set -x MANPAGER "sh -c 'col -bx | bat -l man -p'"
set -x TSSERVER_LOG_FILE "/tmp/tsserver.log"

abbr -a -- hm history merge

abbr -a -- cf nvim ~/.config/fish/config.fish
abbr -a -- ck nvim ~/.config/kitty/kitty.conf
abbr -a -- ci nvim ~/.config/i3/config


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

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

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

Add support for bucket ACLs

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

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

    has acl s3/buckets/$name
    and set -- options $options --acl (get s3/buckets/$name/acl)

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


set fish_greeting ""

abbr --add g git
abbr --add gc 'git commit'
abbr --add gca 'git commit -a'
abbr --add gd 'git diff'
abbr --add gst 'git status'
abbr --add p 'pass'
abbr --add pc 'pass -c'
abbr --add z 'zathura --fork'

setenv SSH_AUTH_SOCK $XDG_RUNTIME_DIR/gnupg/S.gpg-agent.ssh
gpg-connect-agent updatestartuptty /bye > /dev/null

# Start X at login
if status --is-login
    set PATH $PATH /usr/bin /sbin
    if test -z "$DISPLAY" -a $XDG_VTNR = 1
        startx
    end
end

Update pass abbreviation in fish.

set fish_greeting ""

abbr --add g git
abbr --add gc 'git commit'
abbr --add gca 'git commit -a'
abbr --add gd 'git diff'
abbr --add gst 'git status'
abbr --add p 'pass -c'
abbr --add z 'zathura --fork'

setenv SSH_AUTH_SOCK $XDG_RUNTIME_DIR/gnupg/S.gpg-agent.ssh
gpg-connect-agent updatestartuptty /bye > /dev/null

# Start X at login
if status --is-login
    set PATH $PATH /usr/bin /sbin
    if test -z "$DISPLAY" -a $XDG_VTNR = 1
        startx
    end
end


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

## For GPG
## See also https://blog.scottlowe.org/2017/09/06/using-keybase-gpg-macos/
set -x GPG_TTY (tty)

Update to using Java 11 by default

# 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 11)
set -x JAVA_HOME "/Library/Java/JavaVirtualMachines/adoptopenjdk-11.0.1.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"

## For GPG
## See also https://blog.scottlowe.org/2017/09/06/using-keybase-gpg-macos/
set -x GPG_TTY (tty)


function paradox_git_hash --description "Get the current git commit hash, if we're in a git working tree"
  set -l git_info (command git rev-parse --is-inside-work-tree --short HEAD ^/dev/null)
  if test (count $git_info) -gt 1
    set -l inside_worktree $git_info[1]
    set -l git_head $git_info[2]
    if test "true" = "$inside_worktree"
      echo -s (set_color blue) "[$git_head]"
    end
  end
end

Add timeout to git hash function for safety

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

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

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


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

    set -l last_status_string ""
    if [ $last_status -ne 0 ]
        printf "%s(%d)%s " (set_color red --bold) $last_status (set_color normal)
    end

    set -l color_cwd
    set -l suffix
    switch $USER
    case root toor
        if set -q fish_color_cwd_root
            set color_cwd $fish_color_cwd_root
        else
            set color_cwd $fish_color_cwd
        end
        set suffix '#'
    case '*'
        set color_cwd $fish_color_cwd
        set suffix '>'
    end

    # Show $HOME as ~
    set -l cwd (pwd | sed "s_$HOME\>_~_")

    echo -n -s (set_color $color_cwd) $cwd (set_color normal) (__fish_git_prompt) (set_color normal) "$suffix "
end

Fix display of home directory as ~ in fish prompt CWD.

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

    set -l last_status_string ""
    if [ $last_status -ne 0 ]
        printf "%s(%d)%s " (set_color red --bold) $last_status (set_color normal)
    end

    set -l color_cwd
    set -l suffix
    switch $USER
    case root toor
        if set -q fish_color_cwd_root
            set color_cwd $fish_color_cwd_root
        else
            set color_cwd $fish_color_cwd
        end
        set suffix '#'
    case '*'
        set color_cwd $fish_color_cwd
        set suffix '>'
    end

    # Show $HOME as ~
    set -l cwd (pwd | sed -E "s_^$HOME(/|\$)_~\1_")

    echo -n -s (set_color $color_cwd) $cwd (set_color normal) (__fish_git_prompt) (set_color normal) "$suffix "
end


# Colorized ls output
set --export CLICOLOR 1
set --export LSCOLORS Exfxcxdxbxegedabagacad

# Ensure the HOSTNAME environment variable is set so that `rcm` works properly
if ! set --query HOSTNAME
  set --export HOSTNAME (hostname -s)
end

if status --is-interactive
  set --global fish_user_abbreviations

  abbr --add ex 'exercism'
  abbr --add gg 'git graph'
  abbr --add guf 'git update-fork'
  abbr --add p 'project'
end

set --global fish_prompt_pwd_dir_length 0

# Configure Homebrew before doing the other init scripts
# /usr/local is used on Intel Macs
# /opt/homebrew is used on Apple Silicon Macs
if test -d /usr/local/bin/brew
  eval (/usr/local/bin/brew shellenv)
end

if test -d /opt/homebrew/bin/brew
  eval (/opt/homebrew/bin/brew shellenv)
end

for init in (command ls ~/.config/fish/init)
  source ~/.config/fish/init/$init
end

Check for brew as files, not directories

# Colorized ls output
set --export CLICOLOR 1
set --export LSCOLORS Exfxcxdxbxegedabagacad

# Ensure the HOSTNAME environment variable is set so that `rcm` works properly
if ! set --query HOSTNAME
  set --export HOSTNAME (hostname -s)
end

if status --is-interactive
  set --global fish_user_abbreviations

  abbr --add ex 'exercism'
  abbr --add gg 'git graph'
  abbr --add guf 'git update-fork'
  abbr --add p 'project'
end

set --global fish_prompt_pwd_dir_length 0

# Configure Homebrew before doing the other init scripts
# /usr/local is used on Intel Macs
# /opt/homebrew is used on Apple Silicon Macs
if test -e /usr/local/bin/brew
  eval (/usr/local/bin/brew shellenv)
end

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

for init in (command ls ~/.config/fish/init)
  source ~/.config/fish/init/$init
end


function __proxy.set -a proxy \
  -d "Set all proxy vars to specified value"

  set -l envars http_proxy HTTP_PROXY \
    https_proxy HTTPS_PROXY \
    ftp_proxy FTP_PROXY \
    all_proxy ALL_PROXY
  for envar in $envars
    if test $proxy = '-e'
      set -e $envar
    else
      set -gx $envar $proxy
    end
  end
end

Make variables universal instead of global

function __proxy.set -a proxy \
  -d "Set all proxy vars to specified value"

  set -l envars http_proxy HTTP_PROXY \
    https_proxy HTTPS_PROXY \
    ftp_proxy FTP_PROXY \
    all_proxy ALL_PROXY
  for envar in $envars
    if test $proxy = '-e'
      set -e $envar
    else
      set -Ux $envar $proxy
    end
  end
end


# Initializes sharship prompt
if command -v starship > /dev/null
    starship init fish | source
end

# Initializes asdf
if test -f ~/.asdf/asdf.fish > /dev/null
    source ~/.asdf/asdf.fish
end

# Abbreviations
abbr --add be bundle exec
abbr --add dc docker-compose
abbr --add g git
abbr --add gd git diff
abbr --add gds git diff --staged

set -xg EDITOR emacsclient

# FZF
if command -v fzf > /dev/null
    set -xg FZF_DEFAULT_OPTS '--height 40% --border'
    if command -v fd > /dev/null
        set -xg FZF_DEFAULT_COMMAND  'fd --type=file --hidden --no-ignore-vcs'
    end

    function gcf
        git checkout (git branch --all | sed "s/.* //" | fzf)
    end
end

# bat as a cat replacement
if command -v bat > /dev/null
    alias cat="bat"

    function batf
        tail -f $argv | bat --paging=never -l log
    end
end

# `tm` alias to attach to running tmux session or create a new one
if command -v tmux > /dev/null
    function tm -d "Attach to running tmux session or create a new one"
        tmux attach || tmux new
    end
end

# Start / attach to tmux
# - if we are not in a tmux session already
# - if we are not connected via SSH (to prevent nested tmux sessions)
if not set --query TMUX and not set --query SSH_CLIENT
    tm
end

Revert "Do not start tmux if we are logged in via ssh"

# Initializes sharship prompt
if command -v starship > /dev/null
    starship init fish | source
end

# Initializes asdf
if test -f ~/.asdf/asdf.fish > /dev/null
    source ~/.asdf/asdf.fish
end

# Abbreviations
abbr --add be bundle exec
abbr --add dc docker-compose
abbr --add g git
abbr --add gd git diff
abbr --add gds git diff --staged

set -xg EDITOR emacsclient

# FZF
if command -v fzf > /dev/null
    set -xg FZF_DEFAULT_OPTS '--height 40% --border'
    if command -v fd > /dev/null
        set -xg FZF_DEFAULT_COMMAND  'fd --type=file --hidden --no-ignore-vcs'
    end

    function gcf
        git checkout (git branch --all | sed "s/.* //" | fzf)
    end
end

# bat as a cat replacement
if command -v bat > /dev/null
    alias cat="bat"

    function batf
        tail -f $argv | bat --paging=never -l log
    end
end

# `tm` alias to attach to running tmux session or create a new one
if command -v tmux > /dev/null
    function tm -d "Attach to running tmux session or create a new one"
        tmux attach || tmux new
    end
end

# Start / attach to tmux if we are not in a tmux session already
if not set --query TMUX
    tm
end


if status is-login
    if test -z "$DISPLAY" -a "$XDG_VTNR" = 1
        exec startx -- -keeptty
    end
end

set -x PATH ~/.emacs.d/bin ~/.local/bin ~/.cargo/bin (yarn global bin) /usr/share/bcc/tools $PATH
set -x BROWSER "firefox"
set -x EDITOR "nvim"
set -x PAGER "bat"
set -x MANPAGER "sh -c 'col -bx | bat -l man -p'"
set -x TSSERVER_LOG_FILE "/tmp/tsserver.log"

abbr -a -- hm history merge

abbr -a -- cf nvim ~/.config/fish/config.fish
abbr -a -- ck nvim ~/.config/kitty/kitty.conf
abbr -a -- ci nvim ~/.config/i3/config

Add ghcup bin dir to path

if status is-login
    if test -z "$DISPLAY" -a "$XDG_VTNR" = 1
        exec startx -- -keeptty
    end
end

set -x PATH ~/.local/bin ~/.emacs.d/bin ~/.cargo/bin (yarn global bin) ~/.cabal/bin ~/.ghcup/bin $PATH
set -x BROWSER "firefox"
set -x EDITOR "nvim"
set -x PAGER "bat"
set -x MANPAGER "sh -c 'col -bx | bat -l man -p'"
set -x TSSERVER_LOG_FILE "/tmp/tsserver.log"

abbr -a -- hm history merge

abbr -a -- cf nvim ~/.config/fish/config.fish
abbr -a -- ck nvim ~/.config/kitty/kitty.conf
abbr -a -- ci nvim ~/.config/i3/config


# Set path
set -g fish_user_paths $fish_user_paths $HOME/bin

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

# Initialize special functions
source $HOME/.config/fish/functions/__commajump_add.fish
source $HOME/.config/fish/functions/tmux_rename_window.fish

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

# Set program options
set -x HOMEBREW_NO_AUTO_UPDATE true

if which direnv > /dev/null
	eval (direnv hook fish)
end

Add go bin folder to PATH

# Set path
set -g fish_user_paths $fish_user_paths $HOME/bin $HOME/go/bin

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

# Initialize special functions
source $HOME/.config/fish/functions/__commajump_add.fish
source $HOME/.config/fish/functions/tmux_rename_window.fish

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

# Set program options
set -x HOMEBREW_NO_AUTO_UPDATE true

if which direnv > /dev/null
	eval (direnv hook fish)
end


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

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

Add `show-proc` to print detailed process command

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

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

function show-proc -d 'Print the detail of a process'
  # https://explainshell.com/explain?cmd=ps+auxww+123
  ps auxww $argv
end


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


function fish_user_key_bindings
    bind -M insert \eg 'commandline -i " | rg"'
    bind -M insert jk 'if commandline -P; commandline -f cancel; else; set fish_bind_mode default; commandline -f backward-char repaint-mode; end'
    bind -M insert \ce end-of-line
    bind -M insert \ca beginning-of-line
    bind -M insert \cf forward-char
end

fish_vi_key_bindings

Include all emacs keybindings in fish insert mode

function fish_user_key_bindings
    bind -M insert \eg 'commandline -i " | rg"'
    bind -M insert -k nul 'if commandline -P; commandline -f cancel; else; set fish_bind_mode default; commandline -f backward-char repaint-mode; end'

    fish_default_key_bindings -M insert
    fish_vi_key_bindings --no-erase
end


function project \
  --description 'Shortcut from anywhere to a project directory' \
  --argument-names {project}

  cd $REPO_HOME/$project
end

Add check for REPO_HOME environment variable

function project \
  --description 'Shortcut from anywhere to a project directory' \
  --argument-names project

  if not set -q REPO_HOME
    echo 'REPO_HOME environment variable must be set to the directory where all projects are stored'
    exit 1
  end

  cd $REPO_HOME/$project
end


function fish_user_key_bindings
  fish_vi_key_bindings

  if type -q fzf_key_bindings
    fzf_key_bindings
  end

  bind -M insert -m default jk backward-char force-repaint
end

Load fzf fish bindings from nix

function fish_user_key_bindings
  fish_vi_key_bindings

  if command -s fzf-share >/dev/null
    source (fzf-share)/key-bindings.fish
  end

  if type -q fzf_key_bindings
    fzf_key_bindings
  end

  bind -M insert -m default jk backward-char force-repaint
end


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

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

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

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

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

# fin
fin 6

Add alias for python3 and pip3

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

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

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

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

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

# fin
fin 6


function users-without-mfa
    comm -13 (users-with-mfa | psub) (get users | psub)
end

Sort results before piping to comm

function users-without-mfa
    comm -13 (users-with-mfa | sort | psub) (get users | sort | psub)
end


test "$TESTNAME - use custom string to display null values"
    "▂?▄?▆?█" = (
        printf "%s\n" 1,,2,,3,,4 | shark --null="?"
        )
end

test "$TESTNAME - no data prints nothing and exits with a 1"
    1 = (
        echo | shark
        echo $status
        )
end

test "$TESTNAME - show help information"
    "Usage: shark [--line] [--field[=<format>]] [--record[=<format>]] [--max=<n>] [--min=<n>] [--delim=<regex>] [--help] -n --line Process each line as a record -f --field=<format> Set field output format -r --record=<format> Set record output format -m --min=<number> Set minimum numeric value -M --max=<number> Set maximum numeric value -d --delim=<regex> Use <regex> as number separator --null=<string> Use <string> to display null values -h --help Show this help" = (
        shark -h | xargs
        )
end

Remove test for usage help.


function git_status
    if git rev-parse --is-inside-work-tree 1> /dev/null 2>& 1
        if not git diff --quiet
            set_color red
            echo -n "✘"
            set_color normal
        end
        if not git diff --quiet --cached
            set_color yellow
            echo -n "✔"
            set_color normal
        end
        begin
          set -l IFS ""
          if test -n ""(git ls-files --others --exclude-standard)""
            set_color green
            echo -n "☆"
          end
        end
        set_color blue
        echo -n ""(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')""
        set_color normal
    end
end

function fish_prompt
    set_color yellow
    echo -n "$PWD"
    set_color normal
    git_status
    echo -n "\$"
end

Add better git prompt to fish


function fish_right_prompt
  if status --is-interactive
    set -l __paradox_date (command date +%I:%M:%S%P ^/dev/null)
    if type ruby >/dev/null ^/dev/null
      # have to use the echo inline to prevent obnoxious spaces, i.e. (💎2.3.0 )
      set __paradox_rb_version (echo -s "(💎 " (command ruby -e 'print RUBY_VERSION' ^/dev/null) ")")
    end
    echo -se "\e[1A" (set_color blue) "$__paradox_rb_version" (set_color green) (__paradox_command_duration) (set_color normal) "[$__paradox_date]"  "\e[1B"
  end
end

Fix ruby version spacing, and add a few comments

function fish_right_prompt
  if status --is-interactive
    set -l __paradox_date (command date +%I:%M:%S%P ^/dev/null)
    if type ruby >/dev/null ^/dev/null
      # have to use the echo inline to prevent obnoxious spaces, i.e. (💎2.3.0 )
      set __paradox_rb_version (echo -s "(💎  " (command ruby -e 'print RUBY_VERSION' ^/dev/null) ")")
    end

    # The \e[1A code below is to move the prompt up a line, so it aligns with the first line of the lprompt.
    # The \e[1B code resets to the previous line, so everything renders properly
    echo -se "\e[1A" (set_color blue) "$__paradox_rb_version" (set_color green) (__paradox_command_duration) (set_color normal) "[$__paradox_date]"  "\e[1B"
  end
end


alias myip="curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+'"

Add branch to fish prompt

alias myip="curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+'"

function update_dots
  cd ~/.dotfiles; and git stash save and git pull; and ./dots.sh
end

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

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

  if not set -q __git_cb
    set __git_cb ":"(set_color brown)(git branch ^/dev/null | grep \* | sed 's/* //')(set_color normal)""
  end

  switch $USER

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

  printf '%s@%s:%s%s%s%s# ' $USER $__fish_prompt_hostname "$__fish_prompt_cwd" (prompt_pwd) "$__fish_prompt_normal" $__git_cb

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

  printf '%s@%s:%s%s%s%s$ ' $USER $__fish_prompt_hostname "$__fish_prompt_cwd" (prompt_pwd) "$__fish_prompt_normal" $__git_cb
  end
end


function update
    sudo softwareupdate -i -a
    brew update
    brew upgrade --force --all
    brew cleanup
    npm install npm -g
    npm update -g
    mas upgrade
end

Update Atom packages when updating all the things

function update
  sudo softwareupdate -i -a
  brew update
  brew upgrade --force
  brew cleanup
  npm install npm -g
  npm update -g
  apm update -c false
  mas upgrade
end


# Here is the configuration for the fish shell

source ~/deoxys314_dotfiles/fish/aliases.fish

source ~/deoxys314_dotfiles/fish/functions.fish

set PATH $PATH ~/bin

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

Create `~/bin` directory before adding it to the PATH.

# Here is the configuration for the fish shell

source ~/deoxys314_dotfiles/fish/aliases.fish

source ~/deoxys314_dotfiles/fish/functions.fish

mkdir -pv ~/bin

set PATH $PATH ~/bin

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


set ssh_agent_pid (pgrep ssh-agent)
if $ssh_agent_pid[0]
    __test_ssh_identities
else
    __start_ssh_agent
end

Use function to determine presence of ssh-agent

function agent_is_present -d "find ssh-agent process if one is running"
    set ssh_agent_pid (pgrep ssh-agent)
    if $ssh_agent_pid[0] > 1
        return true
    else
        return false
    end
end

if agent_is_present
    __test_ssh_identities
else
    __start_ssh_agent
end


# Run this in the directory you want the subtrees to be located in
# Takes the path to the directory where the plugins are, usually ~/.vim/bundle
# Can be passed a blacklist by adding "--except NAME..." to the arguments. Useful for segregating plugins into different directories
function vim_git_import --description 'Imports ~/.vim/bundle plugins to git subtrees' --argument from
    set -l exceptions
    if test (count $argv) -eq 0
        echo "usage: vim_git_import FROM [--except NAME...]"
        return 1
    else if test (count $argv) -ge 2
        if test $argv[2] != "--except"
            echo "usage: vim_git_import FROM [--except NAME...]"
            return 1
        end
        set exceptions $argv[3..(count $argv)]
    end
    for plugin in (find $from -maxdepth 1 | tail -n +2)
        set -l plugin_name (basename $plugin)
        if contains $plugin_name $exceptions
            continue
        end
        set -l prefix (git rev-parse --show-prefix)$plugin_name
        set -l url (pushd $plugin; git remote -v | head -n 1 | cut -f 2 | cut -d ' ' -f 1; popd)
        pushd (git rev-parse --show-toplevel)
            # echo  "git subtree add --prefix $prefix --squash $url master"
            git subtree add --prefix $prefix --squash $url master; read _
        popd
    end
end

Make this script suitable for adding only one directory

# Run this in the directory you want the subtrees to be located in
# Takes the name of the plugin's directory
function vim_git_import --description 'Imports ~/.vim/bundle plugins to git subtrees' --argument plugin
    if test (count $argv) -ne 1
        echo "usage: vim_git_import PLUGIN"
        return 1
    end
    set -l prefix (git rev-parse --show-prefix)$plugin
    set -l url (pushd $plugin; git remote -v | head -n 1 | cut -f 2 | cut -d ' ' -f 1; popd)
    pushd (git rev-parse --show-toplevel)
    # echo  "git subtree add --prefix $prefix --squash $url master"
    git subtree add --prefix $prefix --squash $url master
    popd
end


function create-security-group --argument name vpc description
    trace (status --current-filename) $argv

    if empty "$name"
        usage create-security-group '<name>' '[vpc]' '[description]'
        return 23
    end

    if empty $description
        set description $name
    end

    if empty $vpc
        aws ec2 create-security-group --group-name $name --description $description | jq --raw-output .SecurityGroups[].GroupId//empty
    else
        if security-group exists $name $vpc
            print --warning Security Group $name already exists in $vpc
        else
            aws ec2 create-security-group --vpc-id $vpc --group-name $name --description $description | jq --raw-output .GroupId//empty
        end
    end
end


# Manage TextMate bundles.
function tmbundles
    set -l bundles editorconfig fish gradle
    set -l bundle_dev ~/dev/textmate
    set -l bundle_dir ~/Library/Application\ Support/TextMate/Bundles

    if not test -e $bundle_dev
        mkdir -p $bundle_dev
    end
    if not test -e $bundle_dir
        mkdir -p $bundle_dir
    end

    pushd $bundle_dev

    for bundle in $bundles
        if not test -e $bundle.tmbundle
            switch $bundle
                case editorconfig
                    git clone git@github.com:Mr0grog/editorconfig-textmate.git $bundle.tmbundle
                case fish
                    git clone git@github.com:l15n/fish-tmbundle.git $bundle.tmbundle
                case gradle
                    git clone git@github.com:alkemist/gradle.tmbundle.git $bundle.tmbundle
            end
        end
        open $bundle.tmbundle
    end

    echo $bundle_dev
    ls
    popd
end

Revise EditorConfig TextMate plugin install to download binary

# Manage TextMate bundles.
function tmbundles
    set -l bundles editorconfig fish gradle

    set -l bundle_dev ~/dev/textmate
    set -l bundle_dir ~/Library/Application\ Support/TextMate/Bundles

    if not test -e $bundle_dev
        mkdir -p $bundle_dev
    end
    if not test -e $bundle_dir
        mkdir -p $bundle_dir
    end

    pushd $bundle_dev

    for bundle in $bundles
        if not test -e $bundle.tmbundle
            switch $bundle
                case editorconfig
                    if not test -e editorconfig-textmate
                        git clone git@github.com:Mr0grog/editorconfig-textmate.git
                    end

                    set -l version 0.3.1
                    # curl -L -O -#
                    curl --location --remote-name --progress-bar \
                        https://github.com/Mr0grog/editorconfig-textmate/releases/download/v$version/editorconfig-textmate-$version.tmplugin.zip

                    set newest_file (ls -1t | head -n 1)
                    unzip -o $newest_file
                        and rm -f $newest_file

                    open editorconfig-textmate.tmplugin

                    # Create a dummy bundle file so install isn't repeated.
                    touch $bundle.tmbundle
                case fish
                    git clone git@github.com:l15n/fish-tmbundle.git $bundle.tmbundle
                case gradle
                    git clone git@github.com:alkemist/gradle.tmbundle.git $bundle.tmbundle
            end
        end
        open $bundle.tmbundle
    end

    echo $bundle_dev
    ls
    popd
end


Add function to show diff between states

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

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

    diff (eval real-$subject | psub) (get $subject | psub)
end


Add fish function for converting PDFs to JPGs.

# Usage
#
#   pdf2jpg in.pdf  # => in.jpg
#
#   pdf2jpg in.pdf out.jpg  # => out.jpg
#
function pdf2jpg --description "Convert a (scanned) PDF to a JPG"

  function _print_usage
    echo -e "Usage:\n  pdf2jpg in.pdf\n  pdf2jpg in.pdf out.jpg"
  end

  switch (count $argv)
    case 0  # No arguments, error.
      _print_usage
      return 1

    case 1  # One argument.
      switch $argv
        case '-h' '--h' '--he' '--hel' '--help'
          _print_usage
          return 0

        case '-*'
          printf "%s: Unknown option %s\n" pdf2jpg $argv
          return 1

        case '*.pdf' '*.PDF'
          set pdf $argv[1]

        case '*'
          _print_usage
          return 1
      end

    case 2  # Two arguments.
      switch (echo $argv)
        case '*.pdf *.jpg' '*.pdf *.jpeg' '*.PDF *.jpg' '*.PDF *.jpeg'
          set pdf $argv[1]
          set jpg $argv[2]

        case '*'
          _print_usage
          return 1
      end

    case \*  # Too many arguments, error.
      printf "%s: Expected one or two arguments, got %d\n" pdf2jpg (count $argv)
      return 1
  end

  if set --query jpg  # Use the given output filename.
    convert -quiet -density 150 -trim $pdf -quality 100 -sharpen 0x1.0 $jpg
  else  # Use the filename of the PDF.
    set jpg (filename $pdf).jpg
    convert -quiet -density 150 -trim $pdf -quality 100 -sharpen 0x1.0 $jpg
  end
end


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

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

  echo -n ' in '

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

  # __terlar_git_prompt
  __fish_git_prompt
  echo

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

  echo -n '∫ '
  set_color normal
end

Use custom colors in fish prompt

function fish_prompt --description 'Write out the prompt'
  # Set custom color variables
  set -l username_color fdd8aa
  set -l prompt_color 8cd6ff

  set -l last_status $status

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

  echo -n ' in '

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

  __fish_git_prompt # __terlar_git_prompt
  echo

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

  echo -n '∫ '
  set_color normal
end


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

  set -l arguments

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

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

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

  command git commit $OPTV $ARGV
  gs
end

Fix the git commit -m wrapper

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

  if test (count $argv) -eq 0
    set_color red
    echo "Arborting commit due to empty commit message"
    set_color normal
    return 1
  end

  command git commit -m "$argv"
  gs
end


abbr -a -- - 'cd -'
abbr -a axel 'axel -a'
abbr -a b 'brew'
abbr -a dl 'wget -r -l 1 -np -nd'
abbr -a fn 'find . -iname'
abbr -a g git
abbr -a gd git diff
abbr -a gf git fetch
abbr -a gs git status -sb
abbr -a l 'ls -lahp'
abbr -a lx 'less -X'
abbr -a o 'open .'
abbr -a q exit
abbr -a ql 'qlmanage -p'
abbr -a t 'tmux'
abbr -a ta 'type -a'
abbr -a v vim

Add abbreviation for clojure with cheshire and rebel-readline

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 dl 'wget -r -l 1 -np -nd'
abbr -a fn 'find . -iname'
abbr -a g git
abbr -a gd git diff
abbr -a gf git fetch
abbr -a gs git status -sb
abbr -a l 'ls -lahp'
abbr -a lx 'less -X'
abbr -a o 'open .'
abbr -a q exit
abbr -a ql 'qlmanage -p'
abbr -a t 'tmux'
abbr -a ta 'type -a'
abbr -a v vim


#!/usr/bin/env fish

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

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

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

Fix fish shell init snippet

#!/usr/bin/env fish

set -l asdf_dir (dirname (status -f))
set -l asdf_data_dir (
  if test -n "$ASDF_DATA_DIR"; echo $ASDF_DATA_DIR;
  else; echo $HOME/.asdf; end)

# Add asdf to PATH
set -l asdf_bin_dirs $asdf_dir/bin $asdf_dir/shims $asdf_data_dir/shims

for x in $asdf_bin_dirs
  if begin not contains $x $PATH; and test -d $x; end
    set -gx PATH $x $PATH
  end
end


# Abbreviations (text expansion)
abbr --add gp 'git push'
abbr --add gpf 'git push --force'
abbr --add gst 'git status'  # gs taken by Ghostscript
abbr --add icat 'kitty +kitten icat'
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 text expansion for editing dotfiles

# Abbreviations (text expansion)
abbr --add cf '$EDITOR $XDG_CONFIG_HOME/'
abbr --add gp 'git push'
abbr --add gpf 'git push --force'
abbr --add gst 'git status'  # gs taken by Ghostscript
abbr --add icat 'kitty +kitten icat'
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'


#!/usr/bin/env fish

set fish_greeting
set -x GOPATH $HOME/Code/gopkg
set -x MAILDIR $HOME/mail
set -x EDITOR vim
set -x MANPAGER vimpager
set -x GEM_HOME $HOME/.local/gems/(ruby -v | awk '{print $2}')
set -x GEM_PATH $GEM_HOME
set -x COCOAPODS_DISABLE_STATS 1
set -x PIP_REQUIRE_VIRTUALENV 1
set -x PKG_CONFIG_PATH /usr/local/lib/pkgconfig /usr/local/lib
set -x PATH $GEM_HOME/bin $HOME/bin /usr/local/bin /usr/local/sbin \
            /bin /usr/bin /usr/sbin /sbin $GOPATH/bin /usr/local/go/bin \
            $HOME/.cargo/bin

source /usr/local/share/chruby/chruby.fish
source $HOME/.config/fish/functions/aliases.fish
status --is-interactive; and . (swiftenv init -|psub)

Remove cargo binpath for multirust

#!/usr/bin/env fish

set fish_greeting
set -x GOPATH $HOME/Code/gopkg
set -x MAILDIR $HOME/mail
set -x EDITOR vim
set -x MANPAGER vimpager
set -x GEM_HOME $HOME/.local/gems/(ruby -v | awk '{print $2}')
set -x GEM_PATH $GEM_HOME
set -x COCOAPODS_DISABLE_STATS 1
set -x PIP_REQUIRE_VIRTUALENV 1
set -x PKG_CONFIG_PATH /usr/local/lib/pkgconfig /usr/local/lib
set -x PATH $GEM_HOME/bin $HOME/bin /usr/local/bin /usr/local/sbin \
            /bin /usr/bin /usr/sbin /sbin $GOPATH/bin /usr/local/go/bin

source /usr/local/share/chruby/chruby.fish
source $HOME/.config/fish/functions/aliases.fish
status --is-interactive; and . (swiftenv init -|psub)


export EDITOR="nvim"
export XDG_CONFIG_HOME="$HOME/.config"
export PAGER="less"
export LESS="-g -i -M -R -S -W -z-4 -x4"
export PATH="$HOME/.bin:$PATH"
export PATH="$PATH:/usr/local/sbin"

## Set Locale
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
export LANG="en_US.UTF-8"

Revert "Add /usr/local/sbin in $PATH"

export EDITOR="nvim"
export XDG_CONFIG_HOME="$HOME/.config"
export PAGER="less"
export LESS="-g -i -M -R -S -W -z-4 -x4"
export PATH="$HOME/.bin:$PATH"

## Set Locale
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
export LANG="en_US.UTF-8"


# Colorized ls output
set --export CLICOLOR 1
set --export LSCOLORS Exfxcxdxbxegedabagacad

# Ensure the HOSTNAME environment variable is set so that `rcm` works properly
if ! set --query HOSTNAME
  set --export HOSTNAME (hostname -s)
end

if status --is-interactive
  set --global fish_user_abbreviations

  abbr --add ex 'exercism'
  abbr --add gg 'git graph'
  abbr --add guf 'git update-fork'
  abbr --add p 'project'
end

set --global fish_prompt_pwd_dir_length 0

# Configure Homebrew before doing the other init scripts
eval (/opt/homebrew/bin/brew shellenv)

for init in (command ls ~/.config/fish/init)
  source ~/.config/fish/init/$init
end

Initialize Homebrew properly on both Intel and ASi Macs

# Colorized ls output
set --export CLICOLOR 1
set --export LSCOLORS Exfxcxdxbxegedabagacad

# Ensure the HOSTNAME environment variable is set so that `rcm` works properly
if ! set --query HOSTNAME
  set --export HOSTNAME (hostname -s)
end

if status --is-interactive
  set --global fish_user_abbreviations

  abbr --add ex 'exercism'
  abbr --add gg 'git graph'
  abbr --add guf 'git update-fork'
  abbr --add p 'project'
end

set --global fish_prompt_pwd_dir_length 0

# Configure Homebrew before doing the other init scripts
# /usr/local is used on Intel Macs
# /opt/homebrew is used on Apple Silicon Macs
if test -d /usr/local/bin/brew
  eval (/usr/local/bin/brew shellenv)
end

if test -d /opt/homebrew/bin/brew
  eval (/opt/homebrew/bin/brew shellenv)
end

for init in (command ls ~/.config/fish/init)
  source ~/.config/fish/init/$init
end


# Disable fish greeting
set fish_greeting ""

function my_vi_key_bindings
    fish_vi_key_bindings
    bind -M insert \cl 'clear; commandline -f repaint'
end

fish_vi_mode

set -g fish_key_bindings my_vi_key_bindings

# Aliases
alias vim="nvim"

# Set environment variables
set -x NVIM_TUI_ENABLE_TRUE_COLOR 1

set -x GAE_SDK /usr/local/Cellar/app-engine-python/1.9.27/share/google-app-engine
set -gx PATH /usr/local/bin /usr/texbin $PATH

set -x DOCKER_HOST tcp://192.168.59.103:2376
set -x DOCKER_CERT_PATH /Users/kevinchen/.boot2docker/certs/boot2docker-vm
set -x DOCKER_TLS_VERIFY 1

eval "bash ~/.config/fish/base16-eighties.dark.sh"

#switch $TERM
#    case '*screen*'
#    case '*'
#        tmux attach -t tmux; or tmux new -s tmux
#end

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

Comment out VI bindings because it's irritating to hit the ESC key every time

# Disable fish greeting
set fish_greeting ""

#function my_vi_key_bindings
#    fish_vi_key_bindings
#    bind -M insert \cl 'clear; commandline -f repaint'
#end

#fish_vi_mode

#set -g fish_key_bindings my_vi_key_bindings

# Aliases
alias vim="nvim"

# Set environment variables
set -x NVIM_TUI_ENABLE_TRUE_COLOR 1

set -x GAE_SDK /usr/local/Cellar/app-engine-python/1.9.27/share/google-app-engine
set -gx PATH /usr/local/bin /usr/texbin $PATH

set -x DOCKER_HOST tcp://192.168.59.103:2376
set -x DOCKER_CERT_PATH /Users/kevinchen/.boot2docker/certs/boot2docker-vm
set -x DOCKER_TLS_VERIFY 1

eval "bash ~/.config/fish/base16-eighties.dark.sh"

#switch $TERM
#    case '*screen*'
#    case '*'
#        tmux attach -t tmux; or tmux new -s tmux
#end

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


function fish_right_prompt
  if set -q VIRTUAL_ENV
    # Let's hope python won't break this way to read the version
    set -l python_version (python --version | sed -e 's/Python //g')
    set -l virtual_env_short (shorten_path $VIRTUAL_ENV)
    echo "$virtual_env_short@$python_version"
  end
end

Add color to virtual env

function fish_right_prompt
  if set -q VIRTUAL_ENV
    # Let's hope python won't break this way to read the version
    set -l python_version (python --version | sed -e 's/Python //g')
    set -l virtual_env_short (shorten_path $VIRTUAL_ENV)
    set_color -b yellow
    set_color black
    echo "$virtual_env_short@$python_version"
    set_color normal
  end
end


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

# better ls
function ls
	command ls -lhFG $argv
end

function la
	command ls -lhFGA $argv
end

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

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

function rm
	command rm -rf $argv
end

function mkdir
	command mkdir -p $argv
end

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

# nvim
function vim
	command nvim $argv
end

# rsync options
function rsync
	command rsync -avzHE $argv
end

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

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

Make rm on macOS use trash

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

# better ls
function ls
	command ls -lhFG $argv
end

function la
	command ls -lhFGA $argv
end

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

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

function rm
  switch (uname)
    case Darwin
      command trash $argv
    case Linux
      command rm -rf $argv
    end
end

function mkdir
	command mkdir -p $argv
end

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

# nvim
function vim
	command nvim $argv
end

# rsync options
function rsync
	command rsync -avzHE $argv
end

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

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


function gco --description="git checkout"
  if test -z (command git rev-parse --show-toplevel 2> /dev/null)
    set_color red
    echo "Not in a git repository"
    set_color normal
    return 1
  end

  set -l arguments

  set -l cmd "git branch --no-color | command sed -E 's/^\*? ? //g'"

  eval "$GISH_DIR/fish/include/parse $argv"

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

    if test (count $arguments) -gt 1
      set_color yellow
      echo "Too many matches"
      echo "Refine your query please"
      set_color normal
      return 1
    end
  end

  if test (count $arguments) -eq 0
    set_color red
    echo "No matches found"
    set_color normal
    return 0
  end

  if test (count (git branch --no-color | command grep "* $arguments")) -eq 1
    set_color yellow
    echo "Already on branch '$arguments'"
    set_color normal
    return 0
  end

  command git checkout $OPTV $arguments > /dev/null

  set_color green
  echo "Swiched to branch '$arguments'"
  set_color normal

  gs
end

Use the `--quiet` option when appropriate

function gco --description="git checkout"
  if test -z (command git rev-parse --show-toplevel 2> /dev/null)
    set_color red
    echo "Not in a git repository"
    set_color normal
    return 1
  end

  set -l arguments

  set -l cmd "git branch --no-color | command sed -E 's/^\*? ? //g'"

  eval "$GISH_DIR/fish/include/parse $argv"

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

    if test (count $arguments) -gt 1
      set_color yellow
      echo "Too many matches"
      echo "Refine your query please"
      set_color normal
      return 1
    end
  end

  if test (count $arguments) -eq 0
    set_color red
    echo "No matches found"
    set_color normal
    return 0
  end

  if test (count (git branch --no-color | command grep "* $arguments")) -eq 1
    set_color yellow
    echo "Already on branch '$arguments'"
    set_color normal
    return 0
  end

  command git checkout --quiet $OPTV $arguments

  set_color green
  echo "Swiched to branch '$arguments'"
  set_color normal

  gs
end


# Aliases
alias ll="exa -lg --group-directories-first"

abbr --add g git
abbr --add v nvim
abbr --add tree "ll --tree"

Disable python virtualenv prompt in fish

# Aliases
alias ll="exa -lg --group-directories-first"

abbr --add g git
abbr --add v nvim
abbr --add tree "ll --tree"

set -gx VIRTUAL_ENV_DISABLE_PROMPT 1


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

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

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

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

  if [ (_git_branch_name) ]

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

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

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

Use red color to indicate master branch

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

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

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

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

  if [ (_git_branch_name) ]

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

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

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


#!/usr/bin/env fish

set fish_greeting
set -x GOPATH $HOME/Code/gopkg
set -x MAILDIR $HOME/mail
set -x EDITOR vim
set -x MANPAGER vimpager
set -x GEM_HOME $HOME/.local/gems/(ruby -v | awk '{print $2}')
set -x GEM_PATH $GEM_HOME
set -x HAXELIB_PATH /usr/local/lib/haxelib
set -x HAXE_STD_PATH /usr/local/lib/haxe/std
set -x COCOAPODS_DISABLE_STATS 1
set -x PIP_REQUIRE_VIRTUALENV 1
set -x PKG_CONFIG_PATH /usr/local/lib/pkgconfig /usr/local/lib
set -x PATH $GEM_HOME/bin $HOME/bin /usr/local/bin /usr/local/sbin \
            /bin /usr/bin /usr/sbin /sbin $GOPATH/bin /usr/local/go/bin

source /usr/local/share/chruby/chruby.fish
source $HOME/.config/fish/functions/aliases.fish
status --is-interactive; and . (swiftenv init -|psub)
status --is-interactive; and . (pyenv init -|psub)

Disable homebrew updating and analytics

#!/usr/bin/env fish

set fish_greeting
set -x GOPATH $HOME/Code/gopkg
set -x MAILDIR $HOME/mail
set -x EDITOR vim
set -x MANPAGER vimpager
set -x GEM_HOME $HOME/.local/gems/(ruby -v | awk '{print $2}')
set -x GEM_PATH $GEM_HOME
set -x HAXELIB_PATH /usr/local/lib/haxelib
set -x HAXE_STD_PATH /usr/local/lib/haxe/std
set -x COCOAPODS_DISABLE_STATS 1
set -x PIP_REQUIRE_VIRTUALENV 1
set -x HOMEBREW_NO_AUTO_UPDATE 1
set -x HOMEBREW_NO_ANALYTICS 1
set -x PKG_CONFIG_PATH /usr/local/lib/pkgconfig /usr/local/lib
set -x PATH $GEM_HOME/bin $HOME/bin /usr/local/bin /usr/local/sbin \
            /bin /usr/bin /usr/sbin /sbin $GOPATH/bin /usr/local/go/bin

source /usr/local/share/chruby/chruby.fish
source $HOME/.config/fish/functions/aliases.fish
status --is-interactive; and . (swiftenv init -|psub)
status --is-interactive; and . (pyenv init -|psub)


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

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

Use vi keybindings in fish.

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"


set PATH (brew --prefix coreutils)/libexec/gnubin $PATH
set PATH ~/bin $PATH
set PATH $PATH ~/.cask/bin

# http://www.martinklepsch.org/posts/git-prompt-for-fish-shell.html
set __fish_git_prompt_showdirtystate 'yes'
set __fish_git_prompt_char_dirtystate '⚡'

# initialize rvm (uses rvm.fish)
rvm current 1>/dev/null 2>&1

# smart cased pt
function pt
  command pt --smart-case $argv
end

### Prompt

function fish_prompt
  set_color red
  echo -n "❯"
  set_color yellow
  echo -n "❯"
  set_color green
  echo -n "❯ "
end

function fish_right_prompt
  set_color blue
  echo -n (prompt_pwd)
  set_color green
  echo -n (__fish_git_prompt)
  set_color normal
end

### fasd support

function -e fish_preexec _run_fasd
  fasd --proc (fasd --sanitize "$argv") > "/dev/null" 2>&1
end

function j
  cd (fasd -d -e 'printf %s' "$argv")
end

if test -e ~/.iterm2_shell_integration.fish
  source ~/.iterm2_shell_integration.fish
end

Add go setup for fish shell

set PATH (brew --prefix coreutils)/libexec/gnubin $PATH
set PATH ~/bin $PATH
set PATH $PATH ~/.cask/bin

if test -e ~/.go
  set -x GOPATH ~/.go
  set PATH $PATH $GOPATH/bin
end

# http://www.martinklepsch.org/posts/git-prompt-for-fish-shell.html
set __fish_git_prompt_showdirtystate 'yes'
set __fish_git_prompt_char_dirtystate '⚡'

# initialize rvm (uses rvm.fish)
rvm current 1>/dev/null 2>&1

# smart cased pt
function pt
  command pt --smart-case $argv
end

### Prompt

function fish_prompt
  set_color red
  echo -n "❯"
  set_color yellow
  echo -n "❯"
  set_color green
  echo -n "❯ "
end

function fish_right_prompt
  set_color blue
  echo -n (prompt_pwd)
  set_color green
  echo -n (__fish_git_prompt)
  set_color normal
end

### fasd support

function -e fish_preexec _run_fasd
  fasd --proc (fasd --sanitize "$argv") > "/dev/null" 2>&1
end

function j
  cd (fasd -d -e 'printf %s' "$argv")
end

if test -e ~/.iterm2_shell_integration.fish
  source ~/.iterm2_shell_integration.fish
end


# Save a function to user's autoload dir.
function fs --argument-names function_name
    set -l dest_file ~/.config/fish/functions/$function_name.fish
    set -l original_contents
    set -l comment_lines

    if test -e $dest_file
        set original_contents (cat $dest_file)
        for line in $original_contents
            # Collect lines starting with a hash
            if test '#' = (string sub --length 1 $line)
                set comment_lines $comment_lines $line
            end
        end
        # echo comments:\n$comment_lines
    end

    funcsave $function_name

    if test -n $comment_lines
        # Read in the new function definition
        set -l new_contents (cat $dest_file)

        # Wipe out the file with the original comments
        echo -n $comment_lines\n >$dest_file

        # Filter the new content to fix indentation
        for line in $new_contents
            set -l first_char (string sub --length 1 $line)
            set -l all_after_first_char (string sub --start 1 $line)

            if test \t = $first_char
                # Skip the tab on the first line of the function body
                # Somehow the \t takes up 2 chars?
                echo "    "(string sub --start 2 $line) >>$dest_file
            else
                echo $all_after_first_char >>$dest_file
            end
        end
        # echo "Comments restored"
    end

    cat $dest_file
end

Use fish_indent to fix funcsave output

# Save a function to user's autoload dir.
function fs --argument function_name
    set -l dest_file ~/.config/fish/functions/$function_name.fish
    set -l original_contents
    set -l comment_lines

    if test -e $dest_file
        set original_contents (cat $dest_file)
        for line in $original_contents
            # Collect lines starting with a hash
            if test '#' = (string sub --length 1 $line)
                set comment_lines $comment_lines $line
            end
        end
    end

    funcsave $function_name

    if test -n $comment_lines
        # Read in the new function definition
        set -l new_contents (cat $dest_file)

        # Wipe out the file with the original comments
        echo -n $comment_lines\n >$dest_file
        echo -n $new_contents\n >>$dest_file
    end

    # Fix the funky indentation (tab on first line of body, extra space on all)
    fish_indent --write $dest_file

    cat $dest_file
end


echo " *** Loading env ***"
set -gx EDITOR /usr/local/bin/vim
set -gx BUNDLER_EDITOR $EDITOR
set -gx TERM "screen-256color"

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

set -gx COPYFILE_DISABLE true

# PATH {{{
append-to-path ~/bin
prepend-to-path /usr/local/sbin
# }}}

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

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

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

Add Postgres.app to the fish path

echo " *** Loading env ***"
set -gx EDITOR /usr/local/bin/vim
set -gx BUNDLER_EDITOR $EDITOR
set -gx TERM "screen-256color"

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

set -gx COPYFILE_DISABLE true

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

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

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

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


if which emacs > /dev/null
    set --global --export EDITOR emacs
else if which subl > /dev/null
    set --global --export EDITOR 'subl --wait'
else
    set --global --export EDITOR vim
end

Use Emacs in daemon mode

if which emacs > /dev/null
    set --global --export EDITOR "emacsclient -t"
    set --global --export ALTERNATE_EDITOR ''

    alias e='emacsclient -t'
    alias ec='emacsclient -c'
    alias vim='emacsclient -t'
    alias vi='emacsclient -t'
else if which subl > /dev/null
    set --global --export EDITOR 'subl --wait'
else
    set --global --export EDITOR vim
end


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

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

#
# Tweaks
#

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

#
# Aliases
#

alias vimf 'f -e vim' # Search files with fasd and then open them with vim

Add aliases to open files/dirs in Atom and Sublime using fasd

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

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

#
# Tweaks
#

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

#
# Aliases
#

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


function fish_right_prompt -d "Right side prompt message"

    # A dark grey
    set --local dark_grey 555

    set_color $dark_grey

    show_git_info
    echo -en (date +%H:%M:%S)

    set_color normal
end

function show_git_info -d "Show git repository information"

    set --local LIMBO /dev/null
    set --local git_status (git status --porcelain 2> $LIMBO)
    set --local dirty ""

    [ $status -eq 128 ]; and return  # Not a repository? Nothing to do

    # If there is modifications, set repository dirty to '*'
    if not [ -z (echo "$git_status" | grep -e '^ M') ]
        set dirty "*"
    end

    # If there is new or deleted files, add  '+' to dirty
    if not [ -z (echo "$git_status" | grep -e '^[MDA]') ]
        set dirty "$dirty+"
    end

    # If there is stashed modifications on repository, add '^' to dirty
    if not [ -z (git stash list) ]
        set dirty "$dirty^"
    end

    # Prints git repository status
    echo -en "("
    echo -en (git rev-parse --abbrev-ref HEAD)$dirty
    echo -en ") "
end

Add support to virtualenv. Display the name of the current virtualenv on the right side of prompt between brackets.

function fish_right_prompt -d "Right side prompt message"

    # A dark grey
    set --local dark_grey 555

    set_color $dark_grey

    show_virtualenv_name
    show_git_info
    echo -en (date +%H:%M:%S)

    set_color normal
end

function show_virtualenv_name -d "Display the name of the current virtualenv"

    if set -q VIRTUAL_ENV
        echo -en "["(basename "$VIRTUAL_ENV")"] "
    end
end

function show_git_info -d "Show git repository information"

    set --local LIMBO /dev/null
    set --local git_status (git status --porcelain 2> $LIMBO)
    set --local dirty ""

    [ $status -eq 128 ]; and return  # Not a repository? Nothing to do

    # If there is modifications, set repository dirty to '*'
    if not [ -z (echo "$git_status" | grep -e '^ M') ]
        set dirty "*"
    end

    # If there is new or deleted files, add  '+' to dirty
    if not [ -z (echo "$git_status" | grep -e '^[MDA]') ]
        set dirty "$dirty+"
    end

    # If there is stashed modifications on repository, add '^' to dirty
    if not [ -z (git stash list) ]
        set dirty "$dirty^"
    end

    # Prints git repository status
    echo -en "("
    echo -en (git rev-parse --abbrev-ref HEAD)$dirty
    echo -en ") "
end


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

    print-status delete-group "$argv"

    for policy in (attached-policies group "$group")
        detach-policy group "$group" "$policy"
    end

    for user in (actual-users-in-group "$group")
        delete-from-group "$group" "$user"
    end

    aws iam delete-group --group-name "$group"
end


function update-dotfiles --description "Updates the dotfiles"
# cd ~/dotfiles; git stash && git reup && git submodule update --init && git stash pop; printf "\n" && gem up && printf "\n" && gem cleanup; print "\n" && (cd ~/.rbenv/plugins/ruby-build; git up); (cd ~/Mjam/mjam-ios; git up); (cd ~/Mjam/mjam-android; g up); (cd ~/Mjam/django; g up); (cd ~/src/freebsd; g up); terminal-notifier -message "Finished upgrading dotfiles, Rubygems and repos" -title "Update finished"

	cd ~/dotfiles

	git stash; and git reup; and git submodule update --init; and git stash pop

	echo -e "\n"

	gem up; and	echo -e "\n"; and gem cleanup

	echo -e "\n"

	# Fish does not yet support subshells
	fish -c 'cd ~/.rbenv/plugins/ruby-build; and git up'
	fish -c 'cd ~/Mjam/mjam-ios; and git up'
	fish -c 'cd ~/Mjam/mjam-android; and git up'
	fish -c 'cd ~/Mjam/django; and git up'
	fish -c 'cd ~/src/freebsd; and git up'

	terminal-notifier -message "Finished upgrading dotfiles, Rubygems and repos" -title "Update finished"\n
end

Make 'update dotfiles' output a bit nicer to read

function update-dotfiles --description "Updates the dotfiles"
# cd ~/dotfiles; git stash && git reup && git submodule update --init && git stash pop; printf "\n" && gem up && printf "\n" && gem cleanup; print "\n" && (cd ~/.rbenv/plugins/ruby-build; git up); (cd ~/Mjam/mjam-ios; git up); (cd ~/Mjam/mjam-android; g up); (cd ~/Mjam/django; g up); (cd ~/src/freebsd; g up); terminal-notifier -message "Finished upgrading dotfiles, Rubygems and repos" -title "Update finished"

  cd ~/dotfiles

  git stash; and git reup; and git submodule update --init; and git stash pop

  echo -e "\n"

  gem up; and echo -e "\n"; and gem cleanup

  echo -e "\n"

  # Fish does not yet support subshells
  echo -e "Updating ruby-build..."
  fish -c 'cd ~/.rbenv/plugins/ruby-build; and git up'
  echo -e "\n\nUpdating mjam-ios..."
  fish -c 'cd ~/Mjam/mjam-ios; and git up'
  echo -e "\n\nUpdating mjam-android..."
  fish -c 'cd ~/Mjam/mjam-android; and git up'
  echo -e "\n\nUpdating django..."
  fish -c 'cd ~/Mjam/django; and git up'
  echo -e "\n\nUpdating FreeBSD"
  fish -c 'cd ~/src/freebsd; and git up'

  terminal-notifier -message "Finished upgrading dotfiles, Rubygems and repos" -title "Update finished"\n
end


# set Helix as the default editor
set --global --export EDITOR helix
set --global --export VISUAL helix

# colorize man pages
set --global --export MANPAGER 'less -R --use-color -Dd+g -Du+c'

# run `make` with as many jobs in parallel as there as processors
set --global --export MAKEFLAGS -j(nproc)

if test (count /etc/debuginfod/*.urls) -gt 0
    set --global --export DEBUGINFOD_URLS (cat /etc/debuginfod/*.urls)
end

# make `fzf` use fd(1)
set --global --export FZF_DEFAULT_COMMAND 'fd --type file --type symlink --hidden --exclude .git 2> /dev/null'

# make `ripgrep` read its config file
set --global --export RIPGREP_CONFIG_PATH $HOME/.config/ripgreprc

set --global --export DOTNET_CLI_TELEMETRY_OPTOUT 1

set fish_user_paths ~/.local/bin
set --global fisher_path $__fish_user_data_dir/fisher

Revert "fish/env: change the default editor to `helix`"

# set LunarVim as the default editor
set --global --export EDITOR lvim
set --global --export VISUAL lvim

# set LunarVim as the default diff tool
set --global --export DIFFPROG 'lvim -d'

# colorize man pages
set --global --export MANPAGER 'less -R --use-color -Dd+g -Du+c'

# run `make` with as many jobs in parallel as there as processors
set --global --export MAKEFLAGS -j(nproc)

if test (count /etc/debuginfod/*.urls) -gt 0
    set --global --export DEBUGINFOD_URLS (cat /etc/debuginfod/*.urls)
end

# make `fzf` use fd(1)
set --global --export FZF_DEFAULT_COMMAND 'fd --type file --type symlink --hidden --exclude .git 2> /dev/null'

# make `ripgrep` read its config file
set --global --export RIPGREP_CONFIG_PATH $HOME/.config/ripgreprc

set --global --export DOTNET_CLI_TELEMETRY_OPTOUT 1

set fish_user_paths ~/.local/bin
set --global fisher_path $__fish_user_data_dir/fisher


# Short alias for installing gems using Bundler.
function brew_update
    # This can only be run by an admin user
    if not user_is_admin
        exit 1
    end

    brew update
    and brew upgrade

    firewall_allow_nginx
end

Check for ownership of brew home instead of admin status

# Short alias for installing gems using Bundler.
function brew_update
    # Verify the user owns the Homebrew dir.
    set brew_home (brew --prefix)
    if not test (stat -f%u $brew_home) -eq (id -u $USER)
        echo "You must be the owner of $brew_home to run this command."
        return 1
    end

    brew update
    and brew upgrade

    firewall_allow_nginx
end