While Tmux does have a "mark" function, I don't think it will work for your use-case.
In copy-mode, pressing Shiftx (a.k.a. "X") sets a mark, and Metax will then toggle between the current location and that mark. The problem is that when you exit copy-mode, the mark is lost. So you wouldn't be able to run a subsequent tail -f
and get back to that point.
My personal recommendation would be to use a pager for the output that supports (a) following a growing file, and (b) mark/jump functionality. That can found pretty easily in the less
command. Your workflow would be pretty close to what you describe:
less +F
some stuff
- Ctrl+c to temporarily exit follow-mode
- ma to set a mark called "a"
- F to restart follow-mode
- Do something which causes a lot of output to be logged
- Ctrl+c to temporarily exit follow-mode (you wouldn't want it scrolling while analyzing your output anyway).
- 'a to jump to your mark
- F to restart follow-mode when/if desired
Edit/Update
If you really want a "mark" and "goto-mark" function, it's possible, but very hacky, IMHO. I'm really only posting this because (a) I finally got it to (mostly) work, and (b) I want to get it out of my config, but don't want to lose work.
First, create two separate additional files:
.tmux-set_mark.tmux
:
# Must use "run-shell" since it can run the
# command immediately. The #() syntax always
# uses the *previous* results.
# The capture-pane is hackery to get the current
# line number we are on (starting from the
# beginning of the history.
run "tmux set-environment TMUX_CUR_LINE $(tmux capture-pane -S - -E - -p | tac | awk 'NF {p=1} p' | wc -l)"
# Store it in a user-option on the current
# pane. This allows marks in multiple panes
# to work.
set-option -F -p @TMUX_MARK "#{TMUX_CUR_LINE}"
display-message "Mark set at line #{@TMUX_MARK}"
.tmux-goto_mark.tmux
:
# Must use "run-shell" since it can run
# the command immediately. The #()
# syntax always uses the *previous*
# results.
run-shell "tmux set-environment TMUX_CUR_LINE $(tmux capture-pane -S - -E - -p | tac | awk 'NF {p=1} p' | wc -l)"
# Set a user option on the pane with
# the line number we need to goto.
# This is calculated, of course, by
# subtracting the marked-line-number
# from the current-line-number
set-option -F -p @TMUX_GOTO "#{e|-:#{TMUX_CUR_LINE},#{@TMUX_MARK}}"
copy-mode
# Goto the line. Again `run-shell` is needed
# here since send-keys can't expand the FORMAT
# string, but run-shell can.
run-shell 'tmux display-message #{@TMUX_GOTO}'
run-shell 'tmux send-keys -X goto-line #{@TMUX_GOTO}'
# The next two lines are just additional
# hackery to use the built-in TMux marking
# ability so that the marked line is highlighted
# and at the top of the screen
send-keys -X set-mark
send-keys -X jump-to-mark
Then, in your .tmux.conf
, set key-bindings to source these files:
unbind x
bind x source-file "$HOME/.tmux-set_mark.tmux"
unbind X
bind X source-file "$HOME/.tmux-goto_mark.tmux"
This is horrible, IMHO. Easier possible methods fail:
- It would be easier if there was a better way to get the current line number you are on in the buffer, but there doesn't seem to be a variable for this. The closest I could find was
history_size
, but the history doesn't start until you begin scrolling your pane.
- It would be easier if
goto-line
took an absolute line number, instead it is the relative line number from the bottom of the buffer in copy-mode, not the top.
There's one additional caveat/bug to this code. If you do this on the first "page" of a Tmux pane (before you start scrolling), the line that it hightlights will not be the one that you marked. The alternative is to not use the:
send-keys -X set-mark
send-keys -X jump-to-mark
But then the goto-line
will always place the desired mark at the bottom of the pane, meaning you will always need to scroll down a pane.
# mymark
before you start running command 3. and then you can search back to that unique string?tail -f ...
) -- Presumably it's a log-runningtail
that is always in a particular pane. The new command in step 3 that causes the log to do something interested is coming in a separate pane, most likely (or even triggered by something entirely external). It is possible to type in the terminal whiletail
ing something, so putting a comment in would work, but only if no additional input comes in while typing. That might be tough iftail
'ing a rapidly growing log file.