Skip to content

zsh-transient-prompt

zsh-transient-prompt splash card

zsh-transient-prompt: Add a transient prompt to your zsh command line — that is, make your current command line's prompt different from past command lines' prompts. For example, past prompts might not need to show as much contextual information. Or you might want to put past commands on their own line, instead of prefixed by a prompt, for easier selecting and copying.

What?

Here's a screencast of Hometown prompt as an example. When you "accept" the command line (that is, hit Enter) the prompt trims down.

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

Or walk through an example. Given the prompt

<time when drawn> <directory when drawn> <Git branch when drawn>

without transient prompt this will happen:

  1. Open a new terminal

    11:11:00 ~/olets/zsh-transient-prompt main
    %
  2. Run a command

    11:11:00 ~/olets/zsh-transient-prompt main
    % echo hello world
    hello world
    
    11:11:47 ~/olets/zsh-transient-prompt main
    %

Compare that to the same prompt, but with the transient prompt

<directory when drawn> %

Now this happens:

  1. Open a new terminal

    11:11:00 ~/olets/zsh-transient-prompt main
    %
  2. Run a command

    ~/olets/zsh-transient-prompt %
    echo hello world
    hello world
    
    11:11:47 ~/olets/zsh-transient-prompt main
    %

 

💅 Don't want to write your own theme? Check out mine, Hometown. It supports transient prompt!