Repository navigation
feat(terminal): restore the last 10 commands per tab on reopen - #51
Merged
Merged
Conversation
…ut of the history file
This was referenced Nov 17, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Closes #50. A reopened tab starts with an empty shell history, so Up recalls nothing from before the close. Each pane now keeps its last 10 commands in
session.jsonand the new shell's own history is seeded with them, so Up and Ctrl+R work as usual (Git Bash, WSL, pwsh; notcmd).OSC 133;E;<nonce>;<percent-encoded command>. The nonce is a per-session secret passed inEMBER_NONCEand kept in an unexported shell variable, so a mark printed by a program (cat, curl, ssh output) is ignored and cannot plant a command for the next restore.pushPaneCommandfilters (empty, leading space, multi-line, over 1000 chars, obvious secrets such astoken=,password:,Authorization), drops a consecutive duplicate and keeps the newest 10.SavedPane.historyis additive;SESSION_VERSIONstays 1.spawnPane->session_create->HookInput.restore_history-> envEMBER_HIST(newest 10, lines over 1000 chars dropped). The hook loads it withhistory -s/AddToHistoryon the first prompt. The seeds are marked as saved (history -a /dev/null, PSReadLineSaveNothing) so they are not appended to the user's history file again.EMBER_HISTandEMBER_NONCEare only set where the hook is installed, since the hook is what unsets them.Known gaps (not filed):
session.jsonis plain text and the secret filter is best effort (misses--password x,curl -u user:pass, URL credentials, bare token prefixes); a few control characters are not encoded in the bash hook; a failed split's history can attach to the next split;Clear-Historyin pwsh makes the prompt error once; pasting a multi-line script into bash records its last 10 lines; Git Bash spawns onehistory 1subshell after each command (about 14 ms measured).How you checked it
CI runs only after a merge, so these are checked locally:
cargo fmt --check,cargo clippy -- -D warningsandcargo testpass (111 tests)pnpm turbo check test buildandpnpm version:checkpass (181 frontend tests; 9 svelte-check warnings, all inProfileEditor.svelte, untouched)CHANGELOG.mdupdated if behaviour changedAlso checked:
bash_hook_end_to_endruns the real hook in Git Bash (encoding, nonce, leading-space command kept for the app to drop, empty Enter silent, seeds literal and not written toHISTFILE; skipped where Git Bash is missing). The WSL bash hook and the pwsh 7 hook were exercised from scripts. A fresh-context review found no critical issues; its four important findings are fixed here.Checked in the running dev build (
pnpm dev, Git Bash tab, cleansession.json): ranecho first-cmd,echo 'a;b%c',echo hidden-leading-space,export TOKEN=abc123,echo last-cmd.session.jsonsaved onlyecho first-cmd,echo 'a;b%c',echo last-cmd(leading-space andTOKEN=lines skipped,;and%intact). After close and reopen, Up recalledecho last-cmd,echo 'a;b%c',echo first-cmdin that order. A second close and reopen left the same three entries (no duplicates). Git Bash did not write these commands to~/.bash_historyon tab close, so this is the only place they persist.Not verified: WSL, pwsh and split panes in the running app (hooks exercised from scripts only), PSReadLine seeding in a real interactive pwsh, and macOS.