mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-12-23 03:19:01 +00:00
Update examples and bash completion
- Use tput sc/rc instead of redraw-current-line - Escape selected items with printf
This commit is contained in:
parent
344b57fe33
commit
07aee79bd8
25
README.md
25
README.md
@ -192,14 +192,6 @@ fda() {
|
||||
DIR=$(find ${1:-*} -type d 2> /dev/null | fzf) && cd "$DIR"
|
||||
}
|
||||
|
||||
# fsel - Select multiple files in the given path
|
||||
fsel() {
|
||||
find ${1:-*} | fzf -m | while read item; do
|
||||
echo -n "\"$item\" "
|
||||
done
|
||||
echo
|
||||
}
|
||||
|
||||
# fh - repeat history
|
||||
fh() {
|
||||
eval $(history | fzf +s | sed 's/ *[0-9]* *//')
|
||||
@ -209,12 +201,23 @@ fh() {
|
||||
fkill() {
|
||||
ps -ef | sed 1d | fzf -m | awk '{print $2}' | xargs kill -${1:-9}
|
||||
}
|
||||
```
|
||||
|
||||
# (Assuming you don't use the default CTRL-T and CTRL-R)
|
||||
bash key bindings
|
||||
-----------------
|
||||
|
||||
```sh
|
||||
# Required to refresh the prompt after fzf
|
||||
bind '"\er": redraw-current-line'
|
||||
|
||||
# CTRL-T - Paste the selected file path into the command line
|
||||
bind '"\er": redraw-current-line'
|
||||
bind '"\C-t": " \C-u \C-a\C-k$(fzf)\e\C-e\C-y\C-a\C-y\ey\C-h\C-e\er"'
|
||||
fsel() {
|
||||
find ${1:-*} | fzf -m | while read item; do
|
||||
printf '%q ' $item
|
||||
done
|
||||
echo
|
||||
}
|
||||
bind '"\C-t": " \C-u \C-a\C-k$(fsel)\e\C-e\C-y\C-a\C-y\ey\C-h\C-e\er"'
|
||||
|
||||
# CTRL-R - Paste the selected command from history into the command line
|
||||
bind '"\C-r": " \C-e\C-u$(history | fzf +s | sed \"s/ *[0-9]* *//\")\e\C-e\er"'
|
||||
|
@ -46,12 +46,9 @@ _fzf_generic_completion() {
|
||||
leftover=${base/#"$dir"}
|
||||
leftover=${leftover/#\/}
|
||||
[ "$dir" = './' ] && dir=''
|
||||
tput sc
|
||||
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
|
||||
printf '%q ' "$item"
|
||||
done)
|
||||
matches=${matches% }
|
||||
if [ -n "$matches" ]; then
|
||||
@ -59,6 +56,7 @@ _fzf_generic_completion() {
|
||||
else
|
||||
COMPREPLY=( "$cur" )
|
||||
fi
|
||||
tput rc
|
||||
return 0
|
||||
fi
|
||||
dir=$(dirname "$dir")
|
||||
@ -110,7 +108,3 @@ for cmd in "
|
||||
complete -F _fzf_all_completion -o default -o bashdefault $cmd
|
||||
done
|
||||
|
||||
bind '"\e\e": complete'
|
||||
bind '"\er": redraw-current-line'
|
||||
bind '"\C-i": "\e\e\er"'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user