Add fish, tmux, vim, and git dotfiles; clean up

This commit is contained in:
mitchell 2019-08-15 00:44:46 -04:00
commit e57d8318d9
47 changed files with 2125 additions and 0 deletions

View file

@ -0,0 +1,3 @@
function cp
rsync -aP $argv
end

View file

@ -0,0 +1,10 @@
function fish_greeting -d "What's up, fish?"
set_color $fish_color_autosuggestion
uname -nmsr
# TODO: `command -q -s` only works on fish 2.5+, so hold off on that for now
command -s uptime >/dev/null
and uptime
set_color normal
end

View file

@ -0,0 +1,3 @@
function fish_mode_prompt
end

View file

@ -0,0 +1,158 @@
function fish_prompt --description 'Write out the prompt'
set -l last_status $status
set -l color_cwd
set -l suffix
set -l user_prefix
set -l git_branch
set -l go_version
set -l docker_version
set -l node_version
set -l ex_version
set -l dart_version
set -l flutter_version
set -l jobs_num
set -l exit_code
# Set exit code, based on last command status
if test $last_status -ne 0
set exit_code '<' (set_color $fish_color_status) $last_status (set_color normal) '> '
end
# Set jobs num, based on exit code of jobs command
if jobs > /dev/null
set -l jobs_out (jobs -c)
set jobs_num '[' (set_color brblack) (count $jobs_out) (set_color normal) '] '
end
# Set cwd color and prompt suffix, based on current user and fish_bind_mode.
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 '#~>'
if test $fish_key_bindings = 'fish_vi_key_bindings'
switch "$fish_bind_mode"
case 'insert'
set suffix (set_color brblue) $suffix (set_color normal)
case 'default'
set suffix '###'
case 'visual'
set suffix (set_color bryellow) '<~#' (set_color normal)
end
end
case '*'
set color_cwd $fish_color_cwd
set suffix '~~>'
if test $fish_key_bindings = 'fish_vi_key_bindings'
switch "$fish_bind_mode"
case 'insert'
set suffix (set_color brblue) $suffix (set_color normal)
case 'default'
set suffix '<~>'
case 'visual'
set suffix (set_color bryellow) '<~~' (set_color normal)
end
end
end
# Set user_prefix, based on whether or not inside of ssh session.
if test -n "$SSH_CLIENT"; set user_prefix $USER @ (prompt_hostname) ' '; end
# Show current git branch, based on git commands only.
if git branch --show-current > /dev/null 2> /dev/null
set -l branch_color green
set -l git_status (git status)
if string match 'Changes not staged for commit:' $git_status > /dev/null
or string match 'Untracked files:' $git_status > /dev/null
set branch_color red
else if string match 'Changes to be committed:' $git_status > /dev/null
set branch_color yellow
end
set -l cur_branch (git branch --show-current)
if test -z $cur_branch; set cur_branch 'detached'; end
set -l cur_branch_len (string length $cur_branch)
if test $cur_branch_len -gt 21
set -l sub_str (string sub -s (math $cur_branch_len - 17) -l 18 $cur_branch)
set cur_branch "...$sub_str"
end
if string match 'Your branch is ahead of*' $git_status > /dev/null
set cur_branch $cur_branch \u21A5
else if string match 'Your branch is behind*' $git_status > /dev/null
set cur_branch $cur_branch \u21A7
end
set git_branch ' on ' (set_color $branch_color) $cur_branch (set_color normal)
end
# Set go version, by existence of go mod or dep files
if test -e ./go.mod; or test -e ./Gopkg.toml
set -l version_str (string match -r 'go\d+\.\d+\.?\d*' (go version))
set go_version ' with ' (set_color 8eadaf) $version_str (set_color normal)
end
# Set docker version, by existence of Dockerfile
if test -e ./Dockerfile
set -l version_str (string match -r '\d+\.\d+\.?\d*' (docker --version))
set docker_version ' on ' (set_color blue) 'docker' $version_str (set_color normal)
end
# Set user prefix, based on docker machine name
if test -n "$DOCKER_MACHINE_NAME"
set user_prefix (set_color blue) $DOCKER_MACHINE_NAME (set_color normal) ' '
end
# Set node (and ts) version, based on existance of package.json (and tsconfig.json)
if test -e ./package.json
set -l version_str (string sub -s 2 (node -v))
set node_version ' with ' (set_color brgreen) 'node' $version_str (set_color normal)
if test -e ./tsconfig.json
set -l version_str (string match -r '\d+\.\d+\.?\d*' (tsc -v))
set node_version $node_version ' and ' (set_color cyan) 'ts' $version_str (set_color normal)
end
end
# Set elixir version, based on existance of mix.exs
if test -e ./mix.exs
set -l version_str (string sub -s 8 (string match -r 'Elixir \d+\.\d+\.?\d*' (elixir -v)))
set ex_version ' with ' (set_color magenta) 'ex' $version_str (set_color normal)
end
# Set dart version, based on existances of pubspec.yaml
if test -e ./pubspec.yaml
set -l version_str (string match -r '\d+\.\d+\.?\d*' (dart --version 2>| cat))
set dart_version ' with ' (set_color brblue) 'dart' $version_str (set_color normal)
if cat pubspec.yaml | grep flutter > /dev/null
set -l version_str (string sub -s 9 (string match -r 'Flutter \d+\.\d+\.?\d*' (flutter --version)))
set flutter_version ' on ' (set_color blue) 'flutter' $version_str (set_color normal)
end
end
# Combine all prompt variables
set -l cwd (set_color $color_cwd) (prompt_pwd) (set_color normal)
set -l top_prompt $cwd $git_branch $go_version $ex_version $node_version $dart_version $flutter_version $docker_version
set -l bottom_prompt $user_prefix $jobs_num $exit_code $suffix ' '
# Decide whether to insert newline, based on whether the top prompt is only equal to cwd
if test "$top_prompt" = "$cwd"
set bottom_prompt ' ' $bottom_prompt
else
set bottom_prompt \n $bottom_prompt
end
echo -n -s $top_prompt
echo -n -s $bottom_prompt
end

