Hometown: A Dynamic, Highly Configurable Git-Focused Zsh Theme

Last Updated

A fast zsh prompt that packs in a lot of Git status info
null

What I want in my prompt are the time, whether or not Iā€™m one of my usual users, whether or not Iā€™m on one of my usual hosts, what directory Iā€™m in, whether Iā€™m root, whether the previous command errored, and lots of Git info.

Thatā€™s what my zsh theme Hometown shows.

Try it out

Screenshots donā€™t do justice to all the configurability, or the dynamic content. To really get a feel for Hometown, install itā€¦ or play with the docsā€™ interactive demo!

Which Git data points to include is configurable. The Git data points you do include can appear, disappear, and change colors based on the Git status.

You can configure certain users and hosts as hidden ā€” use that to only show user and/or host if they arenā€™t your usual.

How much of the directoryā€™s path to show is configurable.

I donā€™t want to be stuck in the same thing always, and wanted it to be flexible enough for other users to enjoy, so every color and symbol is customizable; there are one-line, two-line, and three-line layout options; and thereā€™s a spot for you insert any arbitrary prompt code youā€™re missing.

A lot of information, but the presentation is compact. Hereā€™s a screenshot of Hometown with its default configuration:

Hometown Prompt screenshot, default configuration

That little thing packs in a lot of information:

  • the user is one Iā€™ve configured as hidden (otherwise the user would be shown)
  • the host is one Iā€™ve configured as hidden (otherwise the host would be shown)
  • the current directory is the root of the Git repo hometown-prompt, which is in the olets directory
  • the working tree is dirty (if it werenā€™t, the branch name would not be colorized)
  • the branch main is checked out (if HEAD were detached, the checked-out commitā€™s SHA would be shown)
  • main has an upstream (if it didnā€™t, the word ā€œlocalā€ would be shown)
    • mainā€™s the upstream is origin/main (if the upstream branch name were different, it would be show; if the upstreamā€™s remote were not origin, it would be shown too)
    • main is zero commits behind its upstream (if it were the ā€œbehindā€ count would be shown)
    • main is fifteen commits ahead of its upstream
  • main has not be set up for a triangular workflow (if it were the push remote would be shown)
  • there is no tag at the checked-out commit (if there were any the first would be shown)
  • there are seven stashes, and three staged new files
  • there are no untracked files, no conflicted files, no unstaged deleted files, no unstaged modified files, no staged deleted files, and no staged modified files (if there were, those symbols would have number and would be colorized and not dimmed)
  • no files are marked as skip-worktree (if there were, the skip-worktree symbol and count would be shown)
  • no files are marked as assume-unchanged (if there were, the assume-unchanged symbol and count would be shown)
  • there is no ongoing action (e.g. rebase, cherry-pick, etc; if there were it would be shown)
  • the previous command did not error (green prompt character)
  • the user is not root (prompt character is %)

Not the look you want? Change it!

  • Layout, every color, every symbol, the hidden users, the hidden hosts, the default remote, and the default push remote can be configured.
  • If you prefer words over symbols ā€”e.g. ā€œstashesā€ instead of ā€œā‡²ā€ā€” thatā€™s just one toggle away, and the words can be customized too (you donā€™t even have to make them wordsā€” you could have two symbol sets to switch between)
  • You can disable some content entirely, and custom content can be inserted.

Hereā€™s a screenshot of the same scenario but with Hometown configured to take up three lines, to use words instead of symbols, and to hide inactive status info rather than dimming it.

Hometown Prompt screenshot, three-line layout

Hereā€™s a screenshot Hometown configured to put everything on one line, and to hide rather than dim inactive status info and inactive behind/ahead.

Hometown Prompt screenshot, one-line layout

Hereā€™s on one more screenshot showing custom colors, and custom symbols

Hometown Prompt screenshot, custom colors and symbols

Thatā€™s just a few of the possibilities: you can mix and match layout customization, color customization, and symbol/word customization. And itā€™s only one scenario: what is shown changes with the Git status.

Another project to check out

Hometown is built on Git Prompt Kit, a library of feature-rich performant components for adding Git info to your own custom zsh theme. Read about it in Git Prompt Kit: Configurable, Fast Git Status Components For Custom Zsh Themes

Learn more in the Hometown docs.

If you like it, or just feel like saying ā€œnice workā€, let me know by starring the GitHub repo.

Articles You Might Enjoy

Or Go To All Articles