fzf icon indicating copy to clipboard operation
fzf copied to clipboard

Not able to run fzf with tmux run-shell

Open rbhanot4739 opened this issue 1 year ago • 6 comments

Checklist

  • [X] I have read through the manual page (man fzf)
  • [X] I have searched through the existing issues
  • [X] For bug reports, I have checked if the bug is reproducible in the latest version of fzf

Output of fzf --version

0.55.0 (brew)

OS

  • [ ] Linux
  • [X] macOS
  • [ ] Windows
  • [ ] Etc.

Shell

  • [ ] bash
  • [X] zsh
  • [ ] fish

Problem / Steps to reproduce

Hello, I have the following simplified version of my script, which runs just fine when I run it from shell directly /bin/sh $HOME/test.sh within a tmux session or outside of tmux. However, when I try to run it as tmux run-shell "$HOME/test.sh" it fails with error code 2.

test.sh

#!/bin/bash

run() {
  delx_() {
    ans=$(echo -e "Yes\nNo" | fzf)
    if [ "$ans" == "Yes" ]; then
      echo "Yes $1"
    else
      echo "No $1"
    fi
  }
  export -f delx_
  del_bind="del:become:(delx_ {})"
  binds=" --bind \"$del_bind\""
  fzf_cmd="fzf --no-tmux $binds "

  shell=$(which bash)
  ls | SHELL="$shell" eval "$fzf_cmd"
}

run

I can't change the --no-tmux to --tmux as that starts to throw error 127 and causes fzf to not recognize the exported function as a bash command, however setting --no-tmux does not play nicely when the script is invoked from tmux with run-shell command.

I eventually want to map this script to a keybinding in tmux, so that I run it quickly, but I am not sure why it is failing, so something like this bind M-m run-shell '"$HOME/test.sh"'.

I tested this both tmux version 3.4 and 3.5 and got the same error, so I guess there is something wrong with what I am doing but I am not a shell wizard, so not sure if I am missing something obvious here ?

rbhanot4739 avatar Oct 14 '24 05:10 rbhanot4739

tmux run-shell runs the process in the background, so it won't work with interactive programs.

tmux run-shell top # hangs
tmux run-shell vim # fails

So you have to use --tmux option to start fzf in a tmux popup (or use the legacy fzf-tmux to open in a tmux pane).

causes fzf to not recognize the exported function as a bash command

You might be running into #4001. Try building fzf from the latest source and see if it helps.

junegunn avatar Oct 15 '24 08:10 junegunn

@junegunn thanks for the info. Any eta when this commit will be released as part of the stable release ? I think it seems to fix the issue of bash functions not being exported with --tmux.

rbhanot4739 avatar Oct 15 '24 10:10 rbhanot4739

No specific plan for now.

I think it seems to fix the issue of bash functions not being exported with --tmux.

So with the binary built from the source, does run-shell with --tmux work for you?

junegunn avatar Oct 15 '24 16:10 junegunn

Not the run-shell but the issue wrt to bash exported functions not recognised seems to be fixed.

rbhanot4739 avatar Oct 16 '24 07:10 rbhanot4739

Not the run-shell

Any idea why it's still not working for you? It works fine on my system.

tmux run-shell 'seq 100 | fzf --tmux bottom'

junegunn avatar Oct 20 '24 08:10 junegunn

Oh yeah, it does work with latest commit, apologies for the confusion !

rbhanot4739 avatar Oct 21 '24 08:10 rbhanot4739