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.
Newt comes with these pre-defined looks: default, denver, forest, meadow, mono.
Use a look with prompt newt meadow
.
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.
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
The list of colors is
-
Primary background
-
Primary foreground
-
Secondary background
-
Secondary foreground
-
Alert background
-
Alert foreground
-
Red
-
Green
-
Yellow
-
Blue
-
Magenta
-
Cyan
-
Black
-
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
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
.
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]
.
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
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'
User name is hidden unless it is different from $DEFAULT_USER
.
Host name is hidden unless $SSH_CLIENT
is set.
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 '%/'
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'
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.
This might be used to disable the right side prompt, for example:
zstyle ':prompt-theme:newt:*' right none
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
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' # ◆
Shows the current time. The format can be set with
zstyle ':prompt-theme:newt:*:time' default '%*' # HH:MM:SS
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:*'
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
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
.
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
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.
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'
# 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
Please open an issue if you run into any bugs or missing features.