diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2017-01-16 02:43:56 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-16 02:43:56 +0900 |
commit | 05ed57a9f06cc59f07065f74051012c80088d1f2 (patch) | |
tree | d39eb112954d93de7a476abd4e4019fffebc3bdc | |
parent | 1896aa174877da2e5c6be35219a0a1abcdc4fbf1 (diff) | |
parent | 4bece042077dbf2a37e4f6a9e03e34e2cd20014c (diff) |
Merge pull request #794 from junegunn/devel0.16.0
0.16.0
-rw-r--r-- | .travis.yml | 2 | ||||
-rw-r--r-- | CHANGELOG.md | 12 | ||||
-rw-r--r-- | README.md | 47 | ||||
-rwxr-xr-x | bin/fzf-tmux | 3 | ||||
-rwxr-xr-x | install | 13 | ||||
-rw-r--r-- | man/man1/fzf-tmux.1 | 4 | ||||
-rw-r--r-- | man/man1/fzf.1 | 36 | ||||
-rw-r--r-- | plugin/fzf.vim | 28 | ||||
-rw-r--r-- | shell/completion.bash | 63 | ||||
-rw-r--r-- | shell/completion.zsh | 19 | ||||
-rw-r--r-- | shell/key-bindings.bash | 32 | ||||
-rw-r--r-- | shell/key-bindings.fish | 31 | ||||
-rw-r--r-- | shell/key-bindings.zsh | 14 | ||||
-rw-r--r-- | src/algo/algo.go | 87 | ||||
-rw-r--r-- | src/algo/algo_test.go | 21 | ||||
-rw-r--r-- | src/algo/normalize.go | 424 | ||||
-rw-r--r-- | src/constants.go | 2 | ||||
-rw-r--r-- | src/core.go | 2 | ||||
-rw-r--r-- | src/options.go | 55 | ||||
-rw-r--r-- | src/pattern.go | 24 | ||||
-rw-r--r-- | src/pattern_test.go | 30 | ||||
-rw-r--r-- | src/result.go | 2 | ||||
-rw-r--r-- | src/result_test.go | 15 | ||||
-rw-r--r-- | src/terminal.go | 317 | ||||
-rw-r--r-- | src/tui/light.go | 820 | ||||
-rw-r--r-- | src/tui/ncurses.go | 268 | ||||
-rw-r--r-- | src/tui/tcell.go | 286 | ||||
-rw-r--r-- | src/tui/tui.go | 194 | ||||
-rw-r--r-- | src/tui/tui_test.go | 24 | ||||
-rw-r--r-- | src/util/util.go | 16 | ||||
-rw-r--r-- | src/util/util_unix.go | 6 | ||||
-rw-r--r-- | src/util/util_windows.go | 6 | ||||
-rw-r--r-- | test/test_go.rb | 314 |
33 files changed, 2484 insertions, 733 deletions
diff --git a/.travis.yml b/.travis.yml index a1a6497d..3f2a67f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: ruby matrix: include: - env: TAGS= - rvm: 2.2.0 + rvm: 2.3.3 # - env: TAGS=tcell # rvm: 2.2.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index a37b74c5..d46df325 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,18 @@ CHANGELOG ========= +0.16.0 +------ +- *Added `--height HEIGHT[%]` option* + - fzf can now display finder without occupying the full screen +- Preview window will truncate long lines by default. Line wrap can be enabled + by `:wrap` flag in `--preview-window`. +- Latin script letters will be normalized before matching so that it's easier + to match against accented letters. e.g. `sodanco` can match `Só Danço Samba`. + - Normalization can be disabled via `--literal` +- Added `--filepath-word` to make word-wise movements/actions (`alt-b`, + `alt-f`, `alt-bs`, `alt-d`) respect path separators + 0.15.9 ------ - Fixed rendering glitches introduced in 0.15.8 @@ -123,6 +123,29 @@ vim $(fzf) - Mouse: scroll, click, double-click; shift-click and shift-scroll on multi-select mode +#### Layout + +fzf by default starts in fullscreen mode, but you can make it start below the +cursor with `--height` option. + +```sh +vim $(fzf --height 40%) +``` + +Also check out `--reverse` option if you prefer "top-down" layout instead of +the default "bottom-up" layout. + +```sh +vim $(fzf --height 40% --reverse) +``` + +You can add these options to `$FZF_DEFAULT_OPTS` so that they're applied by +default. + +```sh +export FZF_DEFAULT_OPTS='--height 40% --reverse' +``` + #### Search syntax Unless otherwise specified, fzf starts in "extended-search mode" where you can @@ -189,6 +212,13 @@ cat /usr/share/dict/words | fzf-tmux -l 20% --multi --reverse It will still work even when you're not on tmux, silently ignoring `-[udlr]` options, so you can invariably use `fzf-tmux` in your scripts. +Alternatively, you can use `--height HEIGHT[%]` option not to start fzf in +fullscreen mode. + +```sh +fzf --height 40% +``` + Key bindings for command line ----------------------------- @@ -206,9 +236,9 @@ fish. - Set `FZF_ALT_C_COMMAND` to override the default command - Set `FZF_ALT_C_OPTS` to pass additional options -If you're on a tmux session, fzf will start in a split pane. You may disable -this tmux integration by setting `FZF_TMUX` to 0, or change the height of the -pane with `FZF_TMUX_HEIGHT` (e.g. `20`, `50%`). +If you're on a tmux session, you can start fzf in a split pane by setting +`FZF_TMUX` to 1, and change the height of the pane with `FZF_TMUX_HEIGHT` +(e.g. `20`, `50%`). If you use vi mode on bash, you need to add `set -o vi` *before* `source ~/.fzf.bash` in your .bashrc, so that it correctly sets up key bindings for vi @@ -466,12 +496,9 @@ valid directory. Example: set -l FZF_CTRL_T_COMMAND "command find -L \$dir -type f 2> /dev/null | sed '1d; s#^\./##'" ``` -License -------- - -[MIT](LICENSE) +[License](LICENSE) +------------------ -Author ------- +The MIT License (MIT) -Junegunn Choi +Copyright (c) 2017 Junegunn Choi diff --git a/bin/fzf-tmux b/bin/fzf-tmux index dd335d2b..f2011998 100755 --- a/bin/fzf-tmux +++ b/bin/fzf-tmux @@ -114,6 +114,9 @@ if [[ -z "$TMUX" || "$opt" =~ ^-h && "$columns" -le 40 || ! "$opt" =~ ^-h && "$l exit $? fi +# --height option is not allowed +args+=("--no-height") + # Handle zoomed tmux pane by moving it to a temp window if tmux list-panes -F '#F' | grep -q Z; then zoomed=1 @@ -2,9 +2,7 @@ set -u -[[ "$@" =~ --pre ]] && version=0.15.9 pre=1 || - version=0.15.9 pre=0 - +version=0.16.0 auto_completion= key_bindings= update_config=2 @@ -48,7 +46,7 @@ for opt in "$@"; do --no-update-rc) update_config=0 ;; --32) binary_arch=386 ;; --64) binary_arch=amd64 ;; - --bin|--pre) ;; + --bin) ;; *) echo "unknown option: $opt" help @@ -121,7 +119,7 @@ try_wget() { download() { echo "Downloading bin/fzf ..." - if [ $pre = 0 ]; then + if [[ ! "$version" =~ alpha ]]; then if [ -x "$fzf_base"/bin/fzf ]; then echo " - Already exists" check_binary && return @@ -137,7 +135,10 @@ download() { return fi - local url=https://github.com/junegunn/fzf-bin/releases/download/$version/${1}.tgz + local url + [[ "$version" =~ alpha ]] && + url=https://github.com/junegunn/fzf-bin/releases/download/alpha/${1}.tgz || + url=https://github.com/junegunn/fzf-bin/releases/download/$version/${1}.tgz set -o pipefail if ! (try_curl $url || try_wget $url); then set +o pipefail diff --git a/man/man1/fzf-tmux.1 b/man/man1/fzf-tmux.1 index 6f211398..6ccdb660 100644 --- a/man/man1/fzf-tmux.1 +++ b/man/man1/fzf-tmux.1 @@ -1,7 +1,7 @@ .ig The MIT License (MIT) -Copyright (c) 2016 Junegunn Choi +Copyright (c) 2017 Junegunn Choi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -21,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. .. -.TH fzf-tmux 1 "Nov 2016" "fzf 0.15.9" "fzf-tmux - open fzf in tmux split pane" +.TH fzf-tmux 1 "Jan 2017" "fzf 0.16.0" "fzf-tmux - open fzf in tmux split pane" .SH NAME fzf-tmux - open fzf in tmux split pane diff --git a/man/man1/fzf.1 b/man/man1/fzf.1 index 4e19ce92..a7abf84b 100644 --- a/man/man1/fzf.1 +++ b/man/man1/fzf.1 @@ -1,7 +1,7 @@ .ig The MIT License (MIT) -Copyright (c) 2016 Junegunn Choi +Copyright (c) 2017 Junegunn Choi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -21,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. .. -.TH fzf 1 "Nov 2016" "fzf 0.15.9" "fzf - a command-line fuzzy finder" +.TH fzf 1 "Jan 2017" "fzf 0.16.0" "fzf - a command-line fuzzy finder" .SH NAME fzf - a command-line fuzzy finder @@ -48,6 +48,9 @@ Case-insensitive match (default: smart-case match) .B "+i" Case-sensitive match .TP +.B "--literal" +Do not normalize latin script letters for matching. +.TP .BI "--algo=" TYPE Fuzzy matching algorithm (default: v2) @@ -126,10 +129,30 @@ Number of screen columns to keep to the right of the highlighted substring (default: 10). Setting it to a large value will cause the text to be positioned on the center of the screen. .TP +.B "--filepath-word" +Make word-wise movements and actions respect path separators. The following +actions are affected: + +\fBbackward-kill-word\fR +.br +\fBbackward-word\fR +.br +\fBforward-word\fR +.br +\fBkill-word\fR +.TP .BI "--jump-labels=" "CHARS" Label characters for \fBjump\fR and \fBjump-accept\fR .SS Layout .TP +.BI "--height=" "HEIGHT[%]" +Display fzf window below the cursor with the given height instead of using +the full screen. +.TP +.BI "--min-height=" "HEIGHT" +Minimum height when \fB--height\fR is given in percent (default: 10). +Ignored when \fB--height\fR is not specified. +.TP .B "--reverse" Reverse orientation .TP @@ -185,7 +208,9 @@ Number of spaces for a tab character (default: 8) .BI "--color=" "[BASE_SCHEME][,COLOR:ANSI]" Color configuration. The name of the base color scheme is followed by custom color mappings. Ansi color code of -1 denotes terminal default -foreground/background color. +foreground/background color. You can also specify 24-bit color in \fB#rrggbb\fR +format, but the support for 24-bit colors is experimental and only works when +\fB--height\fR option is used. .RS e.g. \fBfzf --color=bg+:24\fR @@ -248,10 +273,11 @@ e.g. \fBfzf --preview="head -$LINES {}"\fR Note that you can escape a placeholder pattern by prepending a backslash. .RE .TP -.BI "--preview-window=" "[POSITION][:SIZE[%]][:hidden]" +.BI "--preview-window=" "[POSITION][:SIZE[%]][:wrap][:hidden]" Determine the layout of the preview window. If the argument ends with \fB:hidden\fR, the preview window will be hidden by default until -\fBtoggle-preview\fR action is triggered. +\fBtoggle-preview\fR action is triggered. Long lines are truncated by default. +Line wrap can be enabled with \fB:wrap\fR flag. .RS .B POSITION: (default: right) diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 046c3242..4064a559 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -297,14 +297,25 @@ try else let prefix = '' endif - let tmux = (!has('nvim') || get(g:, 'fzf_prefer_tmux', 0)) && s:tmux_enabled() && s:splittable(dict) + + let use_height = has_key(dict, 'down') && + \ !(has('nvim') || has('win32') || has('win64') || s:present(dict, 'up', 'left', 'right')) && + \ executable('tput') && filereadable('/dev/tty') + let tmux = !use_height && (!has('nvim') || get(g:, 'fzf_prefer_tmux', 0)) && s:tmux_enabled() && s:splittable(dict) + let term = has('nvim') && !tmux + if use_height + let optstr .= ' --height='.s:calc_size(&lines, dict.down, dict) + elseif term + let optstr .= ' --no-height' + endif let command = prefix.(tmux ? s:fzf_tmux(dict) : fzf_exec).' '.optstr.' > '.temps.result - if has('nvim') && !tmux + if term return s:execute_term(dict, command, temps) endif - let lines = tmux ? s:execute_tmux(dict, command, temps) : s:execute(dict, command, temps) + let lines = tmux ? s:execute_tmux(dict, command, temps) + \ : s:execute(dict, command, use_height, temps) call s:callback(dict, lines) return lines finally @@ -401,9 +412,9 @@ function! s:exit_handler(code, command, ...) return 1 endfunction -function! s:execute(dict, command, temps) abort +function! s:execute(dict, command, use_height, temps) abort call s:pushd(a:dict) - if has('unix') + if has('unix') && !a:use_height silent! !clear 2> /dev/null endif let escaped = escape(substitute(a:command, '\n', '\\n', 'g'), '%#') @@ -417,7 +428,12 @@ function! s:execute(dict, command, temps) abort else let command = escaped endif - execute 'silent !'.command + if a:use_height + let stdin = has_key(a:dict, 'source') ? '' : '< /dev/tty' + call system(printf('tput cup %d > /dev/tty; tput cnorm > /dev/tty; %s %s 2> /dev/tty', &lines, command, stdin)) + else + execute 'silent !'.command + endif let exit_status = v:shell_error redraw! return s:exit_handler(exit_status, command) ? s:collect(a:temps) : [] diff --git a/shell/completion.bash b/shell/completion.bash index 392aee2d..6ef03860 100644 --- a/shell/completion.bash +++ b/shell/completion.bash @@ -5,7 +5,7 @@ # / __/ / /_/ __/ # /_/ /___/_/-completion.bash # -# - $FZF_TMUX (default: 1) +# - $FZF_TMUX (default: 0) # - $FZF_TMUX_HEIGHT (default: '40%') # - $FZF_COMPLETION_TRIGGER (default: '**') # - $FZF_COMPLETION_OPTS (default: empty) @@ -30,6 +30,14 @@ fi ########################################################### +# To redraw line after fzf closes (printf '\e[5n') +bind '"\e[0n": redraw-current-line' + +__fzfcmd_complete() { + [ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ] && + echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf" +} + _fzf_orig_completion_filter() { sed 's/^\(.*-F\) *\([^ ]*\).* \([^ ]*\)$/export _fzf_orig_completion_\3="\1 %s \3 #\2";/' | awk -F= '{gsub(/[^A-Za-z0-9_= ;]/, "_", $1); print $1"="$2}' @@ -43,35 +51,43 @@ _fzf_opts_completion() { opts=" -x --extended -e --exact + --algo -i +i -n --nth + --with-nth -d --delimiter +s --no-sort --tac --tiebreak - --bind -m --multi --no-mouse - --color - --black - --reverse + --bind + --cycle --no-hscroll + --jump-labels + --height + --literal + --reverse + --margin --inline-info --prompt + --header + --header-lines + --ansi + --tabstop + --color + --no-bold + --history + --history-size + --preview + --preview-window -q --query -1 --select-1 -0 --exit-0 -f --filter --print-query --expect - --toggle-sort - --sync - --cycle - --history - --history-size - --header - --header-lines - --margin" + --sync" case "${prev}" in --tiebreak) @@ -116,7 +132,7 @@ _fzf_handle_dynamic_completion() { __fzf_generic_path_completion() { local cur base dir leftover matches trigger cmd fzf - [ "${FZF_TMUX:-1}" != 0 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf" + fzf="$(__fzfcmd_complete)" cmd="${COMP_WORDS[0]//[^A-Za-z0-9_=]/_}" COMPREPLY=() trigger=${FZF_COMPLETION_TRIGGER-'**'} @@ -132,8 +148,7 @@ __fzf_generic_path_completion() { leftover=${leftover/#\/} [ -z "$dir" ] && dir='.' [ "$dir" != "/" ] && dir="${dir/%\//}" - tput sc - matches=$(eval "$1 $(printf %q "$dir")" | $fzf $FZF_COMPLETION_OPTS $2 -q "$leftover" | while read -r item; do + matches=$(eval "$1 $(printf %q "$dir")" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_COMPLETION_OPTS" $fzf $2 -q "$leftover" | while read -r item; do printf "%q$3 " "$item" done) matches=${matches% } @@ -142,7 +157,7 @@ __fzf_generic_path_completion() { else COMPREPLY=( "$cur" ) fi - tput rc + printf '\e[5n' return 0 fi dir=$(dirname "$dir") @@ -160,7 +175,7 @@ _fzf_complete() { local cur selected trigger cmd fzf post post="$(caller 0 | awk '{print $2}')_post" type -t "$post" > /dev/null 2>&1 || post=cat - [ "${FZF_TMUX:-1}" != 0 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf" + fzf="$(__fzfcmd_complete)" cmd="${COMP_WORDS[0]//[^A-Za-z0-9_=]/_}" trigger=${FZF_COMPLETION_TRIGGER-'**'} @@ -168,10 +183,9 @@ _fzf_complete() { if [[ "$cur" == *"$trigger" ]]; then cur=${cur:0:${#cur}-${#trigger}} - tput sc - selected=$(cat | $fzf $FZF_COMPLETION_OPTS $1 -q "$cur" | $post | tr '\n' ' ') + selected=$(cat | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_COMPLETION_OPTS" $fzf $1 -q "$cur" | $post | tr '\n' ' ') selected=${selected% } # Strip trailing space not to repeat "-o nospace" - tput rc + printf '\e[5n' if [ -n "$selected" ]; then COMPREPLY=("$selected") @@ -200,10 +214,9 @@ _fzf_complete_kill() { [ -n "${COMP_WORDS[COMP_CWORD]}" ] && return 1 local selected fzf - [ "${FZF_TMUX:-1}" != 0 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf" - tput sc - selected=$(ps -ef | sed 1d | $fzf -m $FZF_COMPLETION_OPTS | awk '{print $2}' | tr '\n' ' ') - tput rc + fzf="$(__fzfcmd_complete)" + selected=$(ps -ef | sed 1d | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-50%} --min-height 15 --reverse $FZF_DEFAULT_OPTS --preview 'echo {}' --preview-window down:3:wrap $FZF_COMPLETION_OPTS" $fzf -m | awk '{print $2}' | tr '\n' ' ') + printf '\e[5n' if [ -n "$selected" ]; then COMPREPLY=( "$selected" ) diff --git a/shell/completion.zsh b/shell/completion.zsh index d3faef80..9b9dba3e 100644 --- a/shell/completion.zsh +++ b/shell/completion.zsh @@ -5,7 +5,7 @@ # / __/ / /_/ __/ # /_/ /___/_/-completion.zsh # -# - $FZF_TMUX (default: 1) +# - $FZF_TMUX (default: 0) # - $FZF_TMUX_HEIGHT (default: '40%') # - $FZF_COMPLETION_TRIGGER (default: '**') # - $FZF_COMPLETION_OPTS (default: empty) @@ -30,6 +30,11 @@ fi ########################################################### +__fzfcmd_complete() { + [ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ] && + echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf" +} + __fzf_generic_path_completion() { local base lbuf compgen fzf_opts suffix tail fzf dir leftover matches # (Q) flag removes a quoting level: "foo\ bar" => "foo bar" @@ -39,7 +44,7 @@ __fzf_generic_path_completion() { fzf_opts=$4 suffix=$5 tail=$6 - [ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf" + fzf="$(__fzfcmd_complete)" setopt localoptions nonomatch dir="$base" @@ -50,7 +55,7 @@ __fzf_generic_path_completion() { [ -z "$dir" ] && dir='.' [ "$dir" != "/" ] && dir="${dir/%\//}" dir=${~dir} - matches=$(eval "$compgen $(printf %q "$dir")" | ${=fzf} ${=FZF_COMPLETION_OPTS} ${=fzf_opts} -q "$leftover" | while read item; do + matches=$(eval "$compgen $(printf %q "$dir")" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_COMPLETION_OPTS" ${=fzf} ${=fzf_opts} -q "$leftover" | while read item; do echo -n "${(q)item}$suffix " done) matches=${matches% } @@ -90,10 +95,10 @@ _fzf_complete() { post="${funcstack[2]}_post" type $post > /dev/null 2>&1 || post=cat - [ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf" + fzf="$(__fzfcmd_complete)" _fzf_feed_fifo "$fifo" - matches=$(cat "$fifo" | ${=fzf} ${=FZF_COMPLETION_OPTS} ${=fzf_opts} -q "${(Q)prefix}" | $post | tr '\n' ' ') + matches=$(cat "$fifo" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_COMPLETION_OPTS" ${=fzf} ${=fzf_opts} -q "${(Q)prefix}" | $post | tr '\n' ' ') if [ -n "$matches" ]; then LBUFFER="$lbuf$matches" fi @@ -157,8 +162,8 @@ fzf-completion() { tail=${LBUFFER:$(( ${#LBUFFER} - ${#trigger} ))} # Kill completion (do not require trigger sequence) if [ $cmd = kill -a ${LBUFFER[-1]} = ' ' ]; then - [ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf" - matches=$(ps -ef | sed 1d | ${=fzf} ${=FZF_COMPLETION_OPTS} -m | awk '{print $2}' | tr '\n' ' ') + fzf="$(__fzfcmd_complete)" + matches=$(ps -ef | sed 1d | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-50%} --min-height 15 --reverse $FZF_DEFAULT_OPTS --preview 'echo {}' --preview-window down:3:wrap $FZF_COMPLETION_OPTS" ${=fzf} -m | awk '{print $2}' | tr '\n' ' ') if [ -n "$matches" ]; then LBUFFER="$LBUFFER$matches" fi diff --git a/shell/key-bindings.bash b/shell/key-bindings.bash index 33d8bc8d..06e9656e 100644 --- a/shell/key-bindings.bash +++ b/shell/key-bindings.bash @@ -5,7 +5,7 @@ __fzf_select__() { -o -type f -print \ -o -type d -print \ -o -type l -print 2> /dev/null | cut -b3-"}" - eval "$cmd | fzf -m $FZF_CTRL_T_OPTS" | while read -r item; do + eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS" fzf -m "$@" | while read -r item; do printf '%q ' "$item" done echo @@ -13,8 +13,13 @@ __fzf_select__() { if [[ $- =~ i ]]; then +__fzf_use_tmux__() { + [ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ] +} + __fzfcmd() { - [ "${FZF_TMUX:-1}" != 0 ] && echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf" + __fzf_use_tmux__ && + echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf" } __fzf_select_tmux__() { @@ -26,7 +31,7 @@ __fzf_select_tmux__() { height="-l $height" fi - tmux split-window $height "cd $(printf %q "$PWD"); FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS") PATH=$(printf %q "$PATH") FZF_CTRL_T_COMMAND=$(printf %q "$FZF_CTRL_T_COMMAND") FZF_CTRL_T_OPTS=$(printf %q "$FZF_CTRL_T_OPTS") bash -c 'source \"${BASH_SOURCE[0]}\"; RESULT=\"\$(__fzf_select__)\"; tmux setb -b fzf \"\$RESULT\" \\; pasteb -b fzf -t $TMUX_PANE \\; deleteb -b fzf || tmux send-keys -t $TMUX_PANE \"\$RESULT\"'" + tmux split-window $height "cd $(printf %q "$PWD"); FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS") PATH=$(printf %q "$PATH") FZF_CTRL_T_COMMAND=$(printf %q "$FZF_CTRL_T_COMMAND") FZF_CTRL_T_OPTS=$(printf %q "$FZF_CTRL_T_OPTS") bash -c 'source \"${BASH_SOURCE[0]}\"; RESULT=\"\$(__fzf_select__ --no-height)\"; tmux setb -b fzf \"\$RESULT\" \\; pasteb -b fzf -t $TMUX_PANE \\; deleteb -b fzf || tmux send-keys -t $TMUX_PANE \"\$RESULT\"'" } fzf-file-widget() { @@ -43,7 +48,7 @@ __fzf_cd__() { local cmd dir cmd="${FZF_ALT_C_COMMAND:-"command find -L . \\( -path '*/\\.*' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \ -o -type d -print 2> /dev/null | sed 1d | cut -b3-"}" - dir=$(eval "$cmd | $(__fzfcmd) +m $FZF_ALT_C_OPTS") && printf 'cd %q' "$dir" + dir=$(eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS" $(__fzfcmd) +m) && printf 'cd %q' "$dir" } __fzf_history__() ( @@ -51,7 +56,7 @@ __fzf_history__() ( shopt -u nocaseglob nocasematch line=$( HISTTIMEFORMAT= history | - eval "$(__fzfcmd) +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r $FZF_CTRL_R_OPTS" | + FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS +s --tac --no-reverse -n2..,.. --tiebreak=index --toggle-sort=ctrl-r $FZF_CTRL_R_OPTS +m" $(__fzfcmd) | command grep '^ *[0-9]') && if [[ $- =~ H ]]; then sed 's/^ *\([0-9]*\)\** .*/!\1/' <<< "$line" @@ -60,22 +65,15 @@ __fzf_history__() ( fi ) -__fzf_use_tmux__() { - [ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-1}" != 0 ] && [ ${LINES:-40} -gt 15 ] -} - -[ $BASH_VERSINFO -gt 3 ] && __use_bind_x=1 || __use_bind_x=0 -__fzf_use_tmux__ && __use_tmux=1 || __use_tmux=0 - if [[ ! -o vi ]]; then # Required to refresh the prompt after fzf bind '"\er": redraw-current-line' bind '"\e^": history-expand-line' # CTRL-T - Paste the selected file path into the command line - if [ $__use_bind_x -eq 1 ]; then + if [ $BASH_VERSINFO -gt 3 ]; then bind -x '"\C-t": "fzf-file-widget"' - elif [ $__use_tmux -eq 1 ]; then + elif __fzf_use_tmux__; then bind '"\C-t": " \C-u \C-a\C-k`__fzf_select_tmux__`\e\C-e\C-y\C-a\C-d\C-y\ey\C-h"' else bind '"\C-t": " \C-u \C-a\C-k`__fzf_select__`\e\C-e\C-y\C-a\C-y\ey\C-h\C-e\er \C-h"' @@ -102,9 +100,9 @@ else # CTRL-T - Paste the selected file path into the command line # - FIXME: Selected items are attached to the end regardless of cursor position - if [ $__use_bind_x -eq 1 ]; then + if [ $BASH_VERSINFO -gt 3 ]; then bind -x '"\C-t": "fzf-file-widget"' - elif [ $__use_tmux -eq 1 ]; then + elif __fzf_use_tmux__; then bind '"\C-t": "\C-x\C-a$a \C-x\C-addi`__fzf_select_tmux__`\C-x\C-e\C-x\C-a0P$xa"' else bind '"\C-t": "\C-x\C-a$a \C-x\C-addi`__fzf_select__`\C-x\C-e\C-x\C-a0Px$a \C-x\C-r\C-x\C-axa "' @@ -120,6 +118,4 @@ else bind -m vi-command '"\ec": "ddi`__fzf_cd__`\C-x\C-e\C-x\C-r\C-m"' fi -unset -v __use_tmux __use_bind_x - fi diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish index dd75fecf..3fb7da84 100644 --- a/shell/key-bindings.fish +++ b/shell/key-bindings.fish @@ -21,7 +21,11 @@ function fzf_key_bindings -o -type d -print \ -o -type l -print 2> /dev/null | sed 's#^\./##'" - eval "$FZF_CTRL_T_COMMAND | "(__fzfcmd)" -m $FZF_CTRL_T_OPTS" | while read -l r; set result $result $r; end + set -q FZF_TMUX_HEIGHT; or set FZF_TMUX_HEIGHT 40% + begin + set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT --reverse $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS" + eval "$FZF_CTRL_T_COMMAND | "(__fzfcmd)" -m" | while read -l r; set result $result $r; end + end if [ -z "$result" ] commandline -f repaint return @@ -39,8 +43,12 @@ function fzf_key_bindings end function fzf-history-widget -d "Show command history" - history | eval (__fzfcmd) +s +m --tiebreak=index $FZF_CTRL_R_OPTS -q '(commandline)' | read -l result - and commandline -- $result + set -q FZF_TMUX_HEIGHT; or set FZF_TMUX_HEIGHT 40% + begin + set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT $FZF_DEFAULT_OPTS +s --no-reverse --tiebreak=index $FZF_CTRL_R_OPTS +m" + history | eval (__fzfcmd) -q '(commandline)' | read -l result + and commandline -- $result + end commandline -f repaint end @@ -48,19 +56,20 @@ function fzf_key_bindings set -q FZF_ALT_C_COMMAND; or set -l FZF_ALT_C_COMMAND " command find -L . \\( -path '*/\\.*' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \ -o -type d -print 2> /dev/null | sed 1d | cut -b3-" - eval "$FZF_ALT_C_COMMAND | "(__fzfcmd)" +m $FZF_ALT_C_OPTS" | read -l result - [ "$result" ]; and cd $result + set -q FZF_TMUX_HEIGHT; or set FZF_TMUX_HEIGHT 40% + begin + set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT --reverse $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS" + eval "$FZF_ALT_C_COMMAND | "(__fzfcmd)" +m" | read -l result + [ "$result" ]; and cd $result + end commandline -f repaint end function __fzfcmd - set -q FZF_TMUX; or set FZF_TMUX 1 + 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 set -q FZF_TMUX_HEIGHT - echo "fzf-tmux -d$FZF_TMUX_HEIGHT" - else - echo "fzf-tmux -d40%" - end + echo "fzf-tmux -d$FZF_TMUX_HEIGHT" else echo "fzf" end diff --git a/shell/key-bindings.zsh b/shell/key-bindings.zsh index fed01532..c8705add 100644 --- a/shell/key-bindings.zsh +++ b/shell/key-bindings.zsh @@ -9,7 +9,7 @@ __fsel() { -o -type d -print \ -o -type l -print 2> /dev/null | cut -b3-"}" setopt localoptions pipefail 2> /dev/null - eval "$cmd | $(__fzfcmd) -m $FZF_CTRL_T_OPTS" | while read item; do + eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS" $(__fzfcmd) -m "$@" | while read item; do echo -n "${(q)item} " done local ret=$? @@ -17,8 +17,13 @@ __fsel() { return $ret } +__fzf_use_tmux__() { + [ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ] +} + __fzfcmd() { - [ ${FZF_TMUX:-1} -eq 1 ] && echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf" + __fzf_use_tmux__ && + echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf" } fzf-file-widget() { @@ -36,7 +41,7 @@ fzf-cd-widget() { local cmd="${FZF_ALT_C_COMMAND:-"command find -L . \\( -path '*/\\.*' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \ -o -type d -print 2> /dev/null | sed 1d | cut -b3-"}" setopt localoptions pipefail 2> /dev/null - cd "${$(eval "$cmd | $(__fzfcmd) +m $FZF_ALT_C_OPTS"):-.}" + cd "${$(eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS" $(__fzfcmd) +m):-.}" local ret=$? zle reset-prompt typeset -f zle-line-init >/dev/null && zle zle-line-init @@ -49,7 +54,8 @@ bindkey '\ec' fzf-cd-widget fzf-history-widget() { local selected num |