View file

@ -0,0 +1,82 @@
# Borrowed from bobthefish theme (https://github.com/oh-my-fish/theme-bobthefish).
# Copyright (c) 2013-2014 Justin Hileman.
#
# Modifications:
# - Remove lines 75, 76, 78 of original file. Setting '<' as the default left arrow glyph.
#
# You can override some default right prompt options in your config.fish:
# set -g theme_date_format "+%a %H:%M"
function __bobthefish_cmd_duration -S -d 'Show command duration'
[ "$theme_display_cmd_duration" = "no" ]
and return
[ -z "$CMD_DURATION" -o "$CMD_DURATION" -lt 100 ]
and return
if [ "$CMD_DURATION" -lt 5000 ]
echo -ns $CMD_DURATION 'ms'
else if [ "$CMD_DURATION" -lt 60000 ]
__bobthefish_pretty_ms $CMD_DURATION s
else if [ "$CMD_DURATION" -lt 3600000 ]
set_color $fish_color_error
__bobthefish_pretty_ms $CMD_DURATION m
else
set_color $fish_color_error
__bobthefish_pretty_ms $CMD_DURATION h
end
set_color $fish_color_normal
set_color $fish_color_autosuggestion
[ "$theme_display_date" = "no" ]
or echo -ns ' ' $__bobthefish_left_arrow_glyph
end
function __bobthefish_pretty_ms -S -a ms -a interval -d 'Millisecond formatting for humans'
set -l interval_ms
set -l scale 1
switch $interval
case s
set interval_ms 1000
case m
set interval_ms 60000
case h
set interval_ms 3600000
set scale 2
end
switch $FISH_VERSION
case 2.0.\* 2.1.\* 2.2.\* 2.3.\*
# Fish 2.3 and lower doesn't know about the -s argument to math.
math "scale=$scale;$ms/$interval_ms" | string replace -r '\\.?0*$' $interval
case 2.\*
# Fish 2.x always returned a float when given the -s argument.
math -s$scale "$ms/$interval_ms" | string replace -r '\\.?0*$' $interval
case \*
math -s$scale "$ms/$interval_ms"
echo -ns $interval
end
end
function __bobthefish_timestamp -S -d 'Show the current timestamp'
[ "$theme_display_date" = "no" ]
and return
set -q theme_date_format
or set -l theme_date_format "+%c"
echo -n ' '
date $theme_date_format
end
function fish_right_prompt -d 'bobthefish is all about the right prompt'
set __bobthefish_left_arrow_glyph '<'
set_color $fish_color_autosuggestion
__bobthefish_cmd_duration
__bobthefish_timestamp
set_color normal
end

View file

