CLI to generate a shell prompt.
The default prompt configuration uses symbols from Nerd Fonts and expects one of them to be installed.
Only zsh is supported. Please open an issue if support for another shell is desired.
cargo install eliprompt
Make sure eliprompt
is in your PATH
and add the following to .zshrc
:
eval "$(eliprompt install --shell zsh)"
The prompt is made of blocks. Each block contains the text to display as well as the style (foreground and background colors).
The configuration is stored in ~/.config/eliprompt/config.json
. It consists of a JSON object
of type Config
. Config
and the other JSON types involved are detailed below.
JSON object with a single field named after its type among:
Elapsed
ExitCode
GitHead
GitPath
Hostname
WorkingDirectory
Username
Newline
Space
Text
ExitStatusSymbol
Or
Sequence
Separated
Styled
String with a CSS color name (e.g. "red"
) or a CSS sRGB color (e.g. "#ff1000"
).
Root configuration object. JSON object with the following fields:
-
prompt
[optional]:- Type:
BlockProducer
- The prompt definition.
- Type:
-
alternative_prompt
[optional]:- Type:
BlockProducer
ornull
- Alternative prompt definition to use when
$TERM
islinux
or the environment variableELIPROMPT_ALTERNATIVE_PROMPT
is defined.
- Type:
-
timeout
[optional]:- Type:
Duration
- Maximum time allocated to build the prompt. If it takes longer, a default prompt will be shown.
- Type:
String containing a duration with unit, e.g. "3s"
for 3 seconds.
Shows the duration of the previous command. JSON object with the following fields:
-
style
[optional]:- Type:
Style
- Type:
-
prefix
[optional]:- Type:
String
- Text to display before the duration.
- Type:
-
threshold
[optional]:- Type:
Duration
- The duration of a command is displayed if and only if it took longer than the threshold.
- Type:
Shows the exit code of the previous command if it was not zero. JSON object with the following fields:
-
style
[optional]:- Type:
Style
- Type:
-
prefix
[optional]:- Type:
String
- Text to display before the exit code.
- Type:
-
style
[optional]:- Type:
Style
- Style to use when the exit status is zero.
- Type:
-
error_style
[optional]:- Type:
Style
- Style to use when the exit status is not zero.
- Type:
-
contents
:- Type:
String
- Type:
Shows the current git branch. JSON object with the following fields:
-
style
[optional]:- Type:
Style
- Type:
-
prefix
[optional]:- Type:
String
- Text to display before the git branch.
- Type:
If the current working directory is in a git repository, it is shown relative to the root of the repository. JSON object with the following fields:
-
style
[optional]:- Type:
Style
- Type:
-
prefix
[optional]:- Type:
String
- Text to display before the path.
- Type:
-
style
[optional]:- Type:
Style
- Type:
-
prefix
[optional]:- Type:
String
- Text to display before the hostname.
- Type:
Adds a newline character.
List of BlockProducer
items. Returns blocks from the first producer that
produces at least one block.
-
separator_style
[optional]:- Type:
Style
- Style to use for the separator.
- Type:
-
separator
[optional]:- Type:
String
- Separator to insert between groups of blocks generated by the producers.
- Type:
-
producers
:- Type: List of
BlockProducer
items
- Type: List of
List of BlockProducer
items. Returns blocks from all producers.
Adds a space character.
JSON object with the following fields:
-
style
[optional]:- Type:
Style
- Default style for items that do not specify their foreground or background color.
- Type:
-
producer
:- Type:
BlockProducer
- Generator whose blocks the default style is applied to.
- Type:
-
style
[optional]:- Type:
Style
- Type:
-
contents
:- Type:
String
- Type:
-
style
[optional]:- Type:
Style
- Type:
-
prefix
[optional]:- Type:
String
- Text to display before the username.
- Type:
Shows the current working directory. JSON object with the following fields:
-
style
[optional]:- Type:
Style
- Type:
-
home_as_tilde
[optional]:- Type:
bool
- Indicates if the home directory should be displayed as a tilde.
- Type:
-
prefix
[optional]:- Type:
String
- Text to display before the working directory.
- Type:
{
"prompt": {
"Styled": {
"style": {
"foreground": "teal",
"background": "black"
},
"producer": {
"Sequence": [
{
"Separated": {
"separator_style": {},
"separator": " | ",
"producers": [
{
"Separated": {
"separator_style": {},
"separator": "@",
"producers": [
{
"Username": {
"style": {},
"prefix": ""
}
},
{
"Hostname": {
"style": {},
"prefix": ""
}
}
]
}
},
{
"Or": [
{
"GitPath": {
"style": {},
"prefix": ""
}
},
{
"WorkingDirectory": {
"style": {},
"home_as_tilde": true,
"prefix": ""
}
}
]
},
{
"GitHead": {
"style": {},
"prefix": ""
}
},
{
"Elapsed": {
"style": {},
"prefix": "祥",
"threshold": "2s"
}
},
{
"ExitCode": {
"style": {
"foreground": "crimson"
},
"prefix": ""
}
}
]
}
},
{
"Newline": null
},
{
"ExitStatusSymbol": {
"style": {
"foreground": "dodgerblue"
},
"error_style": {
"foreground": "crimson"
},
"contents": "→"
}
},
{
"Space": null
}
]
}
}
},
"alternative_prompt": {
"Styled": {
"style": {
"foreground": "teal"
},
"producer": {
"Sequence": [
{
"Separated": {
"separator_style": {},
"separator": " | ",
"producers": [
{
"Separated": {
"separator_style": {},
"separator": "@",
"producers": [
{
"Username": {
"style": {},
"prefix": ""
}
},
{
"Hostname": {
"style": {},
"prefix": ""
}
}
]
}
},
{
"WorkingDirectory": {
"style": {},
"home_as_tilde": true,
"prefix": ""
}
},
{
"Elapsed": {
"style": {},
"prefix": "",
"threshold": "2s"
}
},
{
"ExitCode": {
"style": {
"foreground": "crimson"
},
"prefix": ""
}
}
]
}
},
{
"Newline": null
},
{
"ExitStatusSymbol": {
"style": {
"foreground": "dodgerblue"
},
"error_style": {
"foreground": "crimson"
},
"contents": "→"
}
},
{
"Space": null
}
]
}
}
},
"timeout": "1s"
}
All contributions shall be licensed under the MIT license.
starship provides more blocks and supports more shells.