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

Executes fzf from fzf-tmux with a process name #1056

Merged
merged 1 commit into from
Sep 28, 2017

Conversation

richiware
Copy link
Contributor

This is a little improvement useful for my use case, but feel free declining it.
I'm a tmux user and I uses a key binding which depending on the current execution process does several things.

is_fzf='echo "#{pane_current_command}" | grep -iqE "(^|\/)fzf$"'

bind -n C-h run-shell "($is_vim && tmux send-keys C-h) || \
                 ($is_fzf && tmux send-keys C-h) || \
                 ($is_zsh_prompt && tmux send-keys C-h) || \
                 tmux select-pane -L"

Currently if fzf is the current execution process, the process name is bash. With these changes the process name is fzf and I'm able to capture it in tmux.

@junegunn
Copy link
Owner

Thanks, it makes sense but it seems like this will require an extra level of escaping of arguments. e.g. ls | fzf-tmux -q "foo'bar"

Is there a clear, simple solution to the issue? I'd like to avoid making it even more complicated than it currently is now.

@richiware richiware force-pushed the feature/process_name_for_tmux branch from 3711fed to 518dc67 Compare September 22, 2017 07:32
@richiware
Copy link
Contributor Author

I've made changes and now it supports an extra level of escaping of arguments. I've overwritten the previous commit with --amend.

@@ -185,7 +185,7 @@ else
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 "$envs bash -c 'exec -a fzf bash $argsf'" $swap \
Copy link
Owner

Choose a reason for hiding this comment

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

Please update line 181 as well, which is used when fzf is started without stdin pipe.

Copy link
Owner

Choose a reason for hiding this comment

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

How about using sh -c instead? Although /bin/sh is no different from /bin/bash on many systems, sometimes it's linked to a lighter posix-compliant shell such as dash.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the PR with your suggestions.

Copy link
Owner

Choose a reason for hiding this comment

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

Unfortunately, there are failing test cases. Haven't looked into it, it could be an issue of test cases. I'll look into it when I get some time.

Copy link
Owner

Choose a reason for hiding this comment

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

@richiware richiware force-pushed the feature/process_name_for_tmux branch from 518dc67 to 38b8faa Compare September 25, 2017 05:58
@junegunn
Copy link
Owner

A couple things I found out:

  1. exec in dash does not support -a argument, and that's why the tests are failing on Travis CI. So we should use bash instead of sh as in your original suggestion.
  2. The patch does not work as expected when fzf-tmux is started without stdin pipe. tmux list-panes -F "#{window_index} #{pane_index} #{pane_current_command}" -a only shows bash. It looks like because of cd $(printf %q "$PWD"), tmux starts another layer of bash. Moving cd fixes the issue.

So it becomes:

diff --git a/bin/fzf-tmux b/bin/fzf-tmux
index d7ce7a6..79407e6 100755
--- a/bin/fzf-tmux
+++ b/bin/fzf-tmux
@@ -178,14 +178,14 @@ 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 "$envs bash -c 'cd $(printf %q "$PWD"); exec -a fzf bash $argsf'" $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 "$envs bash -c 'exec -a fzf bash $argsf'" $swap \
     > /dev/null 2>&1
   cat <&0 > $fifo1 &
 fi

@richiware richiware force-pushed the feature/process_name_for_tmux branch from 38b8faa to 889e1b6 Compare September 28, 2017 06:13
@richiware
Copy link
Contributor Author

Thanks a lot. I applied your changes and travis is working. Thanks for your time.

@junegunn
Copy link
Owner

Thanks, let's merge this and see if anyone complains :)

@junegunn junegunn merged commit 7f5f6ef into junegunn:master Sep 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants