fzf: Update to 0.16 (and use --height)

master
Pierre Neidhardt 2017-01-16 10:55:46 +01:00
parent 38efb2d440
commit 1279fe654c
4 changed files with 23 additions and 66 deletions

View File

@ -21,7 +21,7 @@ function fish_prompt
(set_color -o $cwd_color)$PROMPT_PWD \
(set_color normal) \
(set_color -o)']'
echo
echo '> '
end

View File

@ -3,4 +3,6 @@ function fish_user_key_bindings
if type -pq fzf
source $fish_config_path/fzf.fish
end
bind \el downcase-word
end

View File

@ -1,22 +1,22 @@
fzf_key_bindings
bind \cT transpose-chars
bind \e\ct __fzf-file-widget
bind \e\ct fzf-file-widget
bind \ec capitalize-word
bind \eC __fzf-cd-widget
bind \eC fzf-cd-widget
function __fzf-select -d 'fzf commandline and print unescaped selection back to commandline'
function fzf-select -d 'fzf commandline and print unescaped selection back to commandline'
set -l cmd (commandline -j)
[ "$cmd" ]; or return
eval $cmd | eval (__fzfcmd) -m --tiebreak=index --select-1 --exit-0 | string join ' ' | read -l result
[ "$result" ]; and commandline -j -- $result
commandline -f repaint
end
bind \e\cm __fzf-select
bind \e\cm fzf-select
function __fzf-complete -d 'fzf completion and print selection back to commandline'
function fzf-complete -d 'fzf completion and print selection back to commandline'
set -l complist (complete -C(commandline -c))
set -l result
string join -- \n $complist | sort | eval (__fzfcmd) -m --tiebreak=index --select-1 --exit-0 --header '(commandline)' | cut -f1 | while read -l r; set result $result $r; end
string join -- \n $complist | sort | fzf -m --tiebreak=index --select-1 --exit-0 --header '(commandline)' | cut -f1 | while read -l r; set result $result $r; end
for i in (seq (count $result))
set -l r $result[$i]
@ -39,74 +39,21 @@ function __fzf-complete -d 'fzf completion and print selection back to commandli
commandline -f repaint
end
bind \t __fzf-complete
bind \t fzf-complete
## TODO: 'complete' is not completely finished, keep original version for now.
bind \e\t complete
## DONE: Report missing (commandline) upstream.
## TODO: Report use of 'read'.
function __fzf-history-widget
history | eval (__fzfcmd) +m --tiebreak=index $FZF_CTRL_R_OPTS -q '(commandline)' | read -l result
and commandline -- $result
commandline -f repaint
end
bind \cr __fzf-history-widget
## Like original but uses last token as root for 'find'.
## If last token is a path, you can use it as $cwd in FZF_CTRL_T_COMMAND to
## restrict search to this path.
## TODO: Report upstream. Makes '**' obsolete for bash and zsh.
function __fzf-file-widget
set -l cwd (commandline -t)
## The commandline token might be escaped, we need to unescape it.
set cwd (eval "printf '%s' $cwd")
if [ ! -d "$cwd" ]
set cwd .
end
set -q FZF_CTRL_T_COMMAND; or set -l FZF_CTRL_T_COMMAND "
command find -L \$cwd \\( -path \$cwd'*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
-o -type f -print \
-o -type d -print \
-o -type l -print 2> /dev/null | sed 1d"
eval "$FZF_CTRL_T_COMMAND | "(__fzfcmd)" -m $FZF_CTRL_T_OPTS" | while read -l r; set result $result $r; end
if [ -z "$result" ]
commandline -f repaint
return
end
if [ "$cwd" != . ]
## Remove last token from commandline.
commandline -t ""
end
for i in $result
commandline -it -- (string escape $i)
commandline -it -- ' '
end
commandline -f repaint
end
function __fzf-cd-widget
set -q FZF_ALT_C_COMMAND; or set -l FZF_ALT_C_COMMAND "
command find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
-o -type d -print 2> /dev/null | sed 1d | cut -b3-"
eval "$FZF_ALT_C_COMMAND | "(__fzfcmd)" +m --select-1 --exit-0 $FZF_ALT_C_OPTS" | read -l result
[ "$result" ]; and cd $result
commandline -f repaint
end
function __fzf-bcd-widget -d 'cd backwards'
function fzf-bcd-widget -d 'cd backwards'
## TODO: (fish upsteam bug) Cannot use eval here.
# pwd | awk -v RS=/ '/\n/ {exit} {p=p $0 "/"; print p}' | tac | eval (__fzfcmd) +m --select-1 --exit-0 $FZF_BCD_OPTS | read -l result
pwd | awk -v RS=/ '/\n/ {exit} {p=p $0 "/"; print p}' | tac | fzf +m --select-1 --exit-0 --preview='preview {}' | read -l result
[ "$result" ]; and cd $result
commandline -f repaint
end
bind \e\cL __fzf-bcd-widget
bind \e\cL fzf-bcd-widget
function __fzf-cdhist-widget -d 'cd to one of the previously visited location'
function fzf-cdhist-widget -d 'cd to one of the previously visited locations'
## Clear non-existent folders from cdhist.
set -l buf
for i in (seq 1 (count $dirprev))
@ -122,4 +69,4 @@ function __fzf-cdhist-widget -d 'cd to one of the previously visited location'
[ "$result" ]; and cd $result
commandline -f repaint
end
bind \er __fzf-cdhist-widget
bind \er fzf-cdhist-widget

View File

@ -130,11 +130,19 @@ fi
## fzf
if command -v fzf >/dev/null 2>&1; then
export FZF_DEFAULT_OPTS="--reverse --inline-info --cycle --extended --multi --select-1 --exit-0 --bind=ctrl-k:kill-line,ctrl-j:accept,alt-s:toggle-sort,ctrl-v:page-down,alt-v:page-up,alt-a:toggle-all,alt-i:toggle-up,alt-z:toggle-preview"
export FZF_DEFAULT_OPTS="--reverse --inline-info --height 40% --cycle --extended --multi --select-1 --exit-0 --bind=ctrl-k:kill-line,ctrl-j:accept,alt-s:toggle-sort,ctrl-v:page-down,alt-v:page-up,alt-a:toggle-all,alt-i:toggle-up,alt-z:toggle-preview"
export FZF_ALT_C_OPTS="--preview='preview {}'"
export FZF_BCD_OPTS=$FZF_ALT_C_OPTS
export FZF_CDHIST_OPTS=$FZF_ALT_C_OPTS
export FZF_CTRL_R_OPTS="--reverse"
export FZF_CTRL_T_OPTS="--bind=ctrl-j:'execute-multi(rifle {})' --preview='preview {}'"
if [ "$(uname -o)" = "GNU/Linux" ]; then
## Append '/' to folder names. GNU find required.
export FZF_CTRL_T_COMMAND="command find -L \$dir -mindepth 1 \\( -path \$dir'*/\\.*' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \
-o -type f -print \
-o -type d -printf '%p/\n' \
-o -type l -print 2> /dev/null | sed 's#^\./##'"
fi
fi
## pacman abs