Awesome
Yellow Sea Diamonds đ¶đ¶đ¶ theme for Zsh/Oh My Zsh
<img width="660" alt="Omnibus_demo_YSD_theme_annotated" src="https://user-images.githubusercontent.com/8410716/173704660-d06e09da-69e7-4a57-a1d2-e979124c39be.png">See this README on GitHub.
Description of output and selective discussion of rationales
Hereâs my theme for Zsh and Oh My Zsh that I developed for my personal workflow that is characterized by:
- git
- Python 3 development
- Consistent use of venv virtual environments
- I am the only person working on my machine
- Therefore I donât need to be told who the âuserâ is
- Iâm not working with multiple machines/hosts
- Therefore I donât need to be told the name of the machine
- I know what time it is and canât think of any reason to have a date or time stamp on the prompt line (though apparently other people do have such needs)
- I work on macOS 12.4 (Monterey) using iTerm and Oh My Zsh
- (Although I use VS Code, too, I almost always use iTerm2 as the terminal app rather than VS Codeâs integrated terminal)
- This is the only environment on which Yellow Sea Diamonds has been tested
- Will my diamond emoji with color
âYellow Seaâ (âđ¶â) render
correctly and with the the same color on other peopleâs systems?
- I donât know!
This theme creates a two-line prompt structure (not including the leading blank line to create some whitespace after the just-previous output):
- Line 1:
- â(venv)â (or whatever the name of your virtual environment directory)
- The presence of this descriptor is conditional on your having an activated virtual environment
- See § Usage note: Prevent duplication of the â(venv)â virtual-environment prompt below to stop virtualenvâs own â(venv)â output from being duplicative
- Current working directory, with â~â replacing $HOME when possible
- Git information (conditional on there being git information to display)
- â | git: â
- Branch name
- Clean (â ) or Dirty (â), depending on whether there are uncommitted changes on your branch.
- The SHA-1 hash of the current commit
- â(venv)â (or whatever the name of your virtual environment directory)
- Line 2 (the actual prompt line):
- Report of return code, ONLY if the return code was nonzero
- Red box with white letters: âERROR #64â, where here the 64 is an example of a return code I encountered.
- An easy way to test this is just to enter at the prompt:
sh -c 'exit 1'
- I rejected including a â or similar for a zero return code, because in my experience thatâs not an exceptional event and so adding such would create visual noise not offset by the minimal informativeness of the extra symbol.
- The Yellow Sea Diamond prompt, (âđ¶â), after which this theme is named
- Report of return code, ONLY if the return code was nonzero
Packing most of the content into the first line leaves plenty of room on Line 2 for comments with long arguments, particularly long file paths.
Examples of output
Current working directory (CWD) onlyâno git, no venv, no error return code
<img width="876" alt="Current_working_directory_only" src="https://user-images.githubusercontent.com/8410716/173452015-7bb02eaf-0eab-4dae-b601-b4324882f62d.png">CWD plus activated virtual environment
<img width="876" alt="Name_of_activated_virtual_environment" src="https://user-images.githubusercontent.com/8410716/173451313-efd99a0f-88ff-4891-b478-f4825d604ef1.png">CWD plus git (with no uncommitted changes, i.e., âcleanâ)
<img width="875" alt="Git_example_clean" src="https://user-images.githubusercontent.com/8410716/173451576-273553c7-9b31-4288-ac1b-248f25097c73.png">CWD plus git (with uncommitted changes, i.e., âdirtyâ)
<img width="875" alt="Git_example_dirty" src="https://user-images.githubusercontent.com/8410716/173451603-b88bb508-3c79-4523-806b-c3c43e4ca922.png">CWD plus nonzero return code
<img width="879" alt="Nonzero_return_code_example" src="https://user-images.githubusercontent.com/8410716/173451675-5686422f-ca17-47ce-b9ce-464e5f4b39fd.png">Install Yellow Sea Diamonds
You can download this theme from its GitHub repository at:
https://github.com/jimratliff/yellow-sea-diamonds-zsh-theme/archive/refs/heads/main.zip
and unzip the archive to find the Oh My Zsh theme file yellow-sea-diamonds.zsh-theme
.
Although that is the file name, the theme name is simply yellow-sea-diamonds
.
You can install Yellow Sea Diamonds in either of the following locations
~/.oh-my-zsh/themes
or
~/.oh-my-zsh/custom/themes
Then edit your ~/.zshrc
file and change its ZSH_THEME
line to be:
ZSH_THEME="yellow-sea-diamonds"
Follow this up with:
source ~/.zshrc
Usage note: Prevent duplication of the â(venv)â virtual-environment prompt
When you activate a venv virtual environment, virtualenv will supply its own â(venv)â line of output. If you donât prevent that, this will be annoyingly duplicative of Yellow Sea Diamondâs own â(venv)â prompt component. See the screenshot immediately below.
<img width="879" alt="(venv)_with_duplication" src="https://user-images.githubusercontent.com/8410716/173463867-255cd7fc-3a0d-44d8-b842-0e4d8855f6d9.png">The key to preventing this duplication is issuing the following command before you activate your virtual environment:
export VIRTUAL_ENV_DISABLE_PROMPT=1
(Hat tip to icktoofayâs answer and Marlon Richertâs answer on Stack Overflow. Also, see the documentation for VIRTUAL_ENV_DISABLE_PROMPT
: âAny virtualenv activated when this is set to a non-empty value will leave the shell prompt unchanged during processing of the activate script, rather than modifying it to indicate the newly activated environment.â (Emphasis in original.))
See the next screenshot for this method in action: <img width="879" alt="(venv)_without_duplication" src="https://user-images.githubusercontent.com/8410716/173463935-af8b2c22-151a-4ce7-a2a8-8430b40d7d0d.png">
Of course, you wonât want to have to remember to type this command every time you activate a virtual environment. Youâll probably find it worthwhile to make an alias like the following:
alias activate_venv='export VIRTUAL_ENV_DISABLE_PROMPT=1;source venv/bin/activate'
Then, after cd
-ing into the directory in which your venv
directory resides, just type activate_venv
to
simultaneously activate your virtual environment while also suppressing Zshâs otherwise duplicative â(venv)â output. See the next screenshot:
<img width="879" alt="(venv)_without_duplication_using_alias" src="https://user-images.githubusercontent.com/8410716/173464465-18b83048-397e-4863-8531-5a742149f0bf.png">
Some tips for customizing Yellow Sea Diamonds, or any theme, to your liking
Good resources to learn about customizing themes
An outstanding source to learn about customizing themes is Sarah Port, âWriting ZSH Themes: A Quickref,â CarbonFive, March 3, 2020. In particular the Quick Reference is amazing.
Also see:
- Armin Briegel, âMoving to zsh, part 6 â Customizing the zsh Prompt,â Scripting OS X.
- § âPrompt Expansionâ in The Z Shell Manual.
Changing colors
Itâs very easy to change the color scheme of Yellow Sea Diamonds.
Yellow Sea Diamonds specifies a color by using an integer 0â255 in, for example, an %{$FG[226]%}
command, where FG
stands for âforeground,â as opposed to %{$BG[226]%}
, which sets the background color.
[To be honest, I have no idea what all the characters in, for example, %{$FG[226]%}
, are doing. If theyâre really necessary, somehow Iâve gotten away with simple use of $FG[226]
, as youâll see in the code for Yellow Sea Diamonds. (Iâd love to be enlightened! đ§]
If you want to conveniently access the mapping between integers and colors, just use the spectrum_ls
command, e.g.,
see the next screenshot:
After you turn on a new color with $FG
, youâll at some point later want to reset it (so that color doesnât take over the world) with
%f
. To reset the background color, use %k
. To reset both foreground and background simultaneously, youâll often
see %{$reset_color%}
.
You can also access a handfull of colors by name, rather than number: Black, Red, Green, Yellow, Blue, Magenta, Cyan,
White. If you specify a color by name, youâll need to use the lowercase version of $FG and $BG, e.g., $fg[red]
.
Deleting a component or rearranging components
The ultimate output of Yellow Sea Diamonds, or any such theme, is the prompt structure itself.
In YSD, this is defined at the very end of the theme:
PROMPT="
ââ$VIRTUALENV_REPORT $CWD $GIT_REPORT $COMMIT_HASH %{$reset_color%}
â°â$REPORT_RETURN_CODE\$(prompt_char) "
I hope that the components are named so transparently that itâll be fairly obvious how to delete something you donât want or rearrange the components that are already there.
Each of the components is defined above the prompt structure, and they are defined in the same order that they appear in the prompt structure (L to R, then up to down).
Of course, you can add components, too. But youâre on your own there. đ
Look out for: does the commit hash continue to update automatically?
As you modify and refactor, Iâd suggest that you continuously test your code.
One thing in particular to watch out for: Does the commit hash continue to update automatically? Iâve had the problem arise where a commit hash would be displayed, but thenâafter I made a subsequent commitâthat hash wouldnât change. Itâs an easy failure to miss, so I suggestâas part of your testing during developmentâto continuously make a new commit to check whether its hash updates.
Version History
- 1.0.0 6/13/2022
License
This project is licensed under the MIT License - see the LICENSE.md file for details.