Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #796 #895

Merged
merged 3 commits into from
Apr 3, 2017
Merged

Fixed #796 #895

merged 3 commits into from
Apr 3, 2017

Conversation

hikouki
Copy link
Contributor

@hikouki hikouki commented Apr 2, 2017

Hi 🍣
I tried fix issue #796.

@junegunn
Copy link
Owner

junegunn commented Apr 2, 2017

Thanks, I like the approach. The signal handler is triggered even when fzf exits normally, so I think it's more appropriate that we clear it when it's not needed. What do you think? This version also sets the exit code properly (130) when the pane is killed.

diff --git a/bin/fzf-tmux b/bin/fzf-tmux
index d7185a2..c1b3446 100755
--- a/bin/fzf-tmux
+++ b/bin/fzf-tmux
@@ -144,8 +144,13 @@ 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 +169,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

@junegunn junegunn added the bug label Apr 2, 2017
@hikouki
Copy link
Contributor Author

hikouki commented Apr 3, 2017

Thank you for review :)
I think so too. Good idea 🎉

bin/fzf-tmux Outdated
@@ -144,8 +144,12 @@ cleanup() {
kill-window -t $tmp_window \; \
resize-pane -Z
fi

if [ $# -gt 0 ]; then
exit 130
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor nit. Can you fix the indentation here to 2 spaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh. sorry.. 🙇
I'll do it right away.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, thanks.

@junegunn junegunn merged commit 7c8f7d3 into junegunn:master Apr 3, 2017
@junegunn
Copy link
Owner

junegunn commented Apr 3, 2017

Merged, thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants