diff --git a/README.md b/README.md index 044ea168..a9b8a91d 100644 --- a/README.md +++ b/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 +----------------- -# CTRL-T - Paste the selected file path into the command line +```sh +# Required to refresh the prompt after fzf 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"' + +# CTRL-T - Paste the selected file path into the command line +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"' diff --git a/fzf-completion.bash b/fzf-completion.bash index c4aca319..6697b372 100644 --- a/fzf-completion.bash +++ b/fzf-completion.bash @@ -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"' -