From 081dc5ccc110642a58f2500dfe839d0e3bf6fd7a Mon Sep 17 00:00:00 2001 From: Sergey Besedin Date: Mon, 15 Nov 2021 00:26:15 +0400 Subject: [PATCH] Update --- config/fish/conf.d/fzf.fish | 63 ++++++++++++++++--- config/fish/fishfile | 1 - config/fish/functions/__fzf_complete.fish | 1 - config/fish/functions/__fzf_get_dir.fish | 4 +- config/fish/functions/__fzf_open.fish | 4 +- .../functions/__fzf_parse_commandline.fish | 4 +- .../fish/functions/__fzf_reverse_isearch.fish | 2 +- config/fish/functions/__fzfcmd.fish | 2 +- local/bin/.keep | 0 ruby/bin/.keep | 0 10 files changed, 64 insertions(+), 17 deletions(-) create mode 100644 local/bin/.keep create mode 100644 ruby/bin/.keep diff --git a/config/fish/conf.d/fzf.fish b/config/fish/conf.d/fzf.fish index e88f48e..d22f583 100644 --- a/config/fish/conf.d/fzf.fish +++ b/config/fish/conf.d/fzf.fish @@ -1,14 +1,63 @@ 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_DISABLE_KEYBINDINGS; or set -U FZF_DISABLE_KEYBINDINGS 0 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 - # disabled until we figure out a sensible way to ensure user overrides - # are not erased - # set -l _vars (set | command grep -E "^FZF.*\$" | command awk '{print $1;}') - # for var in $_vars - # eval (set -e $var) - # end +if test "$FZF_DISABLE_KEYBINDINGS" -ne 1 + 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 ! test "$fish_key_bindings" = fish_default_key_bindings + 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 \co '__fzf_find_file' + bind \cr '__fzf_reverse_isearch' + bind \ec '__fzf_cd' + bind \eC '__fzf_cd --hidden' + bind \eO '__fzf_open' + bind \eo '__fzf_open --editor' + + if ! test "$fish_key_bindings" = fish_default_key_bindings + bind -M insert \co '__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 \eO '__fzf_open' + bind -M insert \eo '__fzf_open --editor' + end + end + + if not bind --user \t >/dev/null 2>/dev/null + if set -q FZF_COMPLETE + bind \t '__fzf_complete' + if ! test "$fish_key_bindings" = fish_default_key_bindings + bind -M insert \t '__fzf_complete' + end + end + end +end + +function _fzf_uninstall -e fzf_uninstall + bind --user \ + | string replace --filter --regex -- "bind (.+)( '?__fzf.*)" 'bind -e $1' \ + | source + + set --names \ + | string replace --filter --regex '(^FZF)' 'set --erase $1' \ + | source + + functions --erase _fzf_uninstall end diff --git a/config/fish/fishfile b/config/fish/fishfile index 7e81aa8..16aeb7e 100644 --- a/config/fish/fishfile +++ b/config/fish/fishfile @@ -1,3 +1,2 @@ rbenv/fish-rbenv jethrokuan/fzf -jorgebucaran/fish-spark diff --git a/config/fish/functions/__fzf_complete.fish b/config/fish/functions/__fzf_complete.fish index d4894de..e8848fa 100644 --- a/config/fish/functions/__fzf_complete.fish +++ b/config/fish/functions/__fzf_complete.fish @@ -58,7 +58,6 @@ function __fzf_complete -d 'fzf completion and print selection back to commandli set -l query string join -- \n $complist \ - | sort \ | eval (__fzfcmd) (string escape --no-quoted -- $initial_query) --print-query (__fzf_complete_opts) \ | cut -f1 \ | while read -l r diff --git a/config/fish/functions/__fzf_get_dir.fish b/config/fish/functions/__fzf_get_dir.fish index a32ac83..77c873c 100644 --- a/config/fish/functions/__fzf_get_dir.fish +++ b/config/fish/functions/__fzf_get_dir.fish @@ -2,12 +2,12 @@ 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 ] + 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 [ ! -d "$dir" ] + 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") diff --git a/config/fish/functions/__fzf_open.fish b/config/fish/functions/__fzf_open.fish index c91c093..aa5ca61 100644 --- a/config/fish/functions/__fzf_open.fish +++ b/config/fish/functions/__fzf_open.fish @@ -39,7 +39,7 @@ function __fzf_open -d "Open files and directories." -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 -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 @@ -54,7 +54,7 @@ function __fzf_open -d "Open files and directories." set -l open_status 0 if not test -z "$select" - commandline "$open_cmd \"$select\"" ;and commandline -f execute + commandline "$open_cmd $select"; and commandline -f execute set open_status $status end diff --git a/config/fish/functions/__fzf_parse_commandline.fish b/config/fish/functions/__fzf_parse_commandline.fish index 80bf3eb..2cc9dfb 100644 --- a/config/fish/functions/__fzf_parse_commandline.fish +++ b/config/fish/functions/__fzf_parse_commandline.fish @@ -2,14 +2,14 @@ function __fzf_parse_commandline -d 'Parse the current command line token and re # eval is used to do shell expansion on paths set -l commandline (eval "printf '%s' "(commandline -t)) - if [ -z $commandline ] + if test -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 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 diff --git a/config/fish/functions/__fzf_reverse_isearch.fish b/config/fish/functions/__fzf_reverse_isearch.fish index 7b31d33..2ebbe20 100644 --- a/config/fish/functions/__fzf_reverse_isearch.fish +++ b/config/fish/functions/__fzf_reverse_isearch.fish @@ -1,6 +1,6 @@ function __fzf_reverse_isearch history merge - 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 + 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 index 3acdbad..821c650 100644 --- a/config/fish/functions/__fzfcmd.fish +++ b/config/fish/functions/__fzfcmd.fish @@ -1,7 +1,7 @@ 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 ] + if test $FZF_TMUX -eq 1 echo "fzf-tmux -d$FZF_TMUX_HEIGHT" else echo "fzf" diff --git a/local/bin/.keep b/local/bin/.keep new file mode 100644 index 0000000..e69de29 diff --git a/ruby/bin/.keep b/ruby/bin/.keep new file mode 100644 index 0000000..e69de29