summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock10
-rw-r--r--Cargo.toml1
-rw-r--r--docs/config/README.md1412
-rw-r--r--src/config.rs130
-rw-r--r--src/configs/aws.rs40
-rw-r--r--src/configs/battery.rs31
-rw-r--r--src/configs/character.rs23
-rw-r--r--src/configs/cmd_duration.rs9
-rw-r--r--src/configs/conda.rs21
-rw-r--r--src/configs/crystal.rs13
-rw-r--r--src/configs/custom.rs17
-rw-r--r--src/configs/directory.rs9
-rw-r--r--src/configs/docker_context.rs15
-rw-r--r--src/configs/dotnet.rs49
-rw-r--r--src/configs/elixir.rs17
-rw-r--r--src/configs/elm.rs15
-rw-r--r--src/configs/env_var.rs17
-rw-r--r--src/configs/erlang.rs15
-rw-r--r--src/configs/git_branch.rs15
-rw-r--r--src/configs/git_commit.rs15
-rw-r--r--src/configs/git_state.rs39
-rw-r--r--src/configs/git_status.rs75
-rw-r--r--src/configs/go.rs15
-rw-r--r--src/configs/hg_branch.rs15
-rw-r--r--src/configs/hostname.rs11
-rw-r--r--src/configs/java.rs13
-rw-r--r--src/configs/jobs.rs13
-rw-r--r--src/configs/julia.rs15
-rw-r--r--src/configs/kubernetes.rs17
-rw-r--r--src/configs/memory_usage.rs23
-rw-r--r--src/configs/nim.rs15
-rw-r--r--src/configs/nix_shell.rs23
-rw-r--r--src/configs/nodejs.rs13
-rw-r--r--src/configs/ocaml.rs15
-rw-r--r--src/configs/package.rs13
-rw-r--r--src/configs/php.rs13
-rw-r--r--src/configs/purescript.rs15
-rw-r--r--src/configs/python.rs17
-rw-r--r--src/configs/ruby.rs13
-rw-r--r--src/configs/rust.rs15
-rw-r--r--src/configs/singularity.rs19
-rw-r--r--src/configs/starship_root.rs108
-rw-r--r--src/configs/terraform.rs19
-rw-r--r--src/configs/time.rs11
-rw-r--r--src/configs/username.rs15
-rw-r--r--src/configs/zig.rs15
-rw-r--r--src/formatter/mod.rs1
-rw-r--r--src/formatter/model.rs86
-rw-r--r--src/formatter/parser.rs71
-rw-r--r--src/formatter/spec.pest51
-rw-r--r--src/formatter/string_formatter.rs616
-rw-r--r--src/module.rs130
-rw-r--r--src/modules/aws.rs98
-rw-r--r--src/modules/battery.rs92
-rw-r--r--src/modules/character.rs55
-rw-r--r--src/modules/cmd_duration.rs37
-rw-r--r--src/modules/conda.rs34
-rw-r--r--src/modules/crystal.rs31
-rw-r--r--src/modules/custom.rs56
-rw-r--r--src/modules/directory.rs55
-rw-r--r--src/modules/docker_context.rs47
-rw-r--r--src/modules/dotnet.rs91
-rw-r--r--src/modules/elixir.rs44
-rw-r--r--src/modules/elm.rs32
-rw-r--r--src/modules/env_var.rs38
-rw-r--r--src/modules/erlang.rs30
-rw-r--r--src/modules/git_branch.rs64
-rw-r--r--src/modules/git_commit.rs44
-rw-r--r--src/modules/git_state.rs171
-rw-r--r--src/modules/git_status.rs475
-rw-r--r--src/modules/golang.rs36
-rw-r--r--src/modules/hg_branch.rs36
-rw-r--r--src/modules/hostname.rs27
-rw-r--r--src/modules/java.rs30
-rw-r--r--src/modules/jobs.rs44
-rw-r--r--src/modules/julia.rs37
-rw-r--r--src/modules/kubernetes.rs56
-rw-r--r--src/modules/line_break.rs11
-rw-r--r--src/modules/memory_usage.rs87
-rw-r--r--src/modules/mod.rs2
-rw-r--r--src/modules/nim.rs39
-rw-r--r--src/modules/nix_shell.rs58
-rw-r--r--src/modules/nodejs.rs37
-rw-r--r--src/modules/ocaml.rs36
-rw-r--r--src/modules/package.rs46
-rw-r--r--src/modules/php.rs34
-rw-r--r--src/modules/purescript.rs31
-rw-r--r--src/modules/python.rs51
-rw-r--r--src/modules/ruby.rs38
-rw-r--r--src/modules/rust.rs43
-rw-r--r--src/modules/singularity.rs40
-rw-r--r--src/modules/terraform.rs44
-rw-r--r--src/modules/time.rs40
-rw-r--r--src/modules/username.rs36
-rw-r--r--src/modules/zig.rs27
-rw-r--r--src/print.rs198
-rw-r--r--tests/testsuite/aws.rs32
-rw-r--r--tests/testsuite/character.rs49
-rw-r--r--tests/testsuite/cmd_duration.rs4
-rw-r--r--tests/testsuite/common.rs2
-rw-r--r--tests/testsuite/conda.rs15
-rw-r--r--tests/testsuite/configuration.rs21
-rwxr-xr-xtests/testsuite/directory.rs87
-rw-r--r--tests/testsuite/dotnet.rs53
-rw-r--r--tests/testsuite/env_var.rs6
-rw-r--r--tests/testsuite/git_branch.rs84
-rw-r--r--tests/testsuite/git_commit.rs15
-rw-r--r--tests/testsuite/git_state.rs67
-rw-r--r--tests/testsuite/git_status.rs113
-rw-r--r--tests/testsuite/hostname.rs42
-rw-r--r--tests/testsuite/line_break.rs13
-rw-r--r--tests/testsuite/main.rs1
-rw-r--r--tests/testsuite/nix_shell.rs20
-rw-r--r--tests/testsuite/terraform.rs6
-rw-r--r--tests/testsuite/time.rs3
115 files changed, 4142 insertions, 2553 deletions
diff --git a/Cargo.lock b/Cargo.lock
index d9ad9d52a..17026fa67 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -868,6 +868,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]]
+name = "quick-xml"
+version = "0.18.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3cc440ee4802a86e357165021e3e255a9143724da31db1e2ea540214c96a0f82"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
name = "quote"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1151,6 +1160,7 @@ dependencies = [
"pest",
"pest_derive",
"pretty_env_logger",
+ "quick-xml",
"rayon",
"regex",
"remove_dir_all",
diff --git a/Cargo.toml b/Cargo.toml
index 111675f2f..b4dbf110d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -59,6 +59,7 @@ open = "1.4.0"
unicode-width = "0.1.8"
textwrap = "0.12.1"
term_size = "0.3.2"
+quick-xml = "0.18.1"
# Optional/http:
attohttpc = { version = "0.15.0", optional = true, default-features = false, features = ["tls", "form"] }
diff --git a/docs/config/README.md b/docs/config/README.md
index 01750a601..7dd339525 100644
--- a/docs/config/README.md
+++ b/docs/config/README.md
@@ -20,8 +20,8 @@ All configuration for starship is done in this [TOML](https://github.com/toml-la
add_newline = false
# Replace the "❯" symbol in the prompt with "➜"
-[character] # The name of the module we are configuring is "character"
-symbol = "➜" # The "symbol" segment is being set to "➜"
+[character] # The name of the module we are configuring is "character"
+success_symbol = "[➜](bold green)" # The "success_symbol" segment is being set to "➜" with the color "bold green"
# Disable the package module, hiding it from the prompt completely
[package]
@@ -29,11 +29,13 @@ disabled = true
```
You can change default `starship.toml` file location with `STARSHIP_CONFIG` environment variable:
+
```sh
export STARSHIP_CONFIG=~/.starship
```
Equivalently in PowerShell (Windows) would be adding this line to your `$PROFILE`:
+
```ps1
$ENV:STARSHIP_CONFIG = "$HOME\.starship"
```
@@ -42,17 +44,43 @@ $ENV:STARSHIP_CONFIG = "$HOME\.starship"
**Module**: A component in the prompt giving information based on contextual information from your OS. For example, the "nodejs" module shows the version of NodeJS that is currently installed on your computer, if your current directory is a NodeJS project.
-**Segment**: Smaller sub-components that compose a module. For example, the "symbol" segment in the "nodejs" module contains the character that is shown before the version number (⬢ by default).
+**Variable**: Smaller sub-components that contains information provided by the module. For example, the "version" variable in the "nodejs" module contains the current version of NodeJS.
-Here is the representation of the node module. In the following example, "symbol" and "version"
-are segments within it. Every module also has a prefix and suffix that are the default terminal color.
+By convention, most modules have a prefix of default terminal color (e.g. `via ` in "nodejs") and an empty space as a suffix.
-```
-[prefix] [symbol] [version] [suffix]
- "via " "⬢" "v10.4.1" ""
-```
+### Format Strings
+
+Format strings are the format that a module prints all its variables with.
+Most modules have an entry called `format` that configures the display format of the module.
+You can use texts, variables and text groups in a format string.
+
+#### Variable
+
+A variable contains a `$` symbol followed by the name of the variable.
+The name of a variable only contains letters, numbers and `_`.
+
+For example:
+
+- `$version` is a format string with a variable named `version`.
+- `$git_branch$git_commit` is a format string with two variables named `git_branch` and `git_commit`.
+- `$git_branch $git_commit` has the two variables separated with a space.
+
+#### Text Group
+
+A text group is made up of two different parts.
+
+The first part, which is enclosed in a `[]`, is a [format string](#format-strings).
+You can add texts, variables, or even nested text groups in it.
+
+In the second part, which is enclosed in a `()`, is a [style string](#style-strings). This can be used style the first part.
-### Style Strings
+For example:
+
+- `[on](red bold)` will print a string `on` with bold text colored red.
+- `[⬢ $version](bold green)` will print a symbol `⬢ ` followed by the content of variable `version`, with bold text colored green.
+- `[a [b](red) c](green)` will print `a b c` with `b` red, and `a` and `c` green.
+
+#### Style Strings
Most modules in starship allow you to configure their display styles. This is done with an entry (usually called `style`) which is a string specifying the configuration. Here are some examples of style strings along with what they do. For details on the full syntax, consult the [advanced config guide](/advanced-config/).
@@ -65,17 +93,60 @@ Most modules in starship allow you to configure their display styles. This is do
Note that what styling looks like will be controlled by your terminal emulator. For example, some terminal emulators will brighten the colors instead of bolding text, and some color themes use the same values for the normal and bright colors. Also, to get italic text, your terminal must support italics.
+#### Conditional Format Strings
+
+A conditional format string wrapped in `(` and `)` will not render if all variables inside are empty.
+
+For example:
+
+- `(@$region)` will show nothing if the variable `region` is `None`, otherwise `@` followed by the value of region.
+- `(some text)` will always show nothing since there are no variables wrapped in the braces.
+- When `$all` is a shortcut for `\[$a$b\] `, `($all)` will show nothing only if `$a` and `$b` are both `None`.
+ This works the same as `(\[$a$b\] )`.
+
+#### Escapable characters
+
+The following symbols have special usage in a format string.
+If you want to print the following symbols, you have to escape them with a backslash (`\`).
+
+- $
+- \\
+- [
+- ]
+- (
+- )
+
+Note that `toml` has [its own escape syntax](https://github.com/toml-lang/toml#user-content-string).
+It is recommended to use a literal string (`''`) in your config.
+If you want to use a basic string (`""`), pay attention to escape the backslash `\`.
+
+For example, when you want to print a `$` symbol on a new line, the following configs for `format` are equivalent:
+
+```toml
+# with basic string
+format = "\n\\$"
+
+# with multiline basic string
+format = """
+
+\\$"""
+
+# with literal string
+format = '''
+
+\$'''
+```
+
## Prompt