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?
.bashrc
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
}
.tmux.conf
bind-key t run-shell "tmux__ranger_to_vim"
--rcfile
is only used for interactive shell invocations. Running thebash
command that you show would never use the--rcfile
file since it's not starting an interactive shell. On the other hand, ifBASH_ENV
was set to the pathname of a file, that file would be sourced for non-interactive shells. – Kusalananda Jan 08 '21 at 12:30rcfile
is used instead of standard.bashrc
when shell is interactive but it doesn't sayrcfile
is not used when shell is non-interactive, unless invoked assh
. Also I saw usage ofrcfile
withouti
flag in this answer https://unix.stackexchange.com/a/432111/390120 – vatosarmat Jan 08 '21 at 13:20bash
does not use--rcfile
for non-interactive shells. – Kusalananda Jan 08 '21 at 13:31