I am trying to implement a feature of opening files in vim using ranger in separate tmux pane. It works if define commands directly in .tmux.conf. But having much code there doesn't look good, so I am trying to move it into functions and source them in .bashrc, but this yelds 'tmux__ranger_to_vim' returned 127. Why tmux run-shell doesn't see functions defined in .bashrc and is it possible to make them available for it?


    function tmux__current_pane_has_process {
      test -n "$1" || { echo "No process name" >&2; return 1; }
      pattern='^[^TXZ ]+ +'"${1}"'$'
      ps -o state= -o comm= | grep -iqE "$pattern"
    function tmux__ranger_to_vim {
      tmux__current_pane_has_process 'ranger' || return 0
      tmux send-keys 'y'
      sleep .01
      tmux send-keys 'p'
      tmux select-pane -L
      tmux__current_pane_has_process 'n?vim' || return 0
      tmux send-keys ':tabe ' C-r * C-m


bind-key t run-shell "tmux__ranger_to_vim"

1 Answer 1


tmux run-shell runs command as sh -c which doesn't source .bashrc. Also on some systems sh is not a bash at all but dash. So one have to explicitly source the file where required function defined before calling it:

bind-key t run-shell 'bash -c "source ~/.tmux.bash ; tmux__ranger_to_vim"'
  • 1
    --rcfile is only used for interactive shell invocations. Running the bash command that you show would never use the --rcfile file since it's not starting an interactive shell. On the other hand, if BASH_ENV was set to the pathname of a file, that file would be sourced for non-interactive shells.
    – Kusalananda
    Jan 8, 2021 at 12:30
  • @Kusalananda but for me it just worked. Bash man page says rcfile is used instead of standard .bashrc when shell is interactive but it doesn't say rcfile is not used when shell is non-interactive, unless invoked as sh. Also I saw usage of rcfile without i flag in this answer unix.stackexchange.com/a/432111/390120
    – vatosarmat
    Jan 8, 2021 at 13:20
  • Well, I can't get this to work on my system since bash does not use --rcfile for non-interactive shells.
    – Kusalananda
    Jan 8, 2021 at 13:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .