This commit is contained in:
Sergey 2021-11-15 00:26:15 +04:00
parent 8583c61d95
commit 081dc5ccc1
10 changed files with 64 additions and 17 deletions

View File

@ -1,14 +1,63 @@
set -q FZF_TMUX_HEIGHT; or set -U FZF_TMUX_HEIGHT "40%" 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_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_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_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" set -q FZF_PREVIEW_DIR_CMD; or set -U FZF_PREVIEW_DIR_CMD "ls"
function fzf_uninstall -e fzf_uninstall if test "$FZF_DISABLE_KEYBINDINGS" -ne 1
# disabled until we figure out a sensible way to ensure user overrides if test "$FZF_LEGACY_KEYBINDINGS" -eq 1
# are not erased bind \ct '__fzf_find_file'
# set -l _vars (set | command grep -E "^FZF.*\$" | command awk '{print $1;}') bind \cr '__fzf_reverse_isearch'
# for var in $_vars bind \ec '__fzf_cd'
# eval (set -e $var) bind \eC '__fzf_cd --hidden'
# end 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 end

View File

@ -1,3 +1,2 @@
rbenv/fish-rbenv rbenv/fish-rbenv
jethrokuan/fzf jethrokuan/fzf
jorgebucaran/fish-spark

View File

@ -58,7 +58,6 @@ function __fzf_complete -d 'fzf completion and print selection back to commandli
set -l query set -l query
string join -- \n $complist \ string join -- \n $complist \
| sort \
| eval (__fzfcmd) (string escape --no-quoted -- $initial_query) --print-query (__fzf_complete_opts) \ | eval (__fzfcmd) (string escape --no-quoted -- $initial_query) --print-query (__fzf_complete_opts) \
| cut -f1 \ | cut -f1 \
| while read -l r | while read -l r

View File

@ -2,12 +2,12 @@ function __fzf_get_dir -d 'Find the longest existing filepath from input string'
set dir $argv set dir $argv
# Strip all trailing slashes. Ignore if $dir is root dir (/) # 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) set dir (string replace -r '/*$' '' $dir)
end end
# Iteratively check if dir exists and strip tail end of path # 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 absolute, this can keep going until ends up at /
# If path is relative, this can keep going until entire input is consumed, dirname returns "." # If path is relative, this can keep going until entire input is consumed, dirname returns "."
set dir (dirname "$dir") set dir (dirname "$dir")

View File

@ -39,7 +39,7 @@ function __fzf_open -d "Open files and directories."
-o -type d -print \ -o -type d -print \
-o -type l -print 2> /dev/null | sed 's@^\./@@'" -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 how to open
set -l open_cmd set -l open_cmd
@ -54,7 +54,7 @@ function __fzf_open -d "Open files and directories."
set -l open_status 0 set -l open_status 0
if not test -z "$select" 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 set open_status $status
end end

View File

@ -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 # eval is used to do shell expansion on paths
set -l commandline (eval "printf '%s' "(commandline -t)) set -l commandline (eval "printf '%s' "(commandline -t))
if [ -z $commandline ] if test -z $commandline
# Default to current directory with no --query # Default to current directory with no --query
set dir '.' set dir '.'
set fzf_query '' set fzf_query ''
else else
set dir (__fzf_get_dir $commandline) 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 # if $dir is "." but commandline is not a relative path, this means no file path found
set fzf_query $commandline set fzf_query $commandline
else else

View File

@ -1,6 +1,6 @@
function __fzf_reverse_isearch function __fzf_reverse_isearch
history merge 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 and commandline -- $result
commandline -f repaint commandline -f repaint
end end

View File

@ -1,7 +1,7 @@
function __fzfcmd function __fzfcmd
set -q FZF_TMUX; or set FZF_TMUX 0 set -q FZF_TMUX; or set FZF_TMUX 0
set -q FZF_TMUX_HEIGHT; or set FZF_TMUX_HEIGHT 40% 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" echo "fzf-tmux -d$FZF_TMUX_HEIGHT"
else else
echo "fzf" echo "fzf"

0
local/bin/.keep Normal file
View File

0
ruby/bin/.keep Normal file
View File