Skip to content

Fat & fast ZSH theme – beautiful inside and out, styled segments done right

License

Notifications You must be signed in to change notification settings

softmoth/zsh-prompt-newt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Newt ZSH Theme

Installation

This is a sample .zshrc. Your plugin manager may have features which automate integrating prompt themes.

# Optional Newt theme settings
DEFAULT_USER=jdoe
: ${PROMPT_NEWT_LOOK=mono}
zstyle :prompt-theme:newt:\* left time context dir
# This enables promptinit to find prompt_newt_setup
# See PROMPT THEMES in zshcontrib(1)
fpath+=~/path/to/repos/zsh-prompt-newt
autoload -Uz promptinit; promptinit
prompt newt

Please open an issue if you have installation tips that may help others.

Looks

Newt comes with these pre-defined looks: default, denver, forest, meadow, mono.

Use a look with prompt newt meadow.

Newt Theme Preview

These looks are simply shorthand for the zstyle configuration, as described in Styling. So the look can be used to get most things as you like, and then individual elements can be refined further.

Custom looks

Create an adhoc look with prompt newt adhoc blue white magenta, giving a name and a list of colors. Each color can be

  • black, red, yellow, green, blue, magenta, cyan, white, or

  • a color number supported by your terminal, or

  • a truecolor specification as described in Truecolor support, or

  • '' or _, meaning the terminal’s default background / foreground, or

  • none, meaning do not set the color, use whatever is already active

Colors indexes

The list of colors is

  1. Primary background

  2. Primary foreground

  3. Secondary background

  4. Secondary foreground

  5. Alert background

  6. Alert foreground

  7. Red

  8. Green

  9. Yellow

  10. Blue

  11. Magenta

  12. Cyan

  13. Black

  14. White

Since the forest look specifies 4 colors, the following will change the Alert (colors 5 & 6) to pale yellow on a hot pink background:

prompt newt forest 161 227

Re-running prompt newt

When prompt newt is run with no arguments, or if the first argument is --, it uses the value of $PROMPT_NEWT_LOOK in the environment. And it always sets PROMPT_NEWT_LOOK to the current settings.

It also takes a snapshot of any zstyle settings that have been set.

This means that, for example, sudo -Es will inherit the current look. It is possible to add more colors to the current look by following the -- with colors. For example

prompt newt example blue white
prompt newt -- green black
prompt newt -- red yellow

That is equivalent to prompt newt example blue white green black red yellow.

Styling

This theme uses the ZSH configuration system, called zstyle, to specify the look and behavior of the prompt. It is documented in the zshmodules(1) manual page. Briefly, a style is a configuration setting, which is looked up in a context. In the English phrase "Give me the background color for the time segment in the default state, using the forest look," the style being requested is "background color", and the context is the forest, time segment, default state.

When you specify a style, often the context you provide will be a pattern with wildcards in it. For example, you can specify the background color for the time segment’s default state in any look with:

zstyle :prompt-theme:newt:*:time:default bg yellow

So, in general, segments can be configured with the context :prompt-theme:newt:LOOK:SEGMENT:STATE.

Look can be any word you like, except for a color name (red, _, etc.). You can call prompt newt LOOK to use a particular look.

If just prompt newt is run, the look is inherited from the $PROMPT_NEWT_LOOK environment variable, or is default.

Segment is the name of the segment, e.g., dir or time.

State is segment-specific, and is default for most segments most of the time.

Run prompt_newt_defaults to show the built-in settings. Your custom overrides can be shown with zstyle -L ':prompt-theme:newt:*'. To remove an override, run zstyle -d ':prompt-theme:newt:*:the:pattern' [look].

Examples

zstyle ':prompt-theme:newt:*:vcs:*'          bg blue
zstyle ':prompt-theme:newt:*:vcs:*'          fg yellow
zstyle ':prompt-theme:newt:*:vcs:clobbered'  bg yellow
zstyle ':prompt-theme:newt:*:vcs:clobbered'  fg red
# Revert the first two changes
zstyle -d ':prompt-theme:newt:*:vcs:*'
zstyle ':prompt-theme:newt:forest:dir:*'     bg green
zstyle ':prompt-theme:newt:forest:dir:*'     fg blue
# Only use the left prompt
zstyle ':prompt-theme:newt:*' left time context status jobs vcs dir
zstyle ':prompt-theme:newt:*' right none

Segments

The segments used for left and right prompts can be set with:

zstyle ':prompt-theme:newt:*' left  history time context dir
zstyle ':prompt-theme:newt:*' right vi_mode status exec_time jobs vcs

This change requires the prompt to be set up again. Run prompt newt for the change to take effect.

The values shown above are default. It is also possible to modify the default settings, adding or removing individual segments, with:

# left gets: time context dir vcs
zstyle ':prompt-theme:newt:*' left  -history +vcs

# right gets: prompt_time vi_mode status vcs exec_time
zstyle ':prompt-theme:newt:*' right '+prompt_time -jobs * +exec_time'

context: User and host name

User name is hidden unless it is different from $DEFAULT_USER.

Host name is hidden unless $SSH_CLIENT is set.

dir: Current directory

