Tmux Jump between Prompt Output with OSC 133 Shell Integration Standard
This apply for Tmux version 3.4 +
Step 1 — The OSC 133 Standard for Prompt Jump
The OSC is Operating System Command. We have many standard here like OSC7 etc.
OSC 133 marks where the prompt start executed, end.
Let’s see what the standard says. I found the one on MS website explain it pretty good.
Basically we need to type
ESC ] 133 ; A ESC \
before every prompt output
Step 2 — Find the way to type the escape char
Now we try to write
ESC ] 133 ; A ESC \
First find the escape for your terminal by
showkey -a
# then hit escape
Press any keys - Ctrl-D will terminate this program
^[ 27 0033 0x1b
You can use either \x1b
as shown above as HEX or default escape code \e
. References here :
Now we do the Testing
# ESC ] 133 ; A ESC \
# can be both written as
echo -n "\\x1b]133;A\\x1b\\"
# OR
echo "\\e]133;A\\e\\"
Then we use TMUX to grab it
# Try to run the command with Ctrl+B then ':'
Ctrl+B
:
# Type in the command
send -X previous-prompt
See if you can go back to previous prompt
Step 3 — Force ZSH to emit the Control Char
Now we will integrate this into every time we run any command
Add this statement into your .zshrc
preexec () {
echo -n "\\x1b]133;A\\x1b\\"
}
Step 4 — Config and Force the Tmux Binding
Here is my binding Alt with ,
and .
I like to remember it like <
and >
without shift.
You set one in your .tmux.conf
bind -n M-m copy-mode
bind -T copy-mode-vi M-. send-keys -X next-prompt
bind -T copy-mode-vi M-, send-keys -X previous-prompt
Closing terminal might not enouh, you may need the hard restart with
tmux kill-server
Here you go !