Improve bash completion: `[DIRECTORY/][FUZZY_PATTERN]**<TAB>`

pull/17/head
Junegunn Choi 11 years ago
parent c61738ae43
commit f660ad35b2

@ -73,12 +73,13 @@ Usage
``` ```
usage: fzf [options] usage: fzf [options]
-m, --multi Enable multi-select -m, --multi Enable multi-select
-x, --extended Extended-search mode -x, --extended Extended-search mode
-s, --sort=MAX Maximum number of matched items to sort. Default: 1000 -q, --query=STR Initial query
+s, --no-sort Do not sort the result. Keep the sequence unchanged. -s, --sort=MAX Maximum number of matched items to sort. Default: 1000
+i Case-sensitive match +s, --no-sort Do not sort the result. Keep the sequence unchanged.
+c, --no-color Disable colors +i Case-sensitive match
+c, --no-color Disable colors
``` ```
fzf will launch curses-based finder, read the list from STDIN, and write the fzf will launch curses-based finder, read the list from STDIN, and write the
@ -266,8 +267,10 @@ over time*
### bash ### bash
fuzzy-finder-completion can be triggered if you type in a directory name Fuzzy completion can be triggered if the word before the cursor ends
followed by the trigger sequence which is by default `**`. with the trigger sequence which is by default `**`.
- `COMMAND [DIRECTORY/][FUZZY_PATTERN]**<TAB>`
#### Examples #### Examples
@ -277,7 +280,10 @@ followed by the trigger sequence which is by default `**`.
vim **<TAB> vim **<TAB>
# Files under parent directory # Files under parent directory
vim ..**<TAB> vim ../**<TAB>
# Files under parent directory that match `fzf`
vim ../fzf**<TAB>
# Files under your home directory # Files under your home directory
vim ~/**<TAB> vim ~/**<TAB>
@ -286,8 +292,8 @@ vim ~/**<TAB>
# Directories under current directory (single-selection) # Directories under current directory (single-selection)
cd **<TAB> cd **<TAB>
# Directories under parent directory # Directories under ~/github that match `fzf`
cd ../**<TAB> cd ~/github/fzf**<TAB>
``` ```
#### Settings #### Settings

@ -31,31 +31,37 @@ _fzf_opts_completion() {
} }
_fzf_generic_completion() { _fzf_generic_completion() {
local cur prev opts base matches local cur prev opts base dir leftover matches
COMPREPLY=() COMPREPLY=()
FZF_COMPLETION_TRIGGER=${FZF_COMPLETION_TRIGGER:-**} FZF_COMPLETION_TRIGGER=${FZF_COMPLETION_TRIGGER:-**}
cur="${COMP_WORDS[COMP_CWORD]}" cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}" prev="${COMP_WORDS[COMP_CWORD-1]}"
if [[ ${cur} == *"$FZF_COMPLETION_TRIGGER" ]]; then if [[ ${cur} == *"$FZF_COMPLETION_TRIGGER" ]]; then
base=${cur:0:${#cur}-${#FZF_COMPLETION_TRIGGER}} base=${cur:0:${#cur}-${#FZF_COMPLETION_TRIGGER}}
base=${base%/}
eval base=$base eval base=$base
find_opts="-name .git -prune -o -name .svn -prune -o" dir="$base"
if [ -z "$base" -o -d "$base" ]; then while [ 1 ]; do
matches=$(find ${base:-*} $1 2> /dev/null | fzf $FZF_COMPLETION_OPTS $2 | while read item; do if [ -z "$dir" -o -d "$dir" ]; then
if [[ ${item} =~ \ ]]; then leftover=${base/#"$dir"}
echo -n "\"$item\" " leftover=${leftover/#\/}
else [ "$dir" = '.' ] && dir=''
echo -n "$item " matches=$(find "$dir"* $1 2> /dev/null | fzf $FZF_COMPLETION_OPTS $2 -q "$leftover" | while read item; do
if [[ ${item} =~ \ ]]; then
echo -n "\"$item\" "
else
echo -n "$item "
fi
done)
matches=${matches% }
if [ -n "$matches" ]; then
COMPREPLY=( "$matches" )
return 0
fi fi
done) return 1
matches=${matches% }
if [ -n "$matches" ]; then
COMPREPLY=( "$matches" )
return 0
fi fi
fi dir=$(dirname "$dir")
done
fi fi
} }

Loading…
Cancel
Save