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.
pager (less) -- get current scroll position?
Question
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?
Solution
OTHER TIPS
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).