From 1279fe654cd64ee34ded1a5c9cc62b2b95476e69 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Mon, 16 Jan 2017 10:55:46 +0100 Subject: [PATCH] fzf: Update to 0.16 (and use --height) --- .config/fish/functions/fish_prompt.fish | 2 +- .../functions/fish_user_key_bindings.fish | 2 + .config/fish/fzf.fish | 75 +++---------------- .profile | 10 ++- 4 files changed, 23 insertions(+), 66 deletions(-) diff --git a/.config/fish/functions/fish_prompt.fish b/.config/fish/functions/fish_prompt.fish index bd3298b0..721e6b21 100644 --- a/.config/fish/functions/fish_prompt.fish +++ b/.config/fish/functions/fish_prompt.fish @@ -21,7 +21,7 @@ function fish_prompt (set_color -o $cwd_color)$PROMPT_PWD \ (set_color normal) \ (set_color -o)']' - + echo echo '> ' end diff --git a/.config/fish/functions/fish_user_key_bindings.fish b/.config/fish/functions/fish_user_key_bindings.fish index 75c63550..fb90ebf0 100644 --- a/.config/fish/functions/fish_user_key_bindings.fish +++ b/.config/fish/functions/fish_user_key_bindings.fish @@ -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 diff --git a/.config/fish/fzf.fish b/.config/fish/fzf.fish index 1578bc5d..dd5e4ec5 100644 --- a/.config/fish/fzf.fish +++ b/.config/fish/fzf.fish @@ -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 diff --git a/.profile b/.profile index 14ca11b4..158efa25 100644 --- a/.profile +++ b/.profile @@ -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