From 7c8f7d3f201b89c2e1fb1aca4b7289964469cba8 Mon Sep 17 00:00:00 2001 From: Kouki Higashikawa Date: Mon, 3 Apr 2017 11:49:54 +0900 Subject: [PATCH] [fzf-tmux] Close with exit code 130 when tmux pane is killed Fix #796 --- bin/fzf-tmux | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/bin/fzf-tmux b/bin/fzf-tmux index d7185a2..b01d995 100755 --- a/bin/fzf-tmux +++ b/bin/fzf-tmux @@ -144,8 +144,12 @@ cleanup() { kill-window -t $tmp_window \; \ resize-pane -Z fi + + if [ $# -gt 0 ]; then + exit 130 + fi } -trap cleanup EXIT SIGINT SIGTERM +trap 'cleanup 1' SIGUSR1 envs="env TERM=$TERM " [[ -n "$FZF_DEFAULT_OPTS" ]] && envs="$envs FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS")" @@ -164,18 +168,22 @@ for arg in "${args[@]}"; do opts="$opts \"$arg\"" done +pppid=$$ +trap_set="trap 'kill -SIGUSR1 $pppid' EXIT SIGINT SIGTERM" +trap_unset="trap - EXIT SIGINT SIGTERM" + if [[ -n "$term" ]] || [[ -t 0 ]]; then cat <<< "\"$fzf\" $opts > $fifo2; echo \$? > $fifo3 $close" > $argsf TMUX=$(echo $TMUX | cut -d , -f 1,2) tmux set-window-option synchronize-panes off \;\ set-window-option remain-on-exit off \;\ - split-window $opt "cd $(printf %q "$PWD");$envs bash $argsf" $swap \ + split-window $opt "$trap_set;cd $(printf %q "$PWD");$envs bash $argsf;$trap_unset" $swap \ > /dev/null 2>&1 else mkfifo $fifo1 cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; echo \$? > $fifo3 $close" > $argsf TMUX=$(echo $TMUX | cut -d , -f 1,2) tmux set-window-option synchronize-panes off \;\ set-window-option remain-on-exit off \;\ - split-window $opt "$envs bash $argsf" $swap \ + split-window $opt "$trap_set;$envs bash $argsf;$trap_unset" $swap \ > /dev/null 2>&1 cat <&0 > $fifo1 & fi