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"
--rcfileis only used for interactive shell invocations. Running thebashcommand that you show would never use the--rcfilefile since it's not starting an interactive shell. On the other hand, ifBASH_ENVwas set to the pathname of a file, that file would be sourced for non-interactive shells. – Kusalananda Jan 08 '21 at 12:30rcfileis used instead of standard.bashrcwhen shell is interactive but it doesn't sayrcfileis not used when shell is non-interactive, unless invoked assh. Also I saw usage ofrcfilewithoutiflag in this answer https://unix.stackexchange.com/a/432111/390120 – vatosarmat Jan 08 '21 at 13:20bashdoes not use--rcfilefor non-interactive shells. – Kusalananda Jan 08 '21 at 13:31