Originally published on MistLab. Part 9 of Building an SSH Terminal.
Part 9 of "Building an SSH Terminal". This is MistTerm v1.2.38. Parts 1–8 still quote v1.2.26.
TL;DR
You can jump to the previous command and copy that command plus its output in one step. The app only knows the edges if the shell prints invisible markers. That convention is called OSC 133. A plain bash prints none until a few lines are added to its startup file. There is no button that runs the command again.
A long session leaves the last df somewhere above the fold. You want to land on it, then take that command and its output together. The ls above it, and the prompt that came after, stay where they are.
A plain scroll of mixed lines, beside one command shaded as a block you can jump to and copy.
What the keys do
With the terminal focused, these three shortcuts are handled in the app. On macOS the same actions are ⌘⇧ with the arrow or with O.
Previous command, next command, and copy. Past the last command, next returns to the latest output.
The keys stop here. They are not typed into the server. If the shell never printed the marks, the view stays put and a hint points at the manual. Right-click still lists the three actions.
Enter is a bad boundary
The screen is one long scroll. A command can take several lines. A prompt does not always end in $. vim, less and htop fill the screen with lines that are not commands. MistTerm waits for the shell to mark the edges. It does not build a block from Enter, or from a line that merely looks like a prompt.
Where the marks sit
The shell prints marks you cannot see, so the app knows where a command starts and where it ends. That convention is called OSC 133. VS Code's shell integration uses the same letters under OSC 633, and MistTerm accepts those too.
Hidden marks sit around the command. Copy takes the shaded command and its output. The prompt stays out.
Copy starts at the command and includes the output. The prompt stays out. While a command is still running, copy stops at the cursor. A command that opens vim or less is still one block. What you copy is the command you typed. The full-screen view stays on that screen. A very long output keeps the start, about 4,000 lines or 200,000 characters, and the rest is marked truncated. Change the window width, or clear the scrollback, and the saved positions are gone.
The "command finished" mark can carry an exit code. Part 10's log may read that number. The number is for the log. The block on screen comes from the edges.
Turning it on
If iTerm2 or VS Code shell integration is already on that account, leave it. Otherwise paste this into the remote ~/.bashrc. It is the short snippet from the manual. When a command finishes it prints a hidden mark, including the exit code, and it marks around the next prompt so the command sits apart from the prompt text.
__mist_cmd_block() { local ec=$? printf '\e]133;D;%s\a' "$ec" printf '\e]133;A\a' } PROMPT_COMMAND="__mist_cmd_block${PROMPT_COMMAND:+;$PROMPT_COMMAND}" PS1="${PS1}"'\[\e]133;B\a\]' zsh has a matching snippet in the manual. Open a new tab so the shell reloads. This is ordinary shell code. Anyone who can edit the file can remove it, and any program can print the same bytes. That is enough for jumping and copying. It is the same kind of mark as the one in Part 6: useful here, useless as a lock.
Two things this release leaves alone
There is no action that sends the command again. The current directory travels in a different hidden message, the ones other apps call OSC 1337 and OSC 133 ; P. v1.2.38 leaves those unread.
Summary
- Jump to the previous command, or copy that command plus its output.
- The shell has to print the hidden marks. A stock bash prints none until the snippet is in its startup file.
- With no marks, the view stays put and the keys are not typed into the server. The menu still lists the actions and points at the manual.
- v1.2.38 does not send the command again, and it does not record the current directory.
FAQ
Why can't I jump to the last command on a new server?
The shell has to print hidden marks. A default bash does not. Add the short snippet from the manual to that account's ~/.bashrc and open a new tab.
Can I run the command again?
No. v1.2.38 jumps to the command and copies it with its output. It does not send the command again.
Does this remember the directory?
No. Other apps use a different hidden message for the current directory. v1.2.38 does not read those (OSC 1337, and OSC 133 ; P). Jump and copy only use the edges of the command.