It uses the '%4~' zsh format by default, which shows nested directories to four levels. Set the format with

zstyle :prompt-theme:newt:\*:dir default '%/'

exec_time: Execution time

The states are default and long.

The threshold from default to long can be set with

zstyle ':prompt-theme:newt:*:exec_time' threshold 30

The default is 5 seconds. It can be fractional, for example 0.75.

The precision can be set with

zstyle ':prompt-theme:newt:*:exec_time' precision 3

The default is 1 if the execution time is below 10 seconds, and 0 otherwise.

By default, the long state shows times in a human-friendly format like 間1h22m33s. The default state is empty (so times below the threshold are not shown). The format can be set with:

# %s: seconds
zstyle ':prompt-theme:newt:*:exec_time' long    '🕑%s'
# %t: human-friendly
zstyle ':prompt-theme:newt:*:exec_time' default '🕑%t'

history: History number

jobs: Background jobs

States are default and zero. The zero state defaults to empty, so when there are no background jobs, nothing is shown. The default state shows an icon and, if there is more than one job, the number of jobs. Run prompt_newt_defaults to see the full setting.

none: Placeholder to do nothing

This might be used to disable the right side prompt, for example:

zstyle ':prompt-theme:newt:*' right none

prompt_time: Prompt time

Displays how long it takes for the prompt itself to be drawn. This segment is off by default. The precision can be set with

zstyle ':prompt-theme:newt:*:prompt_time' precision 3

status: Exit status

The status segment states are ok, error and suspended. By default only error status is shown. To always show a status, set:

zstyle ':prompt-theme:newt:*:status' ok        $'\u2713' # ✓
zstyle ':prompt-theme:newt:*:status' suspended $'\u25c6' # ◆

time: Time

Shows the current time. The format can be set with

zstyle ':prompt-theme:newt:*:time' default '%*'  # HH:MM:SS

vcs: Version control

States are clobbered, root, action, dirty and default. Most of the display is controlled by `vcs_info`:

# See zshcontrib(1) for more options related to version control
zstyle ':vcs_info:*' enable git cvs svn bzr hg
zstyle -L ':vcs_info:*'

vi_mode: Vi mode

States are viins, vicmd, replace, isearch, visual and vline.

Note
Only viins and vicmd states are available by default. The others require the vim-mode plugin.

Text and colors can be changed. For example:

zstyle ':prompt-theme:newt:*:vi_mode' vicmd NORMAL
zstyle ':prompt-theme:newt:*:vi_mode:vicmd' bg 202
zstyle ':prompt-theme:newt:*:vi_mode:vicmd' fg 235

Separators

The theme uses Powerline arrows to separate segments by default. It also has built-in support for separator characters from the Nerd Fonts Powerline Extended set. Request the round half-circle separators with:

zstyle ':prompt-theme:newt:*:*:*' separator nerd-round

The defined separators are: powerline, fade, nerd-round, nerd-backward, nerd-forward, nerd-flame, nerd-pixel, nerd-waveform.

Separators demonstration

Several of the separators may be drawn as two characters wide. If you are using the "Mono" version of a Nerd font, this will create a severe gap after the separator. Turn off the compensatory spacing with:

zstyle ':prompt-theme:newt:*' wide-separators 0

A segment’s separator can be reversed, so its arrow points in rather than out:

# Reverse all segments
zstyle ':prompt-theme:newt:*:*:*' direction reverse
# Or just one
zstyle ':prompt-theme:newt:*:history:*' direction reverse

Defining a custom separator

To add your own separator, run prompt_newt_add_separator after loading this theme:

prompt_newt_add_separator nerd-trapezoid \
            $'\ue0d2' $'\ue0d2' $'\ue0d4' $'\ue0d4'

The arguments are name, left-to-right thick, left-to-right thin, right-to-left thick, and right-to-left thin. Additionally, the options --wide, --wide-ltr, and --wide-rtl may be given. Each takes a specification like 1:1 or 0:1. The left-hand number is 1 if the padding space from the preceding segment should be removed. The right-hand number is 1 if an extra padding space should be added after the separator. Most wide separators will want both set to 1.

Truecolor support

If your terminal supports Truecolor escape sequences, then you can use them anywhere a color can be specified. That is, either in a zstyle to set a color, or directly in a %K{…​} or %F{…​} escape in the prompt text. The color must be given as rrr;ggg;bbb. For example:

zstyle ':vcs_info:*' stagedstr '%F{250;128;114}+'
zstyle ':prompt-theme:newt:*:vi_mode:search' bg '199;21;133'

Miscellaneous settings

# Remove spacing around segments
zstyle ':prompt-theme:newt:*' compact true
# Tell newt what colors the terminal uses; background is used to
# draw the arrow head of the segment separator when the default
# background (bg '') is used.
#
# Also used for the default looks's primary segment colors.
zstyle ':prompt-theme:newt' terminal-background 236
zstyle ':prompt-theme:newt' terminal-foreground 254
# Keep only the latest the right-side prompt
setopt TRANSIENT_RPROMPT

Bugs

Please open an issue if you run into any bugs or missing features.

About

Fat & fast ZSH theme – beautiful inside and out, styled segments done right

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages