[fzf-tmux] Execute trap with bash instead of the default shell

Close #1007
This commit is contained in:
Junegunn Choi 2017-08-26 02:51:19 +09:00
parent e825b07e85
commit 329de8f416
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

View File

@ -146,6 +146,7 @@ cleanup() {
fi fi
if [ $# -gt 0 ]; then if [ $# -gt 0 ]; then
trap - EXIT
exit 130 exit 130
fi fi
} }
@ -170,21 +171,22 @@ for arg in "${args[@]}"; do
done done
pppid=$$ pppid=$$
trap_set="trap 'kill -SIGUSR1 -$pppid' EXIT SIGINT SIGTERM" echo -n "trap 'kill -SIGUSR1 -$pppid' EXIT SIGINT SIGTERM;" > $argsf
trap_unset="trap - EXIT SIGINT SIGTERM" close="; trap - EXIT SIGINT SIGTERM $close"
if [[ -n "$term" ]] || [[ -t 0 ]]; then if [[ -n "$term" ]] || [[ -t 0 ]]; then
cat <<< "\"$fzf\" $opts > $fifo2; echo \$? > $fifo3 $close" > $argsf cat <<< "\"$fzf\" $opts > $fifo2; echo \$? > $fifo3 $close" >> $argsf
cat $argsf
TMUX=$(echo $TMUX | cut -d , -f 1,2) tmux set-window-option synchronize-panes off \;\ TMUX=$(echo $TMUX | cut -d , -f 1,2) tmux set-window-option synchronize-panes off \;\
set-window-option remain-on-exit off \;\ set-window-option remain-on-exit off \;\
split-window $opt "$trap_set;cd $(printf %q "$PWD");$envs bash $argsf;$trap_unset" $swap \ split-window $opt "cd $(printf %q "$PWD");$envs bash $argsf" $swap \
> /dev/null 2>&1 > /dev/null 2>&1
else else
mkfifo $fifo1 mkfifo $fifo1
cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; echo \$? > $fifo3 $close" > $argsf cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; echo \$? > $fifo3 $close" >> $argsf
TMUX=$(echo $TMUX | cut -d , -f 1,2) tmux set-window-option synchronize-panes off \;\ TMUX=$(echo $TMUX | cut -d , -f 1,2) tmux set-window-option synchronize-panes off \;\
set-window-option remain-on-exit off \;\ set-window-option remain-on-exit off \;\
split-window $opt "$trap_set;$envs bash $argsf;$trap_unset" $swap \ split-window $opt "$envs bash $argsf" $swap \
> /dev/null 2>&1 > /dev/null 2>&1
cat <&0 > $fifo1 & cat <&0 > $fifo1 &
fi fi