Appearance
Transient prompt
Hometown has a “transient prompt” feature. When transient prompt is enabled (as it is by default), the current command line gets a distinct prompt.
Transient prompt is a type of “dynamic” prompt: it changes once, right after you execute a command (that is, right after you hit Enter).
Here’s the default configuration in action.
Toggle to show/hide an annotated transcript
shell
mkdir -p repo/child/grandchild/great-grandchild
cd repo
# cwd changes to current dir
# previous prompt simplifies: cwd has only one segment
git init
# cwd changes to underline Git repo root; Git branch and its appear
cd child
# cwd changes to current dir. segments start at repo root's parent
cd grandchild
# cwd changes as before
# previous prompt simplifies: cwd starts at the repo root
cd great-grandchild
# cwd changes. shows at most repo root's parent, repo root, ellipsis, cwd parent, cwd
git init
# cwd changes to underlined repo root, and parent
touch x y
# Git status changes
git add -A
# Git status changes, Git branch color changes
git commit -m first
# Git status changes, Git branch color changes
git switch -c feature
# Git branch changes, Git branch color changes
echo wip >> x
# Git status changes, Git branch color changes
git stash
# Git stash appears, Git status changes, Git branch color changes
echo a >> x
# Git status changes
rm y
# Git status changes
git add .
# Git status changes
git commit -m second
# Git status changes, Git branch color changes
git stash drop
# Git stash disappears
git switch main
# Git branch changes
echo b >> x
# Git status changes, Git branch color changes
git commit -am third
# Git status changes, Git branch color changes
git rebase @ feature
# Git HEAD changes, Git HEAD color changes, Git status changes, Git action appears, prompt character color changes
git checkout —ours x
# Git status changes, Git action appears, prompt character color changes
git add x
# Git HEAD changes, Git HEAD color changes, Git status changes, Git action appears
git rebase —continue —no-edit
The typical reason to use a transient prompt is to show additional information in the current prompt than in past prompts. That’s how Hometown’s works by default. The default Hometown transient prompt
- is on one line (saves space)
- hides all inactive components (saves space)
- is not preceded by a linebreak (saves space)
- moves the prompt character from the start of the command line to the start of prompt (makes it easy to copy and paste prior commands)
- appends the time the command was run — looks like “HH:MM:SS prompt drawn timestamp - HH:MM:SS next command execution start timestamp” (can be helpful when revisiting history)
- if the two were on different days, dates are added— “MM/DD/YY HH:MM:SS prompt drawn timestamp - MM/DD/YY HH:MM:SS next command execution start timestamp”
TIP
You can configure your prompt to show the same timestamp range as the default transient prompt. See the recipe.
Customizing
You can customize the transient prompt with the same options as the regular prompt. Declare them within HOMETOWN_TRANSIENT_PROMPT_ENV
. See Options.
Hometown can (and by default does) set psvar
, providing some values which may be useful in transient prompt customization. See Options and zsh’s official prompt expansion conditional substrings documentation.
Performance
Disabling transient prompt may reduce first prompt lag (time from the start of the shell to appearance of the prompt) by less than 10ms, first command lag (time from the start of the shell to the soonest the first interactive command can start executing) by approximately 20ms, and command lag (the time between pressing Enter on a blank line and the next prompt appearing) by less than 15ms, as measured by zsh-bench.
Nota bene
There’s an edge case where prompts have different content depending on whether transient prompt is enabled.
It comes up when changing the Git state from outside the terminal.
Suppose you have a Git repo with one unstaged modified file. You open that directory in two terminals. In both terminals the prompt reflect the one unstaged modified file. Now in the first terminal you run git add -A
. The first terminal now has a new prompt reflecting one staged modified file; the second terminal still has its prompt reflecting one unstaged modified file. Now hit Enter in the second prompt.
The second terminal’s current prompt now reflects the one staged modified file. But there’s a difference: with transient prompt disabled (and in Hometown v3) the second terminal’s previous prompt still reflects one unstaged modified file, but with transient prompt enabled it has been updated to reflect one staged modified file.