fish: add fzf
This commit is contained in:
parent
b275c574b7
commit
91bedc6fc3
1
config/fish/conf.d/fisher.fish
Normal file
1
config/fish/conf.d/fisher.fish
Normal file
@ -0,0 +1 @@
|
|||||||
|
fisher copy-user-key-bindings
|
9
config/fish/conf.d/fzf.fish
Normal file
9
config/fish/conf.d/fzf.fish
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
set -q FZF_TMUX_HEIGHT; or set -U FZF_TMUX_HEIGHT "40%"
|
||||||
|
set -q FZF_DEFAULT_OPTS; or set -U FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT"
|
||||||
|
set -q FZF_LEGACY_KEYBINDINGS; or set -U FZF_LEGACY_KEYBINDINGS 1
|
||||||
|
set -q FZF_PREVIEW_FILE_CMD; or set -U FZF_PREVIEW_FILE_CMD "head -n 10"
|
||||||
|
set -q FZF_PREVIEW_DIR_CMD; or set -U FZF_PREVIEW_DIR_CMD "ls"
|
||||||
|
|
||||||
|
function fzf_uninstall -e fzf_uninstall
|
||||||
|
# Erase env vars and __fzf functions here.
|
||||||
|
end
|
41
config/fish/conf.d/fzf_key_bindings.fish
Normal file
41
config/fish/conf.d/fzf_key_bindings.fish
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
if test "$FZF_LEGACY_KEYBINDINGS" -eq 1
|
||||||
|
bind \ct '__fzf_find_file'
|
||||||
|
bind \cr '__fzf_reverse_isearch'
|
||||||
|
bind \ec '__fzf_cd'
|
||||||
|
bind \eC '__fzf_cd --hidden'
|
||||||
|
bind \cg '__fzf_open'
|
||||||
|
bind \co '__fzf_open --editor'
|
||||||
|
|
||||||
|
if bind -M insert >/dev/null 2>/dev/null
|
||||||
|
bind -M insert \ct '__fzf_find_file'
|
||||||
|
bind -M insert \cr '__fzf_reverse_isearch'
|
||||||
|
bind -M insert \ec '__fzf_cd'
|
||||||
|
bind -M insert \eC '__fzf_cd --hidden'
|
||||||
|
bind -M insert \cg '__fzf_open'
|
||||||
|
bind -M insert \co '__fzf_open --editor'
|
||||||
|
end
|
||||||
|
else
|
||||||
|
bind \cf '__fzf_find_file'
|
||||||
|
bind \cr '__fzf_reverse_isearch'
|
||||||
|
bind \eo '__fzf_cd'
|
||||||
|
bind \eO '__fzf_cd --hidden'
|
||||||
|
bind \cg '__fzf_open'
|
||||||
|
bind \co '__fzf_open --editor'
|
||||||
|
|
||||||
|
if bind -M insert >/dev/null 2>/dev/null
|
||||||
|
bind -M insert \cf '__fzf_find_file'
|
||||||
|
bind -M insert \cr '__fzf_reverse_isearch'
|
||||||
|
bind -M insert \eo '__fzf_cd'
|
||||||
|
bind -M insert \eO '__fzf_cd --hidden'
|
||||||
|
bind -M insert \cg '__fzf_open'
|
||||||
|
bind -M insert \co '__fzf_open --editor'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if set -q FZF_COMPLETE
|
||||||
|
bind \t '__fzf_complete'
|
||||||
|
end
|
||||||
|
|
||||||
|
function fzf_key_bindings_uninstall -e fzf_key_bindings_uninstall
|
||||||
|
# Erase key bindings here.
|
||||||
|
end
|
@ -1,5 +1,10 @@
|
|||||||
# This file is automatically generated by the fish.
|
# This file is automatically generated by the fish.
|
||||||
# Do NOT edit it directly, your changes will be overwritten.
|
# Do NOT edit it directly, your changes will be overwritten.
|
||||||
|
SET FZF_DEFAULT_OPTS:\x2d\x2dheight\x2040\x25
|
||||||
|
SET FZF_LEGACY_KEYBINDINGS:1
|
||||||
|
SET FZF_PREVIEW_DIR_CMD:ls
|
||||||
|
SET FZF_PREVIEW_FILE_CMD:head\x20\x2dn\x2010
|
||||||
|
SET FZF_TMUX_HEIGHT:40\x25
|
||||||
SET __fish_init_2_39_8:\x1d
|
SET __fish_init_2_39_8:\x1d
|
||||||
SET __fish_init_2_3_0:\x1d
|
SET __fish_init_2_3_0:\x1d
|
||||||
SET fish_color_autosuggestion:normal
|
SET fish_color_autosuggestion:normal
|
||||||
|
@ -1 +1,2 @@
|
|||||||
oh-my-fish/theme-bobthefish
|
oh-my-fish/theme-bobthefish
|
||||||
|
jethrokuan/fzf
|
||||||
|
39
config/fish/functions/__fzf_cd.fish
Normal file
39
config/fish/functions/__fzf_cd.fish
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
function __fzf_cd -d "Change directory"
|
||||||
|
set -l commandline (__fzf_parse_commandline)
|
||||||
|
set -l dir $commandline[1]
|
||||||
|
set -l fzf_query $commandline[2]
|
||||||
|
|
||||||
|
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
|
162
config/fish/functions/__fzf_complete.fish
Normal file
162
config/fish/functions/__fzf_complete.fish
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
##
|
||||||
|
# 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 \
|
||||||
|
| sort \
|
||||||
|
| eval (__fzfcmd) $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"
|
||||||
|
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 -- (string escape -n -- $r)
|
||||||
|
end
|
||||||
|
[ $i -lt (count $result) ]; and commandline -i ' '
|
||||||
|
end
|
||||||
|
|
||||||
|
commandline -f repaint
|
||||||
|
end
|
||||||
|
|
||||||
|
function __fzf_complete_opts_common
|
||||||
|
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
|
||||||
|
end
|
29
config/fish/functions/__fzf_complete_preview.fish
Normal file
29
config/fish/functions/__fzf_complete_preview.fish
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
# list directories on preview
|
||||||
|
if test -d "$argv[1]"
|
||||||
|
eval $FZF_PREVIEW_DIR_CMD (string escape $argv[1])
|
||||||
|
end
|
||||||
|
|
||||||
|
# show ten lines of non-binary files preview
|
||||||
|
if test -f "$argv[1]"; and grep -qI . "$argv[1]"
|
||||||
|
eval $FZF_PREVIEW_FILE_CMD (string escape $argv[1])
|
||||||
|
end
|
||||||
|
|
||||||
|
# if fish knows about it, let it show info
|
||||||
|
type -q "$argv[1]" 2>/dev/null; and type -a "$argv[1]"
|
||||||
|
|
||||||
|
# show aditional data
|
||||||
|
echo $argv[2]
|
||||||
|
end
|
29
config/fish/functions/__fzf_find_file.fish
Normal file
29
config/fish/functions/__fzf_find_file.fish
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
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
|
17
config/fish/functions/__fzf_get_dir.fish
Normal file
17
config/fish/functions/__fzf_get_dir.fish
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
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 [ (string length $dir) -gt 1 ]
|
||||||
|
set dir (string replace -r '/*$' '' $dir)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Iteratively check if dir exists and strip tail end of path
|
||||||
|
while [ ! -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
|
51
config/fish/functions/__fzf_open.fish
Normal file
51
config/fish/functions/__fzf_open.fish
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
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]
|
||||||
|
|
||||||
|
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@^\./@@'"
|
||||||
|
|
||||||
|
eval "$FZF_OPEN_COMMAND | "(__fzfcmd) $preview_cmd "-m $FZF_DEFAULT_OPTS $FZF_OPEN_OPTS --query \"$fzf_query\"" | read -l select
|
||||||
|
|
||||||
|
# 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
|
23
config/fish/functions/__fzf_parse_commandline.fish
Normal file
23
config/fish/functions/__fzf_parse_commandline.fish
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
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 [ -z $commandline ]
|
||||||
|
# Default to current directory with no --query
|
||||||
|
set dir '.'
|
||||||
|
set fzf_query ''
|
||||||
|
else
|
||||||
|
set dir (__fzf_get_dir $commandline)
|
||||||
|
|
||||||
|
if [ "$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
|
5
config/fish/functions/__fzf_reverse_isearch.fish
Normal file
5
config/fish/functions/__fzf_reverse_isearch.fish
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
function __fzf_reverse_isearch
|
||||||
|
history -z | eval (__fzfcmd) --read0 --tiebreak=index --toggle-sort=ctrl-r $FZF_DEFAULT_OPTS $FZF_REVERSE_ISEARCH_OPTS -q '(commandline)' | perl -pe 'chomp if eof' | read -lz result
|
||||||
|
and commandline -- $result
|
||||||
|
commandline -f repaint
|
||||||
|
end
|
9
config/fish/functions/__fzfcmd.fish
Normal file
9
config/fish/functions/__fzfcmd.fish
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
function __fzfcmd
|
||||||
|
set -q FZF_TMUX; or set FZF_TMUX 0
|
||||||
|
set -q FZF_TMUX_HEIGHT; or set FZF_TMUX_HEIGHT 40%
|
||||||
|
if [ $FZF_TMUX -eq 1 ]
|
||||||
|
echo "fzf-tmux -d$FZF_TMUX_HEIGHT"
|
||||||
|
else
|
||||||
|
echo "fzf"
|
||||||
|
end
|
||||||
|
end
|
@ -1,4 +1,4 @@
|
|||||||
set -g fisher_version 3.0.8
|
set -g fisher_version 3.1.0
|
||||||
|
|
||||||
type source >/dev/null; or function source; . $argv; end
|
type source >/dev/null; or function source; . $argv; end
|
||||||
|
|
||||||
@ -9,7 +9,7 @@ switch (command uname)
|
|||||||
end
|
end
|
||||||
case \*
|
case \*
|
||||||
function _fisher_now -a elapsed
|
function _fisher_now -a elapsed
|
||||||
command date "+%s%3N" | command awk "{ sub(/3N\$/,\"000\"); print \$0 - 0$elapsed }"
|
command date "+%s%3N" | command awk -v ELAPSED="$elapsed" '{ sub(/%?3N$/, "000") } $0 -= ELAPSED'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -35,9 +35,21 @@ function fisher -a cmd -d "fish package manager"
|
|||||||
_fisher_self_complete
|
_fisher_self_complete
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if test -e "$fisher_path/conf.d/fisher.fish"
|
||||||
|
command rm -f $fisher_path/conf.d/fisher.fish
|
||||||
|
end
|
||||||
|
|
||||||
|
switch "$version"
|
||||||
|
case \*-\*
|
||||||
|
case 2\*
|
||||||
|
echo "fisher copy-user-key-bindings" > $fisher_path/conf.d/fisher.fish
|
||||||
|
end
|
||||||
|
|
||||||
switch "$cmd"
|
switch "$cmd"
|
||||||
case self-complete
|
case self-complete
|
||||||
_fisher_self_complete
|
_fisher_self_complete
|
||||||
|
case copy-user-key-bindings
|
||||||
|
_fisher_copy_user_key_bindings
|
||||||
case ls
|
case ls
|
||||||
_fisher_ls | command sed "s|$HOME|~|"
|
_fisher_ls | command sed "s|$HOME|~|"
|
||||||
case -v {,--}version
|
case -v {,--}version
|
||||||
@ -79,6 +91,20 @@ function _fisher_self_complete
|
|||||||
end
|
end
|
||||||
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
|
function _fisher_ls
|
||||||
set -l pkgs $fisher_config/*/*/*
|
set -l pkgs $fisher_config/*/*/*
|
||||||
for pkg in $pkgs
|
for pkg in $pkgs
|
||||||
@ -91,20 +117,23 @@ function _fisher_version -a file
|
|||||||
end
|
end
|
||||||
|
|
||||||
function _fisher_help
|
function _fisher_help
|
||||||
echo "usage: fisher add <PACKAGES> add packages"
|
echo "usage: "
|
||||||
|
echo " fisher add <PACKAGES> add packages"
|
||||||
echo " fisher rm <PACKAGES> remove packages"
|
echo " fisher rm <PACKAGES> remove packages"
|
||||||
echo " fisher ls list installed packages"
|
echo " fisher update installed packages"
|
||||||
echo " fisher self-update update fisher"
|
echo " fisher ls show installed packages"
|
||||||
echo " fisher self-uninstall uninstall fisher & all packages"
|
|
||||||
echo " fisher help show this help"
|
echo " fisher help show this help"
|
||||||
echo " fisher version show version"
|
echo " fisher version show version"
|
||||||
|
echo " fisher self-update update fisher"
|
||||||
|
echo " fisher self-uninstall uninstall fisher"
|
||||||
echo
|
echo
|
||||||
echo "examples:"
|
echo "examples:"
|
||||||
echo " fisher add jethrokuan/z rafaelrinaldi/pure"
|
echo " fisher add jethrokuan/z rafaelrinaldi/pure"
|
||||||
echo " fisher add gitlab.com/owner/foobar@v2"
|
echo " fisher add gitlab.com/owner/foobar@v2"
|
||||||
echo " fisher add ~/myfish/mypkg"
|
echo " fisher add ~/path/to/myfish/pkg"
|
||||||
echo " fisher rm rafaelrinaldi/pure"
|
echo " fisher rm rafaelrinaldi/pure"
|
||||||
echo " fisher ls | fisher rm"
|
echo " fisher ls | fisher rm"
|
||||||
|
echo " fisher add < bundle"
|
||||||
end
|
end
|
||||||
|
|
||||||
function _fisher_self_update -a file
|
function _fisher_self_update -a file
|
||||||
@ -132,7 +161,7 @@ end
|
|||||||
|
|
||||||
function _fisher_self_uninstall
|
function _fisher_self_uninstall
|
||||||
set -l current_pkgs $fisher_config/*/*/*
|
set -l current_pkgs $fisher_config/*/*/*
|
||||||
for path in $fisher_cache (_fisher_pkg_remove_all $current_pkgs) $fisher_config $fisher_path/{functions,completions}/fisher.fish $fish_config/fishfile
|
for path in $fisher_cache (_fisher_pkg_remove_all $current_pkgs) $fisher_config $fisher_path/{functions,completions,conf.d}/fisher.fish $fish_config/fishfile
|
||||||
echo "removing $path"
|
echo "removing $path"
|
||||||
command rm -rf $path 2>/dev/null
|
command rm -rf $path 2>/dev/null
|
||||||
end | command sed "s|$HOME|~|" >&2
|
end | command sed "s|$HOME|~|" >&2
|
||||||
@ -160,9 +189,9 @@ function _fisher_commit
|
|||||||
command touch $fishfile
|
command touch $fishfile
|
||||||
echo "created empty fishfile in $fishfile" | command sed "s|$HOME|~|" >&2
|
echo "created empty fishfile in $fishfile" | command sed "s|$HOME|~|" >&2
|
||||||
end
|
end
|
||||||
printf "%s\n" (_fisher_fishfile_indent (echo -s $argv\;) < $fishfile) > $fishfile
|
printf "%s\n" (_fisher_fishfile_format (echo -s $argv\;) < $fishfile) > $fishfile
|
||||||
|
|
||||||
set -l expected_pkgs (_fisher_fishfile_load < $fishfile)
|
set -l expected_pkgs (_fisher_fishfile_read < $fishfile)
|
||||||
set -l added_pkgs (_fisher_pkg_fetch_all $expected_pkgs)
|
set -l added_pkgs (_fisher_pkg_fetch_all $expected_pkgs)
|
||||||
set -l updated_pkgs (
|
set -l updated_pkgs (
|
||||||
for pkg in $removed_pkgs
|
for pkg in $removed_pkgs
|
||||||
@ -177,7 +206,7 @@ function _fisher_commit
|
|||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
echo (count $added_pkgs) (count $updated_pkgs) (count $removed_pkgs) (_fisher_now $elapsed) | _fisher_status_report >&2
|
_fisher_status (count $added_pkgs) (count $updated_pkgs) (count $removed_pkgs) (_fisher_now $elapsed) >&2
|
||||||
end
|
end
|
||||||
|
|
||||||
function _fisher_pkg_remove_all
|
function _fisher_pkg_remove_all
|
||||||
@ -193,52 +222,49 @@ function _fisher_pkg_fetch_all
|
|||||||
set -l actual_pkgs
|
set -l actual_pkgs
|
||||||
set -l expected_pkgs
|
set -l expected_pkgs
|
||||||
|
|
||||||
for name in $argv
|
for id in $argv
|
||||||
switch $name
|
switch $id
|
||||||
case \~\* /\*
|
case \~\* /\*
|
||||||
set -l path (echo "$name" | command sed "s|~|$HOME|")
|
set -l path (echo "$id" | command sed "s|~|$HOME|")
|
||||||
if test -e "$path"
|
if test -e "$path"
|
||||||
set local_pkgs $local_pkgs $path
|
set local_pkgs $local_pkgs $path
|
||||||
else
|
else
|
||||||
echo "cannot install \"$name\" -- is this a valid file?" >&2
|
echo "cannot install \"$id\" -- is this a valid file?" >&2
|
||||||
end
|
end
|
||||||
continue
|
continue
|
||||||
case https://\* ssh://\* {github,gitlab}.com/\* bitbucket.org/\*
|
|
||||||
case \*/\*
|
|
||||||
set name "github.com/$name"
|
|
||||||
case \*
|
|
||||||
echo "cannot install \"$name\" without a prefix -- should be <owner>/$name" >&2
|
|
||||||
continue
|
|
||||||
end
|
end
|
||||||
|
|
||||||
echo $name | command awk '{
|
command awk -v ID=$id -v FS=/ 'BEGIN {
|
||||||
split($0, tmp, /@/)
|
if (split(ID, tmp, /@+|:/) > 2) {
|
||||||
|
if (tmp[4]) sub("@"tmp[4], "", ID)
|
||||||
pkg = tmp[1]
|
print ID "\t" tmp[2]"/"tmp[1]"/"tmp[3] "\t" (tmp[4] ? tmp[4] : "master")
|
||||||
|
} else {
|
||||||
|
pkg = split(ID, _, "/") <= 2 ? "github.com/"tmp[1] : tmp[1]
|
||||||
tag = tmp[2] ? tmp[2] : "master"
|
tag = tmp[2] ? tmp[2] : "master"
|
||||||
name = tmp[split(pkg, tmp, "/")]
|
|
||||||
|
|
||||||
print (\
|
print (\
|
||||||
pkg ~ /^github\.com/ ? "https://codeload."pkg"/tar.gz/"tag : \
|
pkg ~ /^github/ ? "https://codeload."pkg"/tar.gz/"tag : \
|
||||||
pkg ~ /^gitlab\.com/ ? "https://"pkg"/-/archive/"tag"/"name"-"tag".tar.gz" : \
|
pkg ~ /^gitlab/ ? "https://"pkg"/-/archive/"tag"/"tmp[split(pkg, tmp, "/")]"-"tag".tar.gz" : \
|
||||||
pkg ~ /^bitbucket\.org/ ? "https://"pkg"/get/"tag".tar.gz" : pkg \
|
pkg ~ /^bitbucket/ ? "https://"pkg"/get/"tag".tar.gz" : pkg \
|
||||||
) "\t" pkg
|
) "\t" pkg
|
||||||
}' | read -l url pkg
|
}
|
||||||
|
}' | read -l url pkg tag
|
||||||
|
|
||||||
if test ! -d "$fisher_config/$pkg"
|
if test ! -d "$fisher_config/$pkg"
|
||||||
fish -c "
|
fish -c "
|
||||||
echo fetching $url >&2
|
echo fetching $url >&2
|
||||||
command mkdir -p \"$fisher_config/$pkg\"
|
command mkdir -p \"$fisher_config/$pkg\"
|
||||||
|
if test ! -z \"$tag\"
|
||||||
if curl -Ss $url 2>&1 | tar -xzf- -C \"$fisher_config/$pkg\" --strip-components=1 2>/dev/null
|
command git clone $url \"$fisher_config/$pkg\" --branch $tag --depth 1 2>/dev/null
|
||||||
|
or echo cannot clone \"$url\" -- is this a valid url\? >&2
|
||||||
|
else if command curl -Ss $url 2>&1 | command tar -xzf- -C \"$fisher_config/$pkg\" --strip-components=1 2>/dev/null
|
||||||
command mkdir -p \"$fisher_cache/$pkg\"
|
command mkdir -p \"$fisher_cache/$pkg\"
|
||||||
command cp -Rf \"$fisher_config/$pkg\" \"$fisher_cache/$pkg/..\"
|
command cp -Rf \"$fisher_config/$pkg\" \"$fisher_cache/$pkg/..\"
|
||||||
else if test -d \"$fisher_cache/$pkg\"
|
else if test -d \"$fisher_cache/$pkg\"
|
||||||
echo cannot connect to server -- using data from \"$fisher_cache/$pkg\" | command sed 's|$HOME|~|' >&2
|
echo cannot connect to server -- searching in \"$fisher_cache/$pkg\" | command sed 's|$HOME|~|' >&2
|
||||||
command cp -Rf \"$fisher_cache/$pkg\" \"$fisher_config/$pkg/..\"
|
command cp -Rf \"$fisher_cache/$pkg\" \"$fisher_config/$pkg/..\"
|
||||||
else
|
else
|
||||||
command rm -rf \"$fisher_config/$pkg\"
|
command rm -rf \"$fisher_config/$pkg\"
|
||||||
echo cannot install \"$pkg\" -- are you offline\? >&2
|
echo cannot install \"$pkg\" -- is this a valid package\? >&2
|
||||||
end
|
end
|
||||||
" >/dev/null &
|
" >/dev/null &
|
||||||
|
|
||||||
@ -260,10 +286,8 @@ function _fisher_pkg_fetch_all
|
|||||||
for pkg in $local_pkgs
|
for pkg in $local_pkgs
|
||||||
set -l path local/$USER
|
set -l path local/$USER
|
||||||
set -l name (command basename $pkg)
|
set -l name (command basename $pkg)
|
||||||
|
|
||||||
command mkdir -p $fisher_config/$path
|
command mkdir -p $fisher_config/$path
|
||||||
command ln -sf $pkg $fisher_config/$path
|
command ln -sf $pkg $fisher_config/$path
|
||||||
|
|
||||||
set actual_pkgs $actual_pkgs $path/$name
|
set actual_pkgs $actual_pkgs $path/$name
|
||||||
_fisher_pkg_install $fisher_config/$path/$name
|
_fisher_pkg_install $fisher_config/$path/$name
|
||||||
end
|
end
|
||||||
@ -280,14 +304,14 @@ function _fisher_pkg_get_deps
|
|||||||
if test ! -d "$path"
|
if test ! -d "$path"
|
||||||
echo $pkg
|
echo $pkg
|
||||||
else if test -s "$path/fishfile"
|
else if test -s "$path/fishfile"
|
||||||
_fisher_pkg_get_deps (_fisher_fishfile_indent < $path/fishfile | _fisher_fishfile_load)
|
_fisher_pkg_get_deps (_fisher_fishfile_format < $path/fishfile | _fisher_fishfile_read)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function _fisher_pkg_install -a pkg
|
function _fisher_pkg_install -a pkg
|
||||||
set -l name (command basename $pkg)
|
set -l name (command basename $pkg)
|
||||||
set -l files $pkg/{functions,completions,conf.d}/* $pkg/*.fish
|
set -l files $pkg/{functions,completions,conf.d}/**.* $pkg/*.fish
|
||||||
for source in $files
|
for source in $files
|
||||||
set -l target (command basename $source)
|
set -l target (command basename $source)
|
||||||
switch $source
|
switch $source
|
||||||
@ -306,7 +330,7 @@ function _fisher_pkg_install -a pkg
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
echo "linking $target" | command sed "s|$HOME|~|" >&2
|
echo "linking $target" | command sed "s|$HOME|~|" >&2
|
||||||
command ln -f $source $target
|
command cp -f $source $target
|
||||||
switch $target
|
switch $target
|
||||||
case \*.fish
|
case \*.fish
|
||||||
source $target >/dev/null 2>/dev/null
|
source $target >/dev/null 2>/dev/null
|
||||||
@ -316,7 +340,7 @@ end
|
|||||||
|
|
||||||
function _fisher_pkg_uninstall -a pkg
|
function _fisher_pkg_uninstall -a pkg
|
||||||
set -l name (command basename $pkg)
|
set -l name (command basename $pkg)
|
||||||
set -l files $pkg/{conf.d,completions,functions}/* $pkg/*.fish
|
set -l files $pkg/{conf.d,completions,functions}/**.* $pkg/*.fish
|
||||||
for source in $files
|
for source in $files
|
||||||
set -l target (command basename $source)
|
set -l target (command basename $source)
|
||||||
set -l filename (command basename $target .fish)
|
set -l filename (command basename $target .fish)
|
||||||
@ -346,30 +370,24 @@ function _fisher_pkg_uninstall -a pkg
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function _fisher_fishfile_indent -a pkgs
|
function _fisher_fishfile_read
|
||||||
|
command awk -v FS=\# '!/^#/ && NF { print $1 }'
|
||||||
|
end
|
||||||
|
|
||||||
|
function _fisher_fishfile_format -a pkgs
|
||||||
command awk -v PWD=$PWD -v HOME=$HOME -v PKGS="$pkgs" '
|
command awk -v PWD=$PWD -v HOME=$HOME -v PKGS="$pkgs" '
|
||||||
function normalize(s) {
|
|
||||||
gsub(/^[ \t]*|[ \t]*$|https?:\/\/|github\.com\/|\.git$|\/$/, "", s)
|
|
||||||
sub(/^\.\//, PWD"/", s)
|
|
||||||
sub(HOME, "~", s)
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
function get_pkg_name(s) {
|
|
||||||
split(s, tmp, /[@# ]+/)
|
|
||||||
return tmp[1]
|
|
||||||
}
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
pkg_count = split(PKGS, pkgs, ";") - 1
|
pkg_count = split(PKGS, pkgs, ";") - 1
|
||||||
cmd = pkgs[1]
|
cmd = pkgs[1]
|
||||||
for (i = 2; i <= pkg_count; i++) {
|
for (i = 2; i <= pkg_count; i++) {
|
||||||
pkg_ids[i - 1] = get_pkg_name( pkgs[i] = normalize(pkgs[i]) )
|
pkg_ids[i - 1] = get_pkg_id( pkgs[i] = normalize(pkgs[i]) )
|
||||||
}
|
}
|
||||||
} {
|
} {
|
||||||
if (NF) {
|
if (NF) {
|
||||||
nl = nl > 0 ? "" : nl
|
$0 = normalize($0)
|
||||||
pkg_id = get_pkg_name( $0 = normalize($0) )
|
newln = newln > 0 ? "" : newln
|
||||||
if (/^#/) print nl$0
|
if (/^#/) print newln$0
|
||||||
else if (!seen[pkg_id]++) {
|
else if (!seen[(pkg_id = get_pkg_id($0))]++) {
|
||||||
for (i = 1; i < pkg_count; i++) {
|
for (i = 1; i < pkg_count; i++) {
|
||||||
if (pkg_ids[i] == pkg_id) {
|
if (pkg_ids[i] == pkg_id) {
|
||||||
if (cmd == "rm") next
|
if (cmd == "rm") next
|
||||||
@ -377,10 +395,10 @@ function _fisher_fishfile_indent -a pkgs
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print nl$0
|
print newln$0
|
||||||
}
|
}
|
||||||
nl = NF
|
newln = NF
|
||||||
} else if (nl) nl = (nl > 0 ? "" : nl)"\n"
|
} else if (newln) newln = "\n"(newln > 0 ? "" : newln)
|
||||||
}
|
}
|
||||||
END {
|
END {
|
||||||
if (cmd == "rm" || pkg_count <= 1) exit
|
if (cmd == "rm" || pkg_count <= 1) exit
|
||||||
@ -388,22 +406,29 @@ function _fisher_fishfile_indent -a pkgs
|
|||||||
if (!seen[pkg_ids[i - 1]]) print pkgs[i]
|
if (!seen[pkg_ids[i - 1]]) print pkgs[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function normalize(s) {
|
||||||
|
gsub(/^[ \t]*(https?:\/\/)?(github\.com\/)?|[\/ \t]*$/, "", s)
|
||||||
|
sub(/^\.\//, PWD"/", s)
|
||||||
|
sub(HOME, "~", s)
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
function get_pkg_id(s) {
|
||||||
|
return (split(s, tmp, /@+|:/) > 2) ? tmp[2]"/"tmp[1]"/"tmp[3] : tmp[1]
|
||||||
|
}
|
||||||
'
|
'
|
||||||
end
|
end
|
||||||
|
|
||||||
function _fisher_fishfile_load
|
function _fisher_status -a added updated removed elapsed
|
||||||
command awk -v FS=\# '!/^#/ && NF { print $1 }'
|
command awk -v ADDED=$added -v UPDATED=$updated -v REMOVED=$removed -v ELAPSED=$elapsed '
|
||||||
end
|
BEGIN {
|
||||||
|
if (ADDED = ADDED - UPDATED) res = msg(res, "added", ADDED)
|
||||||
function _fisher_status_report
|
if (UPDATED) res = msg(res, "updated", UPDATED)
|
||||||
command awk '
|
if (REMOVED = REMOVED - UPDATED) res = msg(res, "removed", REMOVED)
|
||||||
|
printf((res ? res : "done") " in %.2fs\n", ELAPSED / 1000)
|
||||||
|
}
|
||||||
function msg(res, str, n) {
|
function msg(res, str, n) {
|
||||||
return (res ? res ", " : "") str " " n " package" (n > 1 ? "s" : "")
|
return (res ? res ", " : "") str " " n " package" (n > 1 ? "s" : "")
|
||||||
}
|
}
|
||||||
$1 = $1 - $2 { res = msg(res, "added", $1) }
|
|
||||||
$2 { res = msg(res, "updated", $2) }
|
|
||||||
$3 = $3 - $2 { res = msg(res, "removed", $3) }
|
|
||||||
{ printf((res ? res : "done") " in %.2fs\n", ($4 / 1000)) }
|
|
||||||
'
|
'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user