[bash] Enable fuzzy path completion for all commands (#3958)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
All commands with no custom completion defined. Close #3957
authored by Junegunn Choi · committed by GitHub · parent 303d041 · Browse files · 2 files·+50 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+50 added−12 removed
- other:+50 added−12 removed
Provenance
- Commit
a2d0e8f- Tree
a617680- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
303d041
2 files changed+50 added−12 removed
modified:shell/completion.bash+39 added-12 removed
287 unmodified lines288 cmd="${cmd:1}"289 fi290 COMPREPLY=()291 trigger=${FZF_COMPLETION_TRIGGER-'**'}292- cur="${COMP_WORDS[COMP_CWORD]}"292+ [[ $COMP_CWORD -ge 0 ]] && cur="${COMP_WORDS[COMP_CWORD]}"293 if [[ "$cur" == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then294 base=${cur:0:${#cur}-${#trigger}}295 eval "base=$base" 2> /dev/null || return296 183 unmodified lines480 # itself. As a quick improvement we take fzf's completion. Adding the few extra481 # fzf-tmux specific options (like `-w WIDTH`) are left as a future patch.482 complete -o default -F _fzf_opts_completion fzf-tmux483 484+# Default path completion485+__fzf_default_completion() {486+ __fzf_generic_path_completion _fzf_compgen_path "-m" "" "$@"487+488+ # Dynamic completion loader has updated the completion for the command489+ if [[ $? -eq 124 ]]; then490+ # We trigger _fzf_setup_completion so that fuzzy completion for the command491+ # still works. However, loader can update the completion for multiple492+ # commands at once, and fuzzy completion will no longer work for those493+ # other commands. e.g. pytest -> py.test, pytest-2, pytest-3, etc494+ _fzf_setup_completion path "$1"495+ return 124496+ fi497+}498+499+if complete | command grep -q __fzf_default_completion; then500+ : # Default completion already set up. Do nothing.501+elif ! complete | command grep -- '-D$' | command grep -qv _comp_complete_load &&502+ complete -D -F __fzf_default_completion -o default -o bashdefault 2> /dev/null; then503+ a_cmds=""504+else505+ # We can't set up default completion,506+ # 1. if it's already set up by another script507+ # 2. or if the current version of bash doesn't support -D option508+ #509+ # NOTE: $FZF_COMPLETION_PATH_COMMANDS and $FZF_COMPLETION_VAR_COMMANDS are510+ # undocumented and subject to change in the future.511+ a_cmds="${FZF_COMPLETION_PATH_COMMANDS-"512+ awk bat cat code diff diff3513+ emacs emacsclient ex file ftp g++ gcc gvim head hg hx java514+ javac ld less more mvim nvim patch perl python ruby515+ sed sftp sort source tail tee uniq vi view vim wc xdg-open516+ basename bunzip2 bzip2 chmod chown curl cp dirname du517+ find git grep gunzip gzip hg jar518+ ln ls mv open rm rsync scp519+ svn tar unzip zip"}"520+fi521+522 d_cmds="${FZF_COMPLETION_DIR_COMMANDS-cd pushd rmdir}"523 486-# NOTE: $FZF_COMPLETION_PATH_COMMANDS and $FZF_COMPLETION_VAR_COMMANDS are487-# undocumented and subject to change in the future.488-a_cmds="${FZF_COMPLETION_PATH_COMMANDS-"489- awk bat cat code diff diff3490- emacs emacsclient ex file ftp g++ gcc gvim head hg hx java491- javac ld less more mvim nvim patch perl python ruby492- sed sftp sort source tail tee uniq vi view vim wc xdg-open493- basename bunzip2 bzip2 chmod chown curl cp dirname du494- find git grep gunzip gzip hg jar495- ln ls mv open rm rsync scp496- svn tar unzip zip"}"524 v_cmds="${FZF_COMPLETION_VAR_COMMANDS-export unset printenv}"525 526 # Preserve existing completion527 __fzf_orig_completion < <(complete -p $d_cmds $a_cmds $v_cmds unalias kill ssh 2> /dev/null)72 unmodified linesmodified:CHANGELOG.md+11 added
1 CHANGELOG2 =========3 4+0.54.45+------6+- [bash] Fuzzy path completion is enabled for all commands7+ - 1. If the default completion is not already set8+ - 2. And if the current bash supports `complete -D` option9+ - However, fuzzy completion for some commands can be "dynamically" disabled by the dynamic completion loader10+ - See the comment in `__fzf_default_completion` function for more information11+- Fixed `--tmux bottom` when the status line is not at the bottom12+- Fixed extra scroll offset in multi-line mode (`--read0` or `--wrap`)13+- Added fallback `ps` command for `kill` completion on Cygwin14+15 0.54.316 ------17 - Fixed incompatibility of adaptive height specification and 'start:reload'18 ```sh2236 unmodified lines