Quantcast
Channel: MarsHut
Viewing all articles
Browse latest Browse all 6551

Different results when running the same script directly in shell vs through tmux run-shell

$
0
0
I use tmux 1.9a in xterm, tcsh.

I tweak a lot with my shell init script and I like to source it again
almost every day in all panes/windows/sessions.

I tried doing that through run-shell in tmux but it didn't work and for now
I am using an alias to do the job.

alias tcmdall "tmux list-sessions -F
'#{session_name}' | xargs -I SESS \\
tmux list-windows -t SESS -F
'SESS:#{window_index}' | xargs -I SESS_WIN \\
tmux list-panes -t SESS_WIN -F
'SESS_WIN.#{pane_index}' | xargs -I SESS_WIN_PANE \\
tmux send-keys -t SESS_WIN_PANE '\!*' Enter"

I was unable to do that same using run-shell and so I made the alias less
complicated to debug it.

When I run the below alias in tmux

alias tcmdallw "tmux list-windows -F
'#{session_name}:#{window_index}' | xargs -I SESS_WIN \\
tmux list-panes -t SESS_WIN -F
'SESS_WIN.#{pane_index}'"

I get,

kmodi:1.1
kmodi:2.1
kmodi:3.1
kmodi:3.2
kmodi:4.1
kmodi:5.1
kmodi:6.1
kmodi:6.2
kmodi:7.1
kmodi:8.1
kmodi:9.1
kmodi:9.2

BUT when I run the same through run-shell using a key-binding,

bind C-e run "tmux list-windows -F '#{session_name}:#{window_index}' |
xargs -I SESS_WIN tmux list-panes -t SESS_WIN -F 'SESS_WIN.#{pane_index}'"

I get,

kmodi:1.1
kmodi:1.1
kmodi:1.1
kmodi:1.1
kmodi:1.1
kmodi:1.1
kmodi:1.1
kmodi:1.1
kmodi:1.1

This "kmodi" session has 9 windows. So it printed "kmodi:1.1" nine times.
But what's strange is that the #{window_index} and #{pane_index} variables
stayed frozen for all the iterations! On the other hand the tcmdallw alias
above did exactly what I expected (cycle through the windows and panes
based on "xargs -I".

So it could be one of two things:
- Either this is a bug that the #{window_index} and #{pane_index} freeze to
the values of current window and pane when executing via tmux run-shell
(but don't freeze when executed via shell alias).
- I am doing it wrong. If so, how can I implement the tcmdallw
functionality using tmux run-shell? My ulimate goal is to get the below
working using a tmux key-binding.

alias tcmdall "tmux list-sessions -F
'#{session_name}' | xargs -I SESS \\
tmux list-windows -t SESS -F
'SESS:#{window_index}' | xargs -I SESS_WIN \\
tmux list-panes -t SESS_WIN -F
'SESS_WIN.#{pane_index}' | xargs -I SESS_WIN_PANE \\
tmux send-keys -t SESS_WIN_PANE '\!*' Enter"

Viewing all articles
Browse latest Browse all 6551

Latest Images

Trending Articles



Latest Images