@ -0,0 +1,278 @@
function fish_vi_key_bindings --description 'vi-like key bindings for fish'
if contains -- -h $argv
or contains -- --help $argv
echo "Sorry but this function doesn't support -h or --help"
return 1
end
# Erase all bindings if not explicitly requested otherwise to
# allow for hybrid bindings.
# This needs to be checked here because if we are called again
# via the variable handler the argument will be gone.
set -l rebind true
if test "$argv[1]" = "--no-erase"
set rebind false
set -e argv[1]
else
bind --erase --all --preset # clear earlier bindings, if any
end
# Allow just calling this function to correctly set the bindings.
# Because it's a rather discoverable name, users will execute it
# and without this would then have subtly broken bindings.
if test "$fish_key_bindings" != "fish_vi_key_bindings"
and test "$rebind" = "true"
# Allow the user to set the variable universally.
set -q fish_key_bindings
or set -g fish_key_bindings
# This triggers the handler, which calls us again and ensures the user_key_bindings
# are executed.
set fish_key_bindings fish_vi_key_bindings
return
end
# The default escape timeout is 300ms. But for users of Vi bindings that can be slightly
# annoying when trying to switch to Vi "normal" mode. So set a shorter timeout in this case
# unless the user has explicitly set the delay.
set -q fish_escape_delay_ms
or set -g fish_escape_delay_ms 100
set -l init_mode insert
# These are only the special vi-style keys
# not end/home, we share those.
set -l eol_keys \$ g\$
set -l bol_keys \^ 0 g\^
if contains -- $argv[1] insert default visual
set init_mode $argv[1]
else if set -q argv[1]
# We should still go on so the bindings still get set.
echo "Unknown argument $argv" >&2
end
# Inherit shared key bindings.
# Do this first so vi-bindings win over default.
for mode in insert default visual
__fish_shared_key_bindings -M $mode
end
bind -s --preset -M insert \r execute
bind -s --preset -M insert \n execute
bind -s --preset -M insert "" self-insert
# Add way to kill current command line while in insert mode.
bind -s --preset -M insert \cc __fish_cancel_commandline
# Add a way to switch from insert to normal (command) mode.
# Note if we are paging, we want to stay in insert mode
# See #2871
bind -s --preset -M insert jj "if commandline -P; commandline -f cancel; else; set fish_bind_mode default; commandline -f backward-char force-repaint; end"
# Default (command) mode
bind -s --preset :q exit
bind -s --preset -m insert \cc __fish_cancel_commandline
bind -s --preset -M default h backward-char
bind -s --preset -M default l forward-char
bind -s --preset -m insert \n execute
bind -s --preset -m insert \r execute
bind -s --preset -m insert i force-repaint
bind -s --preset -m insert I beginning-of-line force-repaint
bind -s --preset -m insert a forward-char force-repaint
bind -s --preset -m insert A end-of-line force-repaint
bind -s --preset -m visual v begin-selection force-repaint
#bind -s --preset -m insert o "commandline -a \n" down-line force-repaint
#bind -s --preset -m insert O beginning-of-line "commandline -i \n" up-line force-repaint # doesn't work
bind -s --preset gg beginning-of-buffer
bind -s --preset G end-of-buffer
for key in $eol_keys
bind -s --preset $key end-of-line
end
for key in $bol_keys
bind -s --preset $key beginning-of-line
end
bind -s --preset u history-search-backward
bind -s --preset \cr history-search-forward
bind -s --preset [ history-token-search-backward
bind -s --preset ] history-token-search-forward
bind -s --preset k up-or-search
bind -s --preset j down-or-search
bind -s --preset b backward-word
bind -s --preset B backward-bigword
bind -s --preset ge backward-word
bind -s --preset gE backward-bigword
bind -s --preset w forward-word forward-char
bind -s --preset W forward-bigword forward-char
bind -s --preset e forward-char forward-word backward-char
bind -s --preset E forward-bigword backward-char
# OS X SnowLeopard doesn't have these keys. Don't show an annoying error message.
# Vi/Vim doesn't support these keys in insert mode but that seems silly so we do so anyway.
bind -s --preset -M insert -k home beginning-of-line 2>/dev/null
bind -s --preset -M default -k home beginning-of-line 2>/dev/null
bind -s --preset -M insert -k end end-of-line 2>/dev/null
bind -s --preset -M default -k end end-of-line 2>/dev/null
# Vi moves the cursor back if, after deleting, it is at EOL.
# To emulate that, move forward, then backward, which will be a NOP
# if there is something to move forward to.
bind -s --preset -M default x delete-char forward-char backward-char
bind -s --preset -M default X backward-delete-char
bind -s --preset -M insert -k dc delete-char forward-char backward-char
bind -s --preset -M default -k dc delete-char forward-char backward-char
# Backspace deletes a char in insert mode, but not in normal/default mode.
bind -s --preset -M insert -k backspace backward-delete-char
bind -s --preset -M default -k backspace backward-char
bind -s --preset -M insert \ch backward-delete-char
bind -s --preset -M default \ch backward-char
bind -s --preset -M insert \x7f backward-delete-char
bind -s --preset -M default \x7f backward-char
bind -s --preset -M insert \e\[3\;2~ backward-delete-char # Mavericks Terminal.app shift-ctrl-delete
bind -s --preset -M default \e\[3\;2~ backward-delete-char # Mavericks Terminal.app shift-ctrl-delete
bind -s --preset dd kill-whole-line
bind -s --preset D kill-line
bind -s --preset d\$ kill-line
bind -s --preset d\^ backward-kill-line
bind -s --preset dw kill-word
bind -s --preset dW kill-bigword
bind -s --preset diw forward-char forward-char backward-word kill-word
bind -s --preset diW forward-char forward-char backward-bigword kill-bigword
bind -s --preset daw forward-char forward-char backward-word kill-word
bind -s --preset daW forward-char forward-char backward-bigword kill-bigword
bind -s --preset de kill-word
bind -s --preset dE kill-bigword
bind -s --preset db backward-kill-word
bind -s --preset dB backward-kill-bigword
bind -s --preset dge backward-kill-word
bind -s --preset dgE backward-kill-bigword
bind -s --preset df begin-selection forward-jump kill-selection end-selection
bind -s --preset dt begin-selection forward-jump backward-char kill-selection end-selection
bind -s --preset dF begin-selection backward-jump kill-selection end-selection
bind -s --preset dT begin-selection backward-jump forward-char kill-selection end-selection
bind -s --preset -m insert s delete-char force-repaint
bind -s --preset -m insert S kill-whole-line force-repaint
bind -s --preset -m insert cc kill-whole-line force-repaint
bind -s --preset -m insert C kill-line force-repaint
bind -s --preset -m insert c\$ kill-line force-repaint
bind -s --preset -m insert c\^ backward-kill-line force-repaint
bind -s --preset -m insert cw kill-word force-repaint
bind -s --preset -m insert cW kill-bigword force-repaint
bind -s --preset -m insert ciw forward-char forward-char backward-word kill-word force-repaint
bind -s --preset -m insert ciW forward-char forward-char backward-bigword kill-bigword force-repaint
bind -s --preset -m insert caw forward-char forward-char backward-word kill-word force-repaint
bind -s --preset -m insert caW forward-char forward-char backward-bigword kill-bigword force-repaint
bind -s --preset -m insert ce kill-word force-repaint
bind -s --preset -m insert cE kill-bigword force-repaint
bind -s --preset -m insert cb backward-kill-word force-repaint
bind -s --preset -m insert cB backward-kill-bigword force-repaint
bind -s --preset -m insert cge backward-kill-word force-repaint
bind -s --preset -m insert cgE backward-kill-bigword force-repaint
bind -s --preset '~' capitalize-word
bind -s --preset gu downcase-word
bind -s --preset gU upcase-word
bind -s --preset J end-of-line delete-char
bind -s --preset K 'man (commandline -t) 2>/dev/null; or echo -n \a'
bind -s --preset yy kill-whole-line yank
bind -s --preset Y kill-whole-line yank
bind -s --preset y\$ kill-line yank
bind -s --preset y\^ backward-kill-line yank
bind -s --preset yw kill-word yank
bind -s --preset yW kill-bigword yank
bind -s --preset yiw forward-char forward-char backward-word kill-word yank
bind -s --preset yiW forward-char forward-char backward-bigword kill-bigword yank
bind -s --preset yaw forward-char forward-char backward-word kill-word yank
bind -s --preset yaW forward-char forward-char backward-bigword kill-bigword yank
bind -s --preset ye kill-word yank
bind -s --preset yE kill-bigword yank
bind -s --preset yb backward-kill-word yank
bind -s --preset yB backward-kill-bigword yank
bind -s --preset yge backward-kill-word yank
bind -s --preset ygE backward-kill-bigword yank
bind -s --preset f forward-jump
bind -s --preset F backward-jump
bind -s --preset t forward-jump-till
bind -s --preset T backward-jump-till
bind -s --preset ';' repeat-jump
bind -s --preset , repeat-jump-reverse
# in emacs yank means paste
bind -s --preset p yank
bind -s --preset P backward-char yank
bind -s --preset gp yank-pop
bind -s --preset '"*p' "commandline -i ( xsel -p; echo )[1]"
bind -s --preset '"*P' backward-char "commandline -i ( xsel -p; echo )[1]"
#
# Lowercase r, enters replace_one mode
#
bind -s --preset -m replace_one r force-repaint
bind -s --preset -M replace_one -m default '' delete-char self-insert backward-char force-repaint
bind -s --preset -M replace_one -m default \e cancel force-repaint
#
# visual mode
#
bind -s --preset -M visual h backward-char
bind -s --preset -M visual l forward-char
bind -s --preset -M visual k up-line
bind -s --preset -M visual j down-line
bind -s --preset -M visual b backward-word
bind -s --preset -M visual B backward-bigword
bind -s --preset -M visual ge backward-word
bind -s --preset -M visual gE backward-bigword
bind -s --preset -M visual w forward-word
bind -s --preset -M visual W forward-bigword
bind -s --preset -M visual e forward-word
bind -s --preset -M visual E forward-bigword
bind -s --preset -M visual o swap-selection-start-stop force-repaint
bind -s --preset -M visual f forward-jump
bind -s --preset -M visual t forward-jump-till
bind -s --preset -M visual F backward-jump
bind -s --preset -M visual T backward-jump-till
for key in $eol_keys
bind -s --preset -M visual $key end-of-line
end
for key in $bol_keys
bind -s --preset -M visual $key beginning-of-line
end
bind -s --preset -M visual -m insert c kill-selection end-selection force-repaint
bind -s --preset -M visual -m default d kill-selection end-selection force-repaint
bind -s --preset -M visual -m default x kill-selection end-selection force-repaint
bind -s --preset -M visual -m default X kill-whole-line end-selection force-repaint
bind -s --preset -M visual -m default y kill-selection yank end-selection force-repaint
bind -s --preset -M visual -m default '"*y' "commandline -s | xsel -p; commandline -f end-selection force-repaint"
bind -s --preset -M visual -m default \cc end-selection force-repaint
bind -s --preset -M visual -m default \e end-selection force-repaint
# Make it easy to turn an unexecuted command into a comment in the shell history. Also, remove
# the commenting chars so the command can be further edited then executed.
bind -s --preset -M default \# __fish_toggle_comment_commandline
bind -s --preset -M visual \# __fish_toggle_comment_commandline
# Set the cursor shape
# After executing once, this will have defined functions listening for the variable.
# Therefore it needs to be before setting fish_bind_mode.
fish_vi_cursor
set fish_bind_mode $init_mode
end

View file

@ -0,0 +1,430 @@
set -g fisher_version 3.2.9
function fisher -a cmd -d "fish package manager"
set -q XDG_CACHE_HOME; or set XDG_CACHE_HOME ~/.cache
set -q XDG_CONFIG_HOME; or set XDG_CONFIG_HOME ~/.config
set -g fish_config $XDG_CONFIG_HOME/fish
set -g fisher_cache $XDG_CACHE_HOME/fisher
set -g fisher_config $XDG_CONFIG_HOME/fisher
set -q fisher_path; or set -g fisher_path $fish_config
for path in {$fish_config,$fisher_path}/{functions,completions,conf.d} $fisher_cache
if test ! -d $path
command mkdir -p $path
end
end
if test ! -e $fisher_path/completions/fisher.fish
echo "fisher complete" >$fisher_path/completions/fisher.fish
_fisher_complete
end
if test -e $fisher_path/conf.d/fisher.fish
switch "$version"
case \*-\*
command rm -f $fisher_path/conf.d/fisher.fish
case 2\*
case \*
command rm -f $fisher_path/conf.d/fisher.fish
end
else
switch "$version"
case \*-\*
case 2\*
echo "fisher copy-user-key-bindings" >$fisher_path/conf.d/fisher.fish
end
end
switch "$cmd"
case {,self-}complete
_fisher_complete
case copy-user-key-bindings
_fisher_copy_user_key_bindings
case ls
set -e argv[1]
if test -s "$fisher_path/fishfile"
set -l file (_fisher_fmt <$fisher_path/fishfile | _fisher_parse -R | command sed "s|@.*||")
_fisher_ls | _fisher_fmt | command awk -v FILE="$file" "
BEGIN { for (n = split(FILE, f); ++i <= n;) file[f[i]] } \$0 in file && /$argv[1]/
" | command sed "s|^$HOME|~|"
end
case self-update
_fisher_self_update (status -f)
case self-uninstall
_fisher_self_uninstall
case {,-}-v{ersion,}
echo "fisher version $fisher_version" (status -f | command sed "s|^$HOME|~|")
case {,-}-h{elp,}
_fisher_help
case ""
_fisher_commit --
case add rm
if not isatty
while read -l arg
set argv $argv $arg
end
end
if test (count $argv) = 1
echo "fisher: invalid number of arguments" >&2
_fisher_help >&2
return 1
end
_fisher_commit $argv
case \*
echo "fisher: unknown flag or command \"$cmd\"" >&2
_fisher_help >&2
return 1
end
end
function _fisher_complete
complete -ec fisher
complete -xc fisher -n __fish_use_subcommand -a add -d "Add packages"
complete -xc fisher -n __fish_use_subcommand -a rm -d "Remove packages"
complete -xc fisher -n __fish_use_subcommand -a ls -d "List installed packages matching REGEX"
complete -xc fisher -n __fish_use_subcommand -a --help -d "Show usage help"
complete -xc fisher -n __fish_use_subcommand -a --version -d "$fisher_version"
complete -xc fisher -n __fish_use_subcommand -a self-update -d "Update to the latest version"
for pkg in (fisher ls)
complete -xc fisher -n "__fish_seen_subcommand_from rm" -a $pkg
end
end
function _fisher_copy_user_key_bindings
if functions -q fish_user_key_bindings
functions -c fish_user_key_bindings fish_user_key_bindings_copy
end
function fish_user_key_bindings
for file in $fisher_path/conf.d/*_key_bindings.fish
source $file >/dev/null 2>/dev/null
end
if functions -q fish_user_key_bindings_copy
fish_user_key_bindings_copy
end
end
end
function _fisher_ls
for pkg in $fisher_config/*/*/*
command readlink $pkg; or echo $pkg
end
end
function _fisher_fmt
command sed "s|^[[:space:]]*||;s|^$fisher_config/||;s|^~|$HOME|;s|^\.\/*|$PWD/|;s|^https*:/*||;s|^github\.com/||;s|/*\$||"
end
function _fisher_help
echo "usage: fisher add <package...> Add packages"
echo " fisher rm <package...> Remove packages"
echo " fisher Update all packages"
echo " fisher ls [<regex>] List installed packages matching <regex>"
echo " fisher --help Show this help"
echo " fisher --version Show the current version"
echo " fisher self-update Update to the latest version"
echo " fisher self-uninstall Uninstall from your system"
echo "examples:"
echo " fisher add jethrokuan/z rafaelrinaldi/pure"
echo " fisher add gitlab.com/foo/bar@v2"
echo " fisher add ~/path/to/local/pkg"
echo " fisher add <file"
echo " fisher rm rafaelrinaldi/pure"
echo " fisher ls | fisher rm"
echo " fisher ls fish-\*"
end
function _fisher_self_update -a file
set -l url "https://raw.githubusercontent.com/jorgebucaran/fisher/master/fisher.fish"
echo "fetching $url" >&2
command curl -s "$url?nocache" >$file.
set -l next_version (command awk '{ print $4 } { exit }' <$file.)
switch "$next_version"
case "" $fisher_version
command rm -f $file.
if test -z "$next_version"
echo "fisher: cannot update fisher -- are you offline?" >&2
return 1
end
echo "fisher is already up-to-date" >&2
case \*
echo "linking $file" | command sed "s|$HOME|~|" >&2
command mv -f $file. $file
source $file
echo "updated to fisher $fisher_version -- hooray!" >&2
_fisher_complete
end
end
function _fisher_self_uninstall
for pkg in (_fisher_ls)
_fisher_rm $pkg
end
for file in $fisher_cache $fisher_config $fisher_path/{functions,completions,conf.d}/fisher.fish $fisher_path/fishfile
echo "removing $file"
command rm -Rf $file 2>/dev/null
end | command sed "s|$HOME|~|" >&2
for name in (set -n | command awk '/^fisher_/')
set -e "$name"
end
functions -e (functions -a | command awk '/^_fisher/') fisher
complete -c fisher --erase
end
function _fisher_commit -a cmd
set -e argv[1]
set -l elapsed (_fisher_now)
set -l fishfile $fisher_path/fishfile
if test ! -e "$fishfile"
command touch $fishfile
echo "created new fishfile in $fishfile" | command sed "s|$HOME|~|" >&2
end
set -l old_pkgs (_fisher_ls | _fisher_fmt)
for pkg in (_fisher_ls)
_fisher_rm $pkg
end
command rm -Rf $fisher_config
command mkdir -p $fisher_config
set -l next_pkgs (_fisher_fmt <$fishfile | _fisher_parse -R $cmd (printf "%s\n" $argv | _fisher_fmt))
set -l actual_pkgs (_fisher_fetch $next_pkgs)
set -l updated_pkgs
for pkg in $old_pkgs
if contains -- $pkg $actual_pkgs
set updated_pkgs $updated_pkgs $pkg
end
end
if test -z "$actual_pkgs$updated_pkgs$old_pkgs$next_pkgs"
echo "fisher: nothing to commit -- try adding some packages" >&2
return 1
end
set -l out_pkgs
if test "$cmd" = "rm"
set out_pkgs $next_pkgs
else
for pkg in $next_pkgs
if contains -- (echo $pkg | command sed "s|@.*||") $actual_pkgs
set out_pkgs $out_pkgs $pkg
end
end
end
printf "%s\n" (_fisher_fmt <$fishfile | _fisher_parse -W $cmd $out_pkgs | command sed "s|^$HOME|~|") >$fishfile
_fisher_complete
command awk -v A=(count $actual_pkgs) -v U=(count $updated_pkgs) -v O=(count $old_pkgs) -v E=(_fisher_now $elapsed) '
BEGIN {
res = fmt("removed", O - U, fmt("updated", U, fmt("added", A - U)))
printf((res ? res : "done") " in %.2fs\n", E / 1000)
}
function fmt(action, n, s) {
return n ? (s ? s ", " : s) action " " n " package" (n > 1 ? "s" : "") : s
}
' >&2
end
function _fisher_parse -a mode cmd
set -e argv[1..2]
command awk -v FS="[[:space:]]*#+" -v MODE="$mode" -v CMD="$cmd" -v ARGSTR="$argv" '
BEGIN {
for (n = split(ARGSTR, a, " "); i++ < n;) pkgs[getkey(a[i])] = a[i]
}
!NF { next } { k = getkey($1) }
MODE == "-R" && !(k in pkgs) && $0 = $1
MODE == "-W" && (/^#/ || k in pkgs || CMD != "rm") { print pkgs[k] (sub($1, "") ? $0 : "") }
MODE == "-W" || CMD == "rm" { delete pkgs[k] }
END {
for (k in pkgs) {
if (CMD != "rm" || MODE == "-W") print pkgs[k]
else print "fisher: cannot remove \""k"\" -- package is not in fishfile" > "/dev/stderr"
}
}
function getkey(s, a) {
return (split(s, a, /@+|:/) > 2) ? a[2]"/"a[1]"/"a[3] : a[1]
}
'
end
function _fisher_fetch
set -l pkg_jobs
set -l out_pkgs
set -l next_pkgs
set -l local_pkgs
set -q fisher_user_api_token; and set -l curl_opts -u $fisher_user_api_token
for pkg in $argv
switch $pkg
case \~\* /\*
set -l path (echo "$pkg" | command sed "s|^~|$HOME|")
if test -e "$path"
set local_pkgs $local_pkgs $path
else
echo "fisher: cannot add \"$pkg\" -- is this a valid file?" >&2
end
continue
end
command awk -v PKG="$pkg" -v FS=/ '
BEGIN {
if (split(PKG, tmp, /@+|:/) > 2) {
if (tmp[4]) sub("@"tmp[4], "", PKG)
print PKG "\t" tmp[2]"/"tmp[1]"/"tmp[3] "\t" (tmp[4] ? tmp[4] : "master")
} else {
pkg = split(PKG, _, "/") <= 2 ? "github.com/"tmp[1] : tmp[1]
tag = tmp[2] ? tmp[2] : "master"
print (\
pkg ~ /^github/ ? "https://codeload."pkg"/tar.gz/"tag : \
pkg ~ /^gitlab/ ? "https://"pkg"/-/archive/"tag"/"tmp[split(pkg, tmp, "/")]"-"tag".tar.gz" : \
pkg ~ /^bitbucket/ ? "https://"pkg"/get/"tag".tar.gz" : pkg \
) "\t" pkg
}
}
' | read -l url pkg branch
if test ! -d "$fisher_config/$pkg"
fish -c "
echo fetching $url >&2
command mkdir -p $fisher_config/$pkg $fisher_cache/(command dirname $pkg)
if test ! -z \"$branch\"
command git clone $url $fisher_config/$pkg --branch $branch --depth 1 2>/dev/null
or echo fisher: cannot clone \"$url\" -- is this a valid url\? >&2
else if command curl $curl_opts -Ss -w \"\" $url 2>&1 | command tar -xzf- -C $fisher_config/$pkg 2>/dev/null
command rm -Rf $fisher_cache/$pkg
command mv -f $fisher_config/$pkg/* $fisher_cache/$pkg
command rm -Rf $fisher_config/$pkg
command cp -Rf {$fisher_cache,$fisher_config}/$pkg
else if test -d \"$fisher_cache/$pkg\"
echo fisher: cannot connect to server -- looking in \"$fisher_cache/$pkg\" | command sed 's|$HOME|~|' >&2
command cp -Rf $fisher_cache/$pkg $fisher_config/$pkg/..
else
command rm -Rf $fisher_config/$pkg
echo fisher: cannot add \"$pkg\" -- is this a valid package\? >&2
end
" >/dev/null &
set pkg_jobs $pkg_jobs (_fisher_jobs --last)
set next_pkgs $next_pkgs "$fisher_config/$pkg"
end
end
if set -q pkg_jobs[1]
while for job in $pkg_jobs
contains -- $job (_fisher_jobs); and break
end
end
for pkg in $next_pkgs
if test -d "$pkg"
set out_pkgs $out_pkgs $pkg
_fisher_add $pkg
end
end
end
set -l local_prefix $fisher_config/local/$USER
if test ! -d "$local_prefix"
command mkdir -p $local_prefix
end
for pkg in $local_pkgs
set -l target $local_prefix/(command basename $pkg)
if test ! -L "$target"
command ln -sf $pkg $target
set out_pkgs $out_pkgs $pkg
_fisher_add $pkg --link
end
end
if set -q out_pkgs[1]
_fisher_fetch (
for pkg in $out_pkgs
if test -s "$pkg/fishfile"
_fisher_fmt <$pkg/fishfile | _fisher_parse -R
end
end)
printf "%s\n" $out_pkgs | _fisher_fmt
end
end
function _fisher_add -a pkg opts
for src in $pkg/{functions,completions,conf.d}/**.* $pkg/*.fish
set -l target (command basename $src)
switch $src
case $pkg/conf.d\*
set target $fisher_path/conf.d/$target
case $pkg/completions\*
set target $fisher_path/completions/$target
case $pkg/{functions,}\*
switch $target
case uninstall.fish
continue
case {init,key_bindings}.fish
set target $fisher_path/conf.d/(command basename $pkg)\_$target
case \*
set target $fisher_path/functions/$target
end
end
echo "linking $target" | command sed "s|$HOME|~|" >&2
if set -q opts[1]
command ln -sf $src $target
else
command cp -f $src $target
end
switch $target
case \*.fish
source $target >/dev/null 2>/dev/null
end
end
end
function _fisher_rm -a pkg
for src in $pkg/{conf.d,completions,functions}/**.* $pkg/*.fish
set -l target (command basename $src)
set -l filename (command basename $target .fish)
switch $src
case $pkg/conf.d\*
test "$filename.fish" = "$target"; and emit "$filename"_uninstall
set target conf.d/$target
case $pkg/completions\*
test "$filename.fish" = "$target"; and complete -ec $filename
set target completions/$target
case $pkg/{,functions}\*
test "$filename.fish" = "$target"; and functions -e $filename
switch $target
case uninstall.fish
source $src
continue
case {init,key_bindings}.fish
set target conf.d/(command basename $pkg)\_$target
case \*
set target functions/$target
end
end
command rm -f $fisher_path/$target
end
if not functions -q fish_prompt
source "$__fish_datadir$__fish_data_dir/functions/fish_prompt.fish"
end
end
function _fisher_jobs
jobs $argv | command awk '/^[0-9]+\t/ { print $1 }'
end
function _fisher_now -a elapsed
switch (command uname)
case Darwin \*BSD
command perl -MTime::HiRes -e 'printf("%.0f\n", (Time::HiRes::time() * 1000) - $ARGV[0])' $elapsed
case \*
math (command date "+%s%3N") - "0$elapsed"
end
end

View file

@ -0,0 +1,4 @@
function goland
open -a Goland .
end

View file

@ -0,0 +1,4 @@
function machine-env
eval (docker-machine env $argv)
end

View file

@ -0,0 +1,4 @@
function v
vim (fzf)
end

View file

@ -0,0 +1,4 @@
function vs
vi (ag -l $argv)
end