[fzf-tmux] Close with exit code 130 when tmux pane is killed

Fix #796
This commit is contained in:
Kouki Higashikawa 2017-04-03 11:49:54 +09:00 committed by Junegunn Choi
parent 9078197446
commit 7c8f7d3f20

View File

@ -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