0

I am scripting the display of the output of a script (well, it is just the program git diff) with tmux: Once a filesystem change is detected the shell script executes tmux send-keys q enter C-l "git diff" enter which has it effectively refresh the git diff view.

You might consider this similar to functionality provided by iTerm's coprocesses.

Problem is, I want it on refresh to scroll back to the same position that it was in.

One of the reasons for using tmux is that the window is actually a totally normal and interactive terminal session that can be interacted with as normal to scroll around to look at the full output.

But I want to obtain the scroll position somehow.

Suppose I want to actually do computation on the text content of the terminal window itself, exactly like iTerm2's coprocess does, but so that I can use it on Linux (over ssh). Does tmux provide this ability?

fedorqui
  • 275,237
  • 103
  • 548
  • 598
Steven Lu
  • 41,389
  • 58
  • 210
  • 364

2 Answers2

1

I'm unsure about capturing this with a script, but less -N will show line numbers. And -jn or --jump-target=n can jump to a location.

demure
  • 7,337
  • 3
  • 22
  • 17
  • cool, thanks. for my actual implementation I have actually given up on less and am now using `tmux` in a crazy way in order to get mouse scrolling. – Steven Lu May 03 '13 at 13:16
  • @StevenLu willing to share details on how you do it? – aurora Oct 15 '13 at 08:01
  • it's basically as I describe in the question, I just now force git diff not to use `less`. this way mouse scrolling works automatically in the (potentially nested) tmux buffer – Steven Lu Oct 15 '13 at 13:18
  • I've circled back to this, the gymnastics that i had to use to manipulate the nested tmux session was unmanageable, and even more so in the face of tmux itself evolving. I am thinking now about either implementing my own augmented less or similarly wrapping a manipulator around it. – Steven Lu Mar 05 '18 at 20:27
0

About iTerm's coprocesses,

tmux has a command pipe-pane that can be used to pipe the input and output of a shell command to the output and input of a target pane specified by -t.

So if I have a shell program, ~/script.sh for example:

#!/usr/bin/env bash
while read line; do
    if [[ "$line" = "are you there?"* ]]; then
        echo "echo yes"
    fi
done

Note that read line will read every line printed to the pane, i.e. the prompt as well.

I can connect its stdin and stdout to pane 0 in my-session:my-window like so:

tmux pipe-pane -IO -t my-session:my-window.0 "~/script.sh"

and then at the prompt, type echo are you there?, and it responds:

$ echo are you there?
are you there?
$ echo yes
yes

Be careful using -IO together as it can easily cause a feedback loop (I had to kill the tmux server a few times while experimenting with this feature, lol).

jameh
  • 1,149
  • 3
  • 12
  • 20