diff --git a/config/fish/functions/__bass.py b/config/fish/functions/__bass.py deleted file mode 100644 index 3f02bd4..0000000 --- a/config/fish/functions/__bass.py +++ /dev/null @@ -1,140 +0,0 @@ -""" -To be used with a companion fish function like this: - - function refish - set -l _x (python /tmp/bass.py source ~/.nvm/nvim.sh ';' nvm use iojs); source $_x; and rm -f $_x - end - -""" - -from __future__ import print_function - -import json -import os -import signal -import subprocess -import sys -import traceback - - -BASH = 'bash' - -FISH_READONLY = [ - 'PWD', 'SHLVL', 'history', 'pipestatus', 'status', 'version', - 'FISH_VERSION', 'fish_pid', 'hostname', '_', 'fish_private_mode' -] - -IGNORED = [ - 'PS1', 'XPC_SERVICE_NAME' -] - -def ignored(name): - if name == 'PWD': # this is read only, but has special handling - return False - # ignore other read only variables - if name in FISH_READONLY: - return True - if name in IGNORED or name.startswith("BASH_FUNC"): - return True - if name.startswith('%'): - return True - return False - -def escape(string): - # use json.dumps to reliably escape quotes and backslashes - return json.dumps(string).replace(r'$', r'\$') - -def escape_identifier(word): - return escape(word.replace('?', '\\?')) - -def comment(string): - return '\n'.join(['# ' + line for line in string.split('\n')]) - -def gen_script(): - # Use the following instead of /usr/bin/env to read environment so we can - # deal with multi-line environment variables (and other odd cases). - env_reader = "%s -c 'import os,json; print(json.dumps({k:v for k,v in os.environ.items()}))'" % (sys.executable) - args = [BASH, '-c', env_reader] - output = subprocess.check_output(args, universal_newlines=True) - old_env = output.strip() - - pipe_r, pipe_w = os.pipe() - if sys.version_info >= (3, 4): - os.set_inheritable(pipe_w, True) - command = 'eval $1 && ({}; alias) >&{}'.format( - env_reader, - pipe_w - ) - args = [BASH, '-c', command, 'bass', ' '.join(sys.argv[1:])] - p = subprocess.Popen(args, universal_newlines=True, close_fds=False) - os.close(pipe_w) - with os.fdopen(pipe_r) as f: - new_env = f.readline() - alias_str = f.read() - if p.wait() != 0: - raise subprocess.CalledProcessError( - returncode=p.returncode, - cmd=' '.join(sys.argv[1:]), - output=new_env + alias_str - ) - new_env = new_env.strip() - - old_env = json.loads(old_env) - new_env = json.loads(new_env) - - script_lines = [] - - for k, v in new_env.items(): - if ignored(k): - continue - v1 = old_env.get(k) - if not v1: - script_lines.append(comment('adding %s=%s' % (k, v))) - elif v1 != v: - script_lines.append(comment('updating %s=%s -> %s' % (k, v1, v))) - # process special variables - if k == 'PWD': - script_lines.append('cd %s' % escape(v)) - continue - else: - continue - if k == 'PATH': - value = ' '.join([escape(directory) - for directory in v.split(':')]) - else: - value = escape(v) - script_lines.append('set -g -x %s %s' % (k, value)) - - for var in set(old_env.keys()) - set(new_env.keys()): - script_lines.append(comment('removing %s' % var)) - script_lines.append('set -e %s' % var) - - script = '\n'.join(script_lines) - - alias_lines = [] - for line in alias_str.splitlines(): - _, rest = line.split(None, 1) - k, v = rest.split("=", 1) - alias_lines.append("alias " + escape_identifier(k) + "=" + v) - alias = '\n'.join(alias_lines) - - return script + '\n' + alias - -script_file = os.fdopen(3, 'w') - -if not sys.argv[1:]: - print('__bass_usage', file=script_file, end='') - sys.exit(0) - -try: - script = gen_script() -except subprocess.CalledProcessError as e: - sys.exit(e.returncode) -except Exception: - print('Bass internal error!', file=sys.stderr) - raise # traceback will output to stderr -except KeyboardInterrupt: - signal.signal(signal.SIGINT, signal.SIG_DFL) - os.kill(os.getpid(), signal.SIGINT) -else: - script_file.write(script) diff --git a/config/fish/functions/__fzf_cd.fish b/config/fish/functions/__fzf_cd.fish deleted file mode 100644 index c79a725..0000000 --- a/config/fish/functions/__fzf_cd.fish +++ /dev/null @@ -1,49 +0,0 @@ -function __fzf_cd -d "Change directory" - set -l commandline (__fzf_parse_commandline) - set -l dir $commandline[1] - set -l fzf_query $commandline[2] - - if not type -q argparse - # Fallback for fish shell version < 2.7 - function argparse - functions -e argparse # deletes itself - end - if contains -- --hidden $argv; or contains -- -h $argv - set _flag_hidden "yes" - end - end - - # Fish shell version >= v2.7, use argparse - set -l options "h/hidden" - argparse $options -- $argv - - set -l COMMAND - - set -q FZF_CD_COMMAND - or set -l FZF_CD_COMMAND " - command find -L \$dir -mindepth 1 \\( -path \$dir'*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \ - -o -type d -print 2> /dev/null | sed 's@^\./@@'" - - set -q FZF_CD_WITH_HIDDEN_COMMAND - or set -l FZF_CD_WITH_HIDDEN_COMMAND " - command find -L \$dir \ - \\( -path '*/\\.git*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \ - -o -type d -print 2> /dev/null | sed 1d | cut -b3-" - - if set -q _flag_hidden - set COMMAND $FZF_CD_WITH_HIDDEN_COMMAND - else - set COMMAND $FZF_CD_COMMAND - end - - eval "$COMMAND | "(__fzfcmd)" +m $FZF_DEFAULT_OPTS $FZF_CD_OPTS --query \"$fzf_query\"" | read -l select - - if not test -z "$select" - builtin cd "$select" - - # Remove last token from commandline. - commandline -t "" - end - - commandline -f repaint -end diff --git a/config/fish/functions/__fzf_complete.fish b/config/fish/functions/__fzf_complete.fish deleted file mode 100644 index e8848fa..0000000 --- a/config/fish/functions/__fzf_complete.fish +++ /dev/null @@ -1,168 +0,0 @@ -## -# Use fzf as fish completion widget. -# -# -# When FZF_COMPLETE variable is set, fzf is used as completion -# widget for the fish shell by binding the TAB key. -# -# FZF_COMPLETE can have some special numeric values: -# -# `set FZF_COMPLETE 0` basic widget accepts with TAB key -# `set FZF_COMPLETE 1` extends 0 with candidate preview window -# `set FZF_COMPLETE 2` same as 1 but TAB walks on candidates -# `set FZF_COMPLETE 3` multi TAB selection, RETURN accepts selected ones. -# -# Any other value of FZF_COMPLETE is given directly as options to fzf. -# -# If you prefer to set more advanced options, take a look at the -# `__fzf_complete_opts` function and override that in your environment. - - -# modified from https://github.com/junegunn/fzf/wiki/Examples-(fish)#completion -function __fzf_complete -d 'fzf completion and print selection back to commandline' - # As of 2.6, fish's "complete" function does not understand - # subcommands. Instead, we use the same hack as __fish_complete_subcommand and - # extract the subcommand manually. - set -l cmd (commandline -co) (commandline -ct) - - switch $cmd[1] - case env sudo - for i in (seq 2 (count $cmd)) - switch $cmd[$i] - case '-*' - case '*=*' - case '*' - set cmd $cmd[$i..-1] - break - end - end - end - - set -l cmd_lastw $cmd[-1] - set cmd (string join -- ' ' $cmd) - - set -l initial_query '' - test -n "$cmd_lastw"; and set initial_query --query="$cmd_lastw" - - set -l complist (complete -C$cmd) - set -l result - - # do nothing if there is nothing to select from - test -z "$complist"; and return - - set -l compwc (echo $complist | wc -w) - if test $compwc -eq 1 - # if there is only one option dont open fzf - set result "$complist" - else - - set -l query - string join -- \n $complist \ - | eval (__fzfcmd) (string escape --no-quoted -- $initial_query) --print-query (__fzf_complete_opts) \ - | cut -f1 \ - | while read -l r - # first line is the user entered query - if test -z "$query" - set query $r - # rest of lines are selected candidates - else - set result $result $r - end - end - - # exit if user canceled - if test -z "$query" ;and test -z "$result" - commandline -f repaint - return - end - - # if user accepted but no candidate matches, use the input as result - if test -z "$result" - set result $query - end - end - - set prefix (string sub -s 1 -l 1 -- (commandline -t)) - for i in (seq (count $result)) - set -l r $result[$i] - switch $prefix - case "'" - commandline -t -- (string escape -- $r) - case '"' - if string match '*"*' -- $r >/dev/null - commandline -t -- (string escape -- $r) - else - commandline -t -- '"'$r'"' - end - case '~' - commandline -t -- (string sub -s 2 (string escape -n -- $r)) - case '*' - commandline -t -- $r - end - [ $i -lt (count $result) ]; and commandline -i ' ' - end - - commandline -f repaint -end - -function __fzf_complete_opts_common - if set -q FZF_DEFAULT_OPTS - echo $FZF_DEFAULT_OPTS - end - echo --cycle --reverse --inline-info -end - -function __fzf_complete_opts_tab_accepts - echo --bind tab:accept,btab:cancel -end - -function __fzf_complete_opts_tab_walks - echo --bind tab:down,btab:up -end - -function __fzf_complete_opts_preview - set -l file (status -f) - echo --with-nth=1 --preview-window=right:wrap --preview="fish\ '$file'\ __fzf_complete_preview\ '{1}'\ '{2..}'" -end - -test "$argv[1]" = "__fzf_complete_preview"; and __fzf_complete_preview $argv[2..3] - -function __fzf_complete_opts_0 -d 'basic single selection with tab accept' - __fzf_complete_opts_common - echo --no-multi - __fzf_complete_opts_tab_accepts -end - -function __fzf_complete_opts_1 -d 'single selection with preview and tab accept' - __fzf_complete_opts_0 - __fzf_complete_opts_preview -end - -function __fzf_complete_opts_2 -d 'single selection with preview and tab walks' - __fzf_complete_opts_1 - __fzf_complete_opts_tab_walks -end - -function __fzf_complete_opts_3 -d 'multi selection with preview' - __fzf_complete_opts_common - echo --multi - __fzf_complete_opts_preview -end - -function __fzf_complete_opts -d 'fzf options for fish tab completion' - switch $FZF_COMPLETE - case 0 - __fzf_complete_opts_0 - case 1 - __fzf_complete_opts_1 - case 2 - __fzf_complete_opts_2 - case 3 - __fzf_complete_opts_3 - case '*' - echo $FZF_COMPLETE - end - if set -q FZF_COMPLETE_OPTS - echo $FZF_COMPLETE_OPTS - end -end diff --git a/config/fish/functions/__fzf_complete_preview.fish b/config/fish/functions/__fzf_complete_preview.fish deleted file mode 100644 index 585ab92..0000000 --- a/config/fish/functions/__fzf_complete_preview.fish +++ /dev/null @@ -1,31 +0,0 @@ -function __fzf_complete_preview -d 'generate preview for completion widget. - argv[1] is the currently selected candidate in fzf - argv[2] is a string containing the rest of the output produced by `complete -Ccmd` - ' - - if test "$argv[2]" = "Redefine variable" - # show environment variables current value - set -l evar (echo $argv[1] | cut -d= -f1) - echo $argv[1]$$evar - else - echo $argv[1] - end - - set -l path (string replace "~" $HOME -- $argv[1]) - - # list directories on preview - if test -d "$path" - eval $FZF_PREVIEW_DIR_CMD (string escape $path) - end - - # show ten lines of non-binary files preview - if test -f "$path"; and grep -qI . "$path" - eval $FZF_PREVIEW_FILE_CMD (string escape $path) - end - - # if fish knows about it, let it show info - type -q "$path" 2>/dev/null; and type -a "$path" - - # show aditional data - echo $argv[2] -end diff --git a/config/fish/functions/__fzf_find_file.fish b/config/fish/functions/__fzf_find_file.fish deleted file mode 100644 index 1900006..0000000 --- a/config/fish/functions/__fzf_find_file.fish +++ /dev/null @@ -1,29 +0,0 @@ -function __fzf_find_file -d "List files and folders" - set -l commandline (__fzf_parse_commandline) - set -l dir $commandline[1] - set -l fzf_query $commandline[2] - - set -q FZF_FIND_FILE_COMMAND - or set -l FZF_FIND_FILE_COMMAND " - command find -L \$dir -mindepth 1 \\( -path \$dir'*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \ - -o -type f -print \ - -o -type d -print \ - -o -type l -print 2> /dev/null | sed 's@^\./@@'" - - begin - eval "$FZF_FIND_FILE_COMMAND | "(__fzfcmd) "-m $FZF_DEFAULT_OPTS $FZF_FIND_FILE_OPTS --query \"$fzf_query\"" | while read -l s; set results $results $s; end - end - - if test -z "$results" - commandline -f repaint - return - else - commandline -t "" - end - - for result in $results - commandline -it -- (string escape $result) - commandline -it -- " " - end - commandline -f repaint -end diff --git a/config/fish/functions/__fzf_get_dir.fish b/config/fish/functions/__fzf_get_dir.fish deleted file mode 100644 index 77c873c..0000000 --- a/config/fish/functions/__fzf_get_dir.fish +++ /dev/null @@ -1,17 +0,0 @@ -function __fzf_get_dir -d 'Find the longest existing filepath from input string' - set dir $argv - - # Strip all trailing slashes. Ignore if $dir is root dir (/) - if test (string length $dir) -gt 1 - set dir (string replace -r '/*$' '' $dir) - end - - # Iteratively check if dir exists and strip tail end of path - while test ! -d "$dir" - # If path is absolute, this can keep going until ends up at / - # If path is relative, this can keep going until entire input is consumed, dirname returns "." - set dir (dirname "$dir") - end - - echo $dir -end diff --git a/config/fish/functions/__fzf_open.fish b/config/fish/functions/__fzf_open.fish deleted file mode 100644 index aa5ca61..0000000 --- a/config/fish/functions/__fzf_open.fish +++ /dev/null @@ -1,63 +0,0 @@ -function __fzf_open -d "Open files and directories." - function __fzf_open_get_open_cmd -d "Find appropriate open command." - if type -q xdg-open - echo "xdg-open" - else if type -q open - echo "open" - end - end - - set -l commandline (__fzf_parse_commandline) - set -l dir $commandline[1] - set -l fzf_query $commandline[2] - - if not type -q argparse - set created_argparse - function argparse - functions -e argparse # deletes itself - end - if contains -- --editor $argv; or contains -- -e $argv - set _flag_editor "yes" - end - if contains -- --preview $argv; or contains -- -p $argv - set _flag_preview "yes" - end - end - - set -l options "e/editor" "p/preview=?" - argparse $options -- $argv - - set -l preview_cmd - if set -q FZF_ENABLE_OPEN_PREVIEW - set preview_cmd "--preview-window=right:wrap --preview='fish -c \"__fzf_complete_preview {}\"'" - end - - set -q FZF_OPEN_COMMAND - or set -l FZF_OPEN_COMMAND " - command find -L \$dir -mindepth 1 \\( -path \$dir'*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \ - -o -type f -print \ - -o -type d -print \ - -o -type l -print 2> /dev/null | sed 's@^\./@@'" - - set -l select (eval "$FZF_OPEN_COMMAND | "(__fzfcmd) $preview_cmd "-m $FZF_DEFAULT_OPTS $FZF_OPEN_OPTS --query \"$fzf_query\"" | string escape) - - # set how to open - set -l open_cmd - if set -q _flag_editor - set open_cmd "$EDITOR" - else - set open_cmd (__fzf_open_get_open_cmd) - if test -z "$open_cmd" - echo "Couldn't find appropriate open command to use. Do you have 'xdg-open' or 'open' installed?"; and return 1 - end - end - - set -l open_status 0 - if not test -z "$select" - commandline "$open_cmd $select"; and commandline -f execute - set open_status $status - end - - commandline -f repaint - return $open_status -end diff --git a/config/fish/functions/__fzf_parse_commandline.fish b/config/fish/functions/__fzf_parse_commandline.fish deleted file mode 100644 index 2cc9dfb..0000000 --- a/config/fish/functions/__fzf_parse_commandline.fish +++ /dev/null @@ -1,23 +0,0 @@ -function __fzf_parse_commandline -d 'Parse the current command line token and return split of existing filepath and rest of token' - # eval is used to do shell expansion on paths - set -l commandline (eval "printf '%s' "(commandline -t)) - - if test -z $commandline - # Default to current directory with no --query - set dir '.' - set fzf_query '' - else - set dir (__fzf_get_dir $commandline) - - if test "$dir" = "." -a (string sub -l 1 $commandline) != '.' - # if $dir is "." but commandline is not a relative path, this means no file path found - set fzf_query $commandline - else - # Also remove trailing slash after dir, to "split" input properly - set fzf_query (string replace -r "^$dir/?" '' "$commandline") - end - end - - echo $dir - echo $fzf_query -end diff --git a/config/fish/functions/__fzf_reverse_isearch.fish b/config/fish/functions/__fzf_reverse_isearch.fish deleted file mode 100644 index 2ebbe20..0000000 --- a/config/fish/functions/__fzf_reverse_isearch.fish +++ /dev/null @@ -1,6 +0,0 @@ -function __fzf_reverse_isearch - history merge - history -z | eval (__fzfcmd) --read0 --print0 --tiebreak=index --toggle-sort=ctrl-r $FZF_DEFAULT_OPTS $FZF_REVERSE_ISEARCH_OPTS -q '(commandline)' | read -lz result - and commandline -- $result - commandline -f repaint -end diff --git a/config/fish/functions/__fzfcmd.fish b/config/fish/functions/__fzfcmd.fish deleted file mode 100644 index 821c650..0000000 --- a/config/fish/functions/__fzfcmd.fish +++ /dev/null @@ -1,9 +0,0 @@ -function __fzfcmd - set -q FZF_TMUX; or set FZF_TMUX 0 - set -q FZF_TMUX_HEIGHT; or set FZF_TMUX_HEIGHT 40% - if test $FZF_TMUX -eq 1 - echo "fzf-tmux -d$FZF_TMUX_HEIGHT" - else - echo "fzf" - end -end diff --git a/config/fish/functions/__z.fish b/config/fish/functions/__z.fish deleted file mode 100644 index f72ff0e..0000000 --- a/config/fish/functions/__z.fish +++ /dev/null @@ -1,174 +0,0 @@ -function __z -d "Jump to a recent directory." - function __print_help -d "Print z help." - printf "Usage: $Z_CMD [-celrth] string1 string2...\n\n" - printf " -c --clean Removes directories that no longer exist from $Z_DATA\n" - printf " -d --dir Opens matching directory using system file manager.\n" - printf " -e --echo Prints best match, no cd\n" - printf " -l --list List matches and scores, no cd\n" - printf " -p --purge Delete all entries from $Z_DATA\n" - printf " -r --rank Search by rank\n" - printf " -t --recent Search by recency\n" - printf " -x --delete Removes the current directory from $Z_DATA\n" - printf " -h --help Print this help\n\n" - end - function __z_legacy_escape_regex - # taken from escape_string_pcre2 in fish - # used to provide compatibility with fish 2 - for c in (string split '' $argv) - if contains $c (string split '' '.^$*+()?[{}\\|-]') - printf \\ - end - printf '%s' $c - end - end - - set -l options h/help c/clean e/echo l/list p/purge r/rank t/recent d/directory x/delete - - argparse $options -- $argv - - if set -q _flag_help - __print_help - return 0 - else if set -q _flag_clean - __z_clean - printf "%s cleaned!\n" $Z_DATA - return 0 - else if set -q _flag_purge - echo >$Z_DATA - printf "%s purged!\n" $Z_DATA - return 0 - else if set -q _flag_delete - sed -i -e "\:^$PWD|.*:d" $Z_DATA - return 0 - end - - set -l typ - - if set -q _flag_rank - set typ rank - else if set -q _flag_recent - set typ recent - end - - set -l z_script ' - function frecent(rank, time) { - dx = t-time - if( dx < 3600 ) return rank*4 - if( dx < 86400 ) return rank*2 - if( dx < 604800 ) return rank/2 - return rank/4 - } - - function output(matches, best_match, common) { - # list or return the desired directory - if( list ) { - cmd = "sort -nr" - for( x in matches ) { - if( matches[x] ) { - printf "%-10s %s\n", matches[x], x | cmd - } - } - } else { - if( common ) best_match = common - print best_match - } - } - - function common(matches) { - # find the common root of a list of matches, if it exists - for( x in matches ) { - if( matches[x] && (!short || length(x) < length(short)) ) { - short = x - } - } - if( short == "/" ) return - for( x in matches ) if( matches[x] && index(x, short) != 1 ) { - return - } - return short - } - - BEGIN { - hi_rank = ihi_rank = -9999999999 - } - { - if( typ == "rank" ) { - rank = $2 - } else if( typ == "recent" ) { - rank = $3 - t - } else rank = frecent($2, $3) - if( $1 ~ q ) { - matches[$1] = rank - } else if( tolower($1) ~ tolower(q) ) imatches[$1] = rank - if( matches[$1] && matches[$1] > hi_rank ) { - best_match = $1 - hi_rank = matches[$1] - } else if( imatches[$1] && imatches[$1] > ihi_rank ) { - ibest_match = $1 - ihi_rank = imatches[$1] - } - } - - END { - # prefer case sensitive - if( best_match ) { - output(matches, best_match, common(matches)) - } else if( ibest_match ) { - output(imatches, ibest_match, common(imatches)) - } - } - ' - - set -l qs - for arg in $argv - set -l escaped $arg - if string escape --style=regex '' >/dev/null 2>&1 # use builtin escape if available - set escaped (string escape --style=regex $escaped) - else - set escaped (__z_legacy_escape_regex $escaped) - end - # Need to escape twice, see https://www.math.utah.edu/docs/info/gawk_5.html#SEC32 - set escaped (string replace --all \\ \\\\ $escaped) - set qs $qs $escaped - end - set -l q (string join '.*' $qs) - - if set -q _flag_list - # Handle list separately as it can print common path information to stderr - # which cannot be captured from a subcommand. - command awk -v t=(date +%s) -v list="list" -v typ="$typ" -v q="$q" -F "|" $z_script "$Z_DATA" - return - end - - set target (command awk -v t=(date +%s) -v typ="$typ" -v q="$q" -F "|" $z_script "$Z_DATA") - - if test "$status" -gt 0 - return - end - - if test -z "$target" - printf "'%s' did not match any results\n" "$argv" - return 1 - end - - if set -q _flag_echo - printf "%s\n" "$target" - else if set -q _flag_directory - if test -n "$ZO_METHOD" - type -q "$ZO_METHOD"; and "$ZO_METHOD" "$target"; and return $status - echo "Cannot open with ZO_METHOD set to $ZO_METHOD"; and return 1 - else if test "$OS" = Windows_NT - # Be careful, in msys2, explorer always return 1 - type -q explorer; and explorer "$target" - return 0 - echo "Cannot open file explorer" - return 1 - else - type -q xdg-open; and xdg-open "$target"; and return $status - type -q open; and open "$target"; and return $status - echo "Not sure how to open file manager"; and return 1 - end - else - pushd "$target" - end -end diff --git a/config/fish/functions/__z_add.fish b/config/fish/functions/__z_add.fish deleted file mode 100644 index 20d5d7e..0000000 --- a/config/fish/functions/__z_add.fish +++ /dev/null @@ -1,49 +0,0 @@ -function __z_add -d "Add PATH to .z file" - test -n "$fish_private_mode"; and return 0 - - for i in $Z_EXCLUDE - if string match -r $i $PWD >/dev/null - return 0 #Path excluded - end - end - - set -l tmpfile (mktemp $Z_DATA.XXXXXX) - - if test -f $tmpfile - set -l path (string replace --all \\ \\\\ $PWD) - command awk -v path=$path -v now=(date +%s) -F "|" ' - BEGIN { - rank[path] = 1 - time[path] = now - } - $2 >= 1 { - if( $1 == path ) { - rank[$1] = $2 + 1 - time[$1] = now - } - else { - rank[$1] = $2 - time[$1] = $3 - } - count += $2 - } - END { - if( count > 1000 ) { - for( i in rank ) print i "|" 0.9*rank[i] "|" time[i] # aging - } - else for( i in rank ) print i "|" rank[i] "|" time[i] - } - ' $Z_DATA 2>/dev/null >$tmpfile - - if test ! -z "$Z_OWNER" - chown $Z_OWNER:(id -ng $Z_OWNER) $tmpfile - end - # - # Don't use redirection here as it can lead to a race condition where $Z_DATA is clobbered. - # Note: There is a still a possible race condition where an old version of $Z_DATA is - # read by one instance of Fish before another instance of Fish writes its copy. - # - command mv $tmpfile $Z_DATA - or command rm $tmpfile - end -end diff --git a/config/fish/functions/__z_clean.fish b/config/fish/functions/__z_clean.fish deleted file mode 100644 index ae1721a..0000000 --- a/config/fish/functions/__z_clean.fish +++ /dev/null @@ -1,11 +0,0 @@ -function __z_clean -d "Clean up .z file to remove paths no longer valid" - set -l tmpfile (mktemp $Z_DATA.XXXXXX) - - if test -f $tmpfile - while read line - set -l path (string split '|' $line)[1] - test -d $path; and echo $line - end <$Z_DATA >$tmpfile - command mv -f $tmpfile $Z_DATA - end -end diff --git a/config/fish/functions/__z_complete.fish b/config/fish/functions/__z_complete.fish deleted file mode 100644 index a626456..0000000 --- a/config/fish/functions/__z_complete.fish +++ /dev/null @@ -1,13 +0,0 @@ -function __z_complete -d "add completions" - complete -c $Z_CMD -a "(__z -l | string replace -r '^\\S*\\s*' '')" -f -k - complete -c $ZO_CMD -a "(__z -l | string replace -r '^\\S*\\s*' '')" -f -k - - complete -c $Z_CMD -s c -l clean -d "Cleans out $Z_DATA" - complete -c $Z_CMD -s e -l echo -d "Prints best match, no cd" - complete -c $Z_CMD -s l -l list -d "List matches, no cd" - complete -c $Z_CMD -s p -l purge -d "Purges $Z_DATA" - complete -c $Z_CMD -s r -l rank -d "Searches by rank, cd" - complete -c $Z_CMD -s t -l recent -d "Searches by recency, cd" - complete -c $Z_CMD -s h -l help -d "Print help" - complete -c $Z_CMD -s x -l delete -d "Removes the current directory from $Z_DATA" -end diff --git a/config/fish/functions/_autopair_backspace.fish b/config/fish/functions/_autopair_backspace.fish deleted file mode 100644 index a43fa79..0000000 --- a/config/fish/functions/_autopair_backspace.fish +++ /dev/null @@ -1,9 +0,0 @@ -function _autopair_backspace - set --local index (commandline --cursor) - set --local buffer (commandline) - - test $index -ge 1 && - contains -- (string sub --start=$index --length=2 -- "$buffer") $autopair_pairs && - commandline --function delete-char - commandline --function backward-delete-char -end diff --git a/config/fish/functions/_autopair_insert_left.fish b/config/fish/functions/_autopair_insert_left.fish deleted file mode 100644 index f078e86..0000000 --- a/config/fish/functions/_autopair_insert_left.fish +++ /dev/null @@ -1,13 +0,0 @@ -function _autopair_insert_left --argument-names left right - set --local buffer (commandline) - set --local before (commandline --cut-at-cursor) - - commandline --insert -- $left - - switch "$buffer" - case "$before"{," "\*,$autopair_right\*} - set --local index (commandline --cursor) - commandline --insert -- $right - commandline --cursor $index - end -end diff --git a/config/fish/functions/_autopair_insert_right.fish b/config/fish/functions/_autopair_insert_right.fish deleted file mode 100644 index a0bd61c..0000000 --- a/config/fish/functions/_autopair_insert_right.fish +++ /dev/null @@ -1,11 +0,0 @@ -function _autopair_insert_right --argument-names key - set --local buffer (commandline) - set --local before (commandline --cut-at-cursor) - - switch "$buffer" - case "$before$key"\* - commandline --cursor (math (commandline --cursor) + 1) - case \* - commandline --insert -- $key - end -end diff --git a/config/fish/functions/_autopair_insert_same.fish b/config/fish/functions/_autopair_insert_same.fish deleted file mode 100644 index 27f971d..0000000 --- a/config/fish/functions/_autopair_insert_same.fish +++ /dev/null @@ -1,20 +0,0 @@ -function _autopair_insert_same --argument-names key - set --local buffer (commandline) - set --local index (commandline --cursor) - set --local next (string sub --start=(math $index + 1) --length=1 -- "$buffer") - - if test (math (count (string match --all --regex -- "$key" "$buffer")) % 2) = 0 - test $key = $next && commandline --cursor (math $index + 1) && return - - commandline --insert -- $key - - if test $index -lt 1 || - contains -- (string sub --start=$index --length=1 -- "$buffer") "" " " $autopair_left && - contains -- $next "" " " $autopair_right - commandline --insert -- $key - commandline --cursor (math $index + 1) - end - else - commandline --insert -- $key - end -end diff --git a/config/fish/functions/_autopair_tab.fish b/config/fish/functions/_autopair_tab.fish deleted file mode 100644 index f2ab8eb..0000000 --- a/config/fish/functions/_autopair_tab.fish +++ /dev/null @@ -1,7 +0,0 @@ -function _autopair_tab - commandline --paging-mode && down-or-search && return - - string match --quiet --regex -- '\$[^\s]*"$' (commandline --current-token) && - commandline --function end-of-line --function backward-delete-char - commandline --function complete -end diff --git a/config/fish/functions/bass.fish b/config/fish/functions/bass.fish deleted file mode 100644 index 2b3af16..0000000 --- a/config/fish/functions/bass.fish +++ /dev/null @@ -1,29 +0,0 @@ -function bass - set -l bash_args $argv - set -l bass_debug - if test "$bash_args[1]_" = '-d_' - set bass_debug true - set -e bash_args[1] - end - - set -l script_file (mktemp) - if command -v python3 >/dev/null 2>&1 - command python3 -sS (dirname (status -f))/__bass.py $bash_args 3>$script_file - else - command python -sS (dirname (status -f))/__bass.py $bash_args 3>$script_file - end - set -l bass_status $status - if test $bass_status -ne 0 - return $bass_status - end - - if test -n "$bass_debug" - cat $script_file - end - source $script_file - command rm $script_file -end - -function __bass_usage - echo "Usage: bass [-d] " -end diff --git a/config/fish/functions/fisher.fish b/config/fish/functions/fisher.fish deleted file mode 100644 index b1513d3..0000000 --- a/config/fish/functions/fisher.fish +++ /dev/null @@ -1,240 +0,0 @@ -function fisher --argument-names cmd --description "A plugin manager for Fish" - set --query fisher_path || set --local fisher_path $__fish_config_dir - set --local fisher_version 4.4.4 - set --local fish_plugins $__fish_config_dir/fish_plugins - - switch "$cmd" - case -v --version - echo "fisher, version $fisher_version" - case "" -h --help - echo "Usage: fisher install Install plugins" - echo " fisher remove Remove installed plugins" - echo " fisher update Update installed plugins" - echo " fisher update Update all installed plugins" - echo " fisher list [] List installed plugins matching regex" - echo "Options:" - echo " -v, --version Print version" - echo " -h, --help Print this help message" - echo "Variables:" - echo " \$fisher_path Plugin installation path. Default: $__fish_config_dir" | string replace --regex -- $HOME \~ - case ls list - string match --entire --regex -- "$argv[2]" $_fisher_plugins - case install update remove - isatty || read --local --null --array stdin && set --append argv $stdin - - set --local install_plugins - set --local update_plugins - set --local remove_plugins - set --local arg_plugins $argv[2..-1] - set --local old_plugins $_fisher_plugins - set --local new_plugins - - test -e $fish_plugins && set --local file_plugins (string match --regex -- '^[^\s]+$' <$fish_plugins) - - if ! set --query argv[2] - if test "$cmd" != update - echo "fisher: Not enough arguments for command: \"$cmd\"" >&2 && return 1 - else if ! set --query file_plugins - echo "fisher: \"$fish_plugins\" file not found: \"$cmd\"" >&2 && return 1 - end - set arg_plugins $file_plugins - end - - for plugin in $arg_plugins - set plugin (test -e "$plugin" && realpath $plugin || string lower -- $plugin) - contains -- "$plugin" $new_plugins || set --append new_plugins $plugin - end - - if set --query argv[2] - for plugin in $new_plugins - if contains -- "$plugin" $old_plugins - test "$cmd" = remove && - set --append remove_plugins $plugin || - set --append update_plugins $plugin - else if test "$cmd" = install - set --append install_plugins $plugin - else - echo "fisher: Plugin not installed: \"$plugin\"" >&2 && return 1 - end - end - else - for plugin in $new_plugins - contains -- "$plugin" $old_plugins && - set --append update_plugins $plugin || - set --append install_plugins $plugin - end - - for plugin in $old_plugins - contains -- "$plugin" $new_plugins || set --append remove_plugins $plugin - end - end - - set --local pid_list - set --local source_plugins - set --local fetch_plugins $update_plugins $install_plugins - set --local fish_path (status fish-path) - - echo (set_color --bold)fisher $cmd version $fisher_version(set_color normal) - - for plugin in $fetch_plugins - set --local source (command mktemp -d) - set --append source_plugins $source - - command mkdir -p $source/{completions,conf.d,themes,functions} - - $fish_path --command " - if test -e $plugin - command cp -Rf $plugin/* $source - else - set temp (command mktemp -d) - set repo (string split -- \@ $plugin) || set repo[2] HEAD - - if set path (string replace --regex -- '^(https://)?gitlab.com/' '' \$repo[1]) - set name (string split -- / \$path)[-1] - set url https://gitlab.com/\$path/-/archive/\$repo[2]/\$name-\$repo[2].tar.gz - else - set url https://api.github.com/repos/\$repo[1]/tarball/\$repo[2] - end - - echo Fetching (set_color --underline)\$url(set_color normal) - - if command curl -q --silent -L \$url | command tar -xzC \$temp -f - 2>/dev/null - command cp -Rf \$temp/*/* $source - else - echo fisher: Invalid plugin name or host unavailable: \\\"$plugin\\\" >&2 - command rm -rf $source - end - - command rm -rf \$temp - end - - set files $source/* && string match --quiet --regex -- .+\.fish\\\$ \$files - " & - - set --append pid_list (jobs --last --pid) - end - - wait $pid_list 2>/dev/null - - for plugin in $fetch_plugins - if set --local source $source_plugins[(contains --index -- "$plugin" $fetch_plugins)] && test ! -e $source - if set --local index (contains --index -- "$plugin" $install_plugins) - set --erase install_plugins[$index] - else - set --erase update_plugins[(contains --index -- "$plugin" $update_plugins)] - end - end - end - - for plugin in $update_plugins $remove_plugins - if set --local index (contains --index -- "$plugin" $_fisher_plugins) - set --local plugin_files_var _fisher_(string escape --style=var -- $plugin)_files - - if contains -- "$plugin" $remove_plugins - for name in (string replace --filter --regex -- '.+/conf\.d/([^/]+)\.fish$' '$1' $$plugin_files_var) - emit {$name}_uninstall - end - printf "%s\n" Removing\ (set_color red --bold)$plugin(set_color normal) " "$$plugin_files_var | string replace -- \~ ~ - set --erase _fisher_plugins[$index] - end - - command rm -rf (string replace -- \~ ~ $$plugin_files_var) - - functions --erase (string replace --filter --regex -- '.+/functions/([^/]+)\.fish$' '$1' $$plugin_files_var) - - for name in (string replace --filter --regex -- '.+/completions/([^/]+)\.fish$' '$1' $$plugin_files_var) - complete --erase --command $name - end - - set --erase $plugin_files_var - end - end - - if set --query update_plugins[1] || set --query install_plugins[1] - command mkdir -p $fisher_path/{functions,themes,conf.d,completions} - end - - for plugin in $update_plugins $install_plugins - set --local source $source_plugins[(contains --index -- "$plugin" $fetch_plugins)] - set --local files $source/{functions,themes,conf.d,completions}/* - - if set --local index (contains --index -- $plugin $install_plugins) - set --local user_files $fisher_path/{functions,themes,conf.d,completions}/* - set --local conflict_files - - for file in (string replace -- $source/ $fisher_path/ $files) - contains -- $file $user_files && set --append conflict_files $file - end - - if set --query conflict_files[1] && set --erase install_plugins[$index] - echo -s "fisher: Cannot install \"$plugin\": please remove or move conflicting files first:" \n" "$conflict_files >&2 - continue - end - end - - for file in (string replace -- $source/ "" $files) - command cp -RLf $source/$file $fisher_path/$file - end - - set --local plugin_files_var _fisher_(string escape --style=var -- $plugin)_files - - set --query files[1] && set --universal $plugin_files_var (string replace -- $source $fisher_path $files | string replace -- ~ \~) - - contains -- $plugin $_fisher_plugins || set --universal --append _fisher_plugins $plugin - contains -- $plugin $install_plugins && set --local event install || set --local event update - - printf "%s\n" Installing\ (set_color --bold)$plugin(set_color normal) " "$$plugin_files_var | string replace -- \~ ~ - - for file in (string match --regex -- '.+/[^/]+\.fish$' $$plugin_files_var | string replace -- \~ ~) - source $file - if set --local name (string replace --regex -- '.+conf\.d/([^/]+)\.fish$' '$1' $file) - emit {$name}_$event - end - end - end - - command rm -rf $source_plugins - - if set --query _fisher_plugins[1] - set --local commit_plugins - - for plugin in $file_plugins - contains -- (string lower -- $plugin) (string lower -- $_fisher_plugins) && set --append commit_plugins $plugin - end - - for plugin in $_fisher_plugins - contains -- (string lower -- $plugin) (string lower -- $commit_plugins) || set --append commit_plugins $plugin - end - - printf "%s\n" $commit_plugins >$fish_plugins - else - set --erase _fisher_plugins - command rm -f $fish_plugins - end - - set --local total (count $install_plugins) (count $update_plugins) (count $remove_plugins) - - test "$total" != "0 0 0" && echo (string join ", " ( - test $total[1] = 0 || echo "Installed $total[1]") ( - test $total[2] = 0 || echo "Updated $total[2]") ( - test $total[3] = 0 || echo "Removed $total[3]") - ) plugin/s - case \* - echo "fisher: Unknown command: \"$cmd\"" >&2 && return 1 - end -end - -if ! set --query _fisher_upgraded_to_4_4 - set --universal _fisher_upgraded_to_4_4 - if functions --query _fisher_list - set --query XDG_DATA_HOME[1] || set --local XDG_DATA_HOME ~/.local/share - command rm -rf $XDG_DATA_HOME/fisher - functions --erase _fisher_{list,plugin_parse} - fisher update >/dev/null 2>/dev/null - else - for var in (set --names | string match --entire --regex '^_fisher_.+_files$') - set $var (string replace -- ~ \~ $$var) - end - functions --erase _fisher_fish_postexec - end -end