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"
|
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 - repeat history
|
||||||
fh() {
|
fh() {
|
||||||
eval $(history | fzf +s | sed 's/ *[0-9]* *//')
|
eval $(history | fzf +s | sed 's/ *[0-9]* *//')
|
||||||
@ -209,12 +201,23 @@ fh() {
|
|||||||
fkill() {
|
fkill() {
|
||||||
ps -ef | sed 1d | fzf -m | awk '{print $2}' | xargs kill -${1:-9}
|
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
|
# CTRL-T - Paste the selected file path into the command line
|
||||||
bind '"\er": redraw-current-line'
|
fsel() {
|
||||||
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"'
|
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
|
# 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"'
|
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=${base/#"$dir"}
|
||||||
leftover=${leftover/#\/}
|
leftover=${leftover/#\/}
|
||||||
[ "$dir" = './' ] && dir=''
|
[ "$dir" = './' ] && dir=''
|
||||||
|
tput sc
|
||||||
matches=$(find "$dir"* $1 2> /dev/null | fzf $FZF_COMPLETION_OPTS $2 -q "$leftover" | while read item; do
|
matches=$(find "$dir"* $1 2> /dev/null | fzf $FZF_COMPLETION_OPTS $2 -q "$leftover" | while read item; do
|
||||||
if [[ ${item} =~ \ ]]; then
|
printf '%q ' "$item"
|
||||||
echo -n "\"$item\" "
|
|
||||||
else
|
|
||||||
echo -n "$item "
|
|
||||||
fi
|
|
||||||
done)
|
done)
|
||||||
matches=${matches% }
|
matches=${matches% }
|
||||||
if [ -n "$matches" ]; then
|
if [ -n "$matches" ]; then
|
||||||
@ -59,6 +56,7 @@ _fzf_generic_completion() {
|
|||||||
else
|
else
|
||||||
COMPREPLY=( "$cur" )
|
COMPREPLY=( "$cur" )
|
||||||
fi
|
fi
|
||||||
|
tput rc
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
dir=$(dirname "$dir")
|
dir=$(dirname "$dir")
|
||||||
@ -110,7 +108,3 @@ for cmd in "
|
|||||||
complete -F _fzf_all_completion -o default -o bashdefault $cmd
|
complete -F _fzf_all_completion -o default -o bashdefault $cmd
|
||||||
done
|
done
|
||||||
|
|
||||||
bind '"\e\e": complete'
|
|
||||||
bind '"\er": redraw-current-line'
|
|
||||||
bind '"\C-i": "\e\e\er"'
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user