new zsh widgets

+ new fzf-cd-widget for running cd

* fzf-file-widget now properly escapes the special characters and supports
  multi-selection

* fzf-history-widget replaces the current line instead of appending to it
This commit is contained in:
Wojciech Siewierski 2013-11-10 18:13:04 +01:00
parent 1e9e597837
commit a6f7caf20d
1 changed files with 21 additions and 6 deletions

View File

@ -177,20 +177,35 @@ zsh widgets
-----------
```sh
# CTRL-T - Paste the selected file path into the command line
# CTRL-T - Paste the selected file(s) path into the command line
fzf-file-widget() {
LBUFFER+=$(
find * -path '*/\.*' -prune \
-o -type f -print \
-o -type l -print 2> /dev/null | fzf)
local FILES
local IFS="
"
FILES=($(
find * -path '*/\.*' -prune \
-o -type f -print \
-o -type l -print 2> /dev/null | fzf -m))
unset IFS
FILES=$FILES:q
LBUFFER="${LBUFFER%% #} $FILES"
zle redisplay
}
zle -N fzf-file-widget
bindkey '^T' fzf-file-widget
# ALT-C - cd into the selected directory
fzf-cd-widget() {
cd ${$(find * -path '*/\.*' -prune \
-o -type d -print 2> /dev/null | fzf):-.}
zle reset-prompt
}
zle -N fzf-cd-widget
bindkey '\ec' fzf-cd-widget
# CTRL-R - Paste the selected command from history into the command line
fzf-history-widget() {
LBUFFER+=$(history | fzf +s | sed "s/ *[0-9]* *//")
LBUFFER=$(history | fzf +s | sed "s/ *[0-9]* *//")
zle redisplay
}
zle -N fzf-history-widget