summaryrefslogtreecommitdiffstats
path: root/shell
diff options
context:
space:
mode:
authorDaniel Hahler <git@thequod.de>2016-06-16 01:03:48 +0200
committerDaniel Hahler <git@thequod.de>2016-06-16 20:20:29 +0200
commit38a2076b893213f6d29b91299c5edbe5237a4320 (patch)
tree60eccadc662e0dca899220d44b0ed0f431ebfede /shell
parent5759d50d4a4ff05f826d1fe546b76315d3860a82 (diff)
zsh: pass through exit code from widgets
This allows to have a custom widget like the following, which would additionally accept the line, but only in case of entries being selected: fzf-file-widget-with-accept() { zle fzf-file-widget if [[ "$?" == 0 ]] && (( $#BUFFER )); then zle accept-line fi } zle -N fzf-file-widget-with-accept bindkey '\e^T' fzf-file-widget-with-accept With this `<C-a>t` will launch fzf, and simulate the pressing of "Enter" afterwards.
Diffstat (limited to 'shell')
-rw-r--r--shell/key-bindings.zsh12
1 files changed, 11 insertions, 1 deletions
diff --git a/shell/key-bindings.zsh b/shell/key-bindings.zsh
index 35e5f194..ea65c0c0 100644
--- a/shell/key-bindings.zsh
+++ b/shell/key-bindings.zsh
@@ -8,10 +8,13 @@ __fsel() {
-o -type f -print \
-o -type d -print \
-o -type l -print 2> /dev/null | sed 1d | cut -b3-"}"
+ setopt localoptions pipefail
eval "$cmd | $(__fzfcmd) -m $FZF_CTRL_T_OPTS" | while read item; do
echo -n "${(q)item} "
done
+ local ret=$?
echo
+ return $ret
}
__fzfcmd() {
@@ -20,7 +23,9 @@ __fzfcmd() {
fzf-file-widget() {
LBUFFER="${LBUFFER}$(__fsel)"
+ local ret=$?
zle redisplay
+ return $ret
}
zle -N fzf-file-widget
bindkey '^T' fzf-file-widget
@@ -29,8 +34,11 @@ bindkey '^T' fzf-file-widget
fzf-cd-widget() {
local cmd="${FZF_ALT_C_COMMAND:-"command find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
-o -type d -print 2> /dev/null | sed 1d | cut -b3-"}"
+ setopt localoptions pipefail
cd "${$(eval "$cmd | $(__fzfcmd) +m $FZF_ALT_C_OPTS"):-.}"
+ local ret=$?
zle reset-prompt
+ return $ret
}
zle -N fzf-cd-widget
bindkey '\ec' fzf-cd-widget
@@ -38,8 +46,9 @@ bindkey '\ec' fzf-cd-widget
# CTRL-R - Paste the selected command from history into the command line
fzf-history-widget() {
local selected num
- setopt localoptions noglobsubst
+ setopt localoptions noglobsubst pipefail
selected=( $(fc -l 1 | eval "$(__fzfcmd) +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r $FZF_CTRL_R_OPTS -q ${(q)LBUFFER}") )
+ local ret=$?
if [ -n "$selected" ]; then
num=$selected[1]
if [ -n "$num" ]; then
@@ -47,6 +56,7 @@ fzf-history-widget() {
fi
fi
zle redisplay
+ return $ret
}
zle -N fzf-history-widget
bindkey '^R' fzf-history-widget