summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2024-08-11 14:22:21 +0900
committerGitHub <noreply@github.com>2024-08-11 14:22:21 +0900
commita2d0e8f233fd7cda11390dd8b5675af04693631b (patch)
treea61768049809a6cfb7afbf24944a34e1ec206294
parent303d04106a4bb8914080a2ac1162f2d2acf2d97e (diff)
downloadfzf-a2d0e8f233fd7cda11390dd8b5675af04693631b.tar.gz
[bash] Enable fuzzy path completion for all commands (#3958)
All commands with no custom completion defined. Close #3957
-rw-r--r--CHANGELOG.md11
-rw-r--r--shell/completion.bash51
2 files changed, 50 insertions, 12 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 73cb0331..c6fdb0cb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,17 @@
CHANGELOG
=========
+0.54.4
+------
+- [bash] Fuzzy path completion is enabled for all commands
+ - 1. If the default completion is not already set
+ - 2. And if the current bash supports `complete -D` option
+ - However, fuzzy completion for some commands can be "dynamically" disabled by the dynamic completion loader
+ - See the comment in `__fzf_default_completion` function for more information
+- Fixed `--tmux bottom` when the status line is not at the bottom
+- Fixed extra scroll offset in multi-line mode (`--read0` or `--wrap`)
+- Added fallback `ps` command for `kill` completion on Cygwin
+
0.54.3
------
- Fixed incompatibility of adaptive height specification and 'start:reload'
diff --git a/shell/completion.bash b/shell/completion.bash
index 3eaf40da..38e7202f 100644
--- a/shell/completion.bash
+++ b/shell/completion.bash
@@ -289,7 +289,7 @@ __fzf_generic_path_completion() {
fi
COMPREPLY=()
trigger=${FZF_COMPLETION_TRIGGER-'**'}
- cur="${COMP_WORDS[COMP_CWORD]}"
+ [[ $COMP_CWORD -ge 0 ]] && cur="${COMP_WORDS[COMP_CWORD]}"
if [[ "$cur" == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then
base=${cur:0:${#cur}-${#trigger}}
eval "base=$base" 2> /dev/null || return
@@ -481,19 +481,46 @@ complete -o default -F _fzf_opts_completion fzf
# fzf-tmux specific options (like `-w WIDTH`) are left as a future patch.
complete -o default -F _fzf_opts_completion fzf-tmux
+# Default path completion
+__fzf_default_completion() {
+ __fzf_generic_path_completion _fzf_compgen_path "-m" "" "$@"
+
+ # Dynamic completion loader has updated the completion for the command
+ if [[ $? -eq 124 ]]; then
+ # We trigger _fzf_setup_completion so that fuzzy completion for the command
+ # still works. However, loader can update the completion for multiple
+ # commands at once, and fuzzy completion will no longer work for those
+ # other commands. e.g. pytest -> py.test, pytest-2, pytest-3, etc
+ _fzf_setup_completion path "$1"
+ return 124
+ fi
+}
+
+if complete | command grep -q __fzf_default_completion; then
+ : # Default completion already set up. Do nothing.
+elif ! complete | command grep -- '-D$' | command grep -qv _comp_complete_load &&
+ complete -D -F __fzf_default_completion -o default -o bashdefault 2> /dev/null; then
+ a_cmds=""
+else
+ # We can't set up default completion,
+ # 1. if it's already set up by another script
+ # 2. or if the current version of bash doesn't support -D option
+ #
+ # NOTE: $FZF_COMPLETION_PATH_COMMANDS and $FZF_COMPLETION_VAR_COMMANDS are
+ # undocumented and subject to change in the future.
+ a_cmds="${FZF_COMPLETION_PATH_COMMANDS-"
+ awk bat cat code diff diff3
+ emacs emacsclient ex file ftp g++ gcc gvim head hg hx java
+ javac ld less more mvim nvim patch perl python ruby
+ sed sftp sort source tail tee uniq vi view vim wc xdg-open
+ basename bunzip2 bzip2 chmod chown curl cp dirname du
+ find git grep gunzip gzip hg jar
+ ln ls mv open rm rsync scp
+ svn tar unzip zip"}"
+fi
+
d_cmds="${FZF_COMPLETION_DIR_COMMANDS-cd pushd rmdir}"
-# NOTE: $FZF_COMPLETION_PATH_COMMANDS and $FZF_COMPLETION_VAR_COMMANDS are
-# undocumented and subject to change in the future.
-a_cmds="${FZF_COMPLETION_PATH_COMMANDS-"
- awk bat cat code diff diff3
- emacs emacsclient ex file ftp g++ gcc gvim head hg hx java
- javac ld less more mvim nvim patch perl python ruby
- sed sftp sort source tail tee uniq vi view vim wc xdg-open
- basename bunzip2 bzip2 chmod chown curl cp dirname du
- find git grep gunzip gzip hg jar
- ln ls mv open rm rsync scp
- svn tar unzip zip"}"
v_cmds="${FZF_COMPLETION_VAR_COMMANDS-export unset printenv}"
# Preserve existing completion