mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-16 10:05:13 +00:00
feat: Add configuration for the git_status
prefix and suffix (#367)
This commit is contained in:
parent
8014e9276e
commit
7a98ec1d8e
@ -326,21 +326,23 @@ current directory.
|
|||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
| Variable | Default | Description |
|
| Variable | Default | Description |
|
||||||
| ----------------- | ------------ | ------------------------------------------------------- |
|
| ------------------------ | ------------ | ------------------------------------------------------- |
|
||||||
| `conflicted` | `"="` | This branch has merge conflicts. |
|
| `conflicted` | `"="` | This branch has merge conflicts. |
|
||||||
| `ahead` | `"⇡"` | This branch is ahead of the branch being tracked. |
|
| `ahead` | `"⇡"` | This branch is ahead of the branch being tracked. |
|
||||||
| `behind` | `"⇣"` | This branch is behind of the branch being tracked. |
|
| `behind` | `"⇣"` | This branch is behind of the branch being tracked. |
|
||||||
| `diverged` | `"⇕"` | This branch has diverged from the branch being tracked. |
|
| `diverged` | `"⇕"` | This branch has diverged from the branch being tracked. |
|
||||||
| `untracked` | `"?"` | There are untracked files in the working directory. |
|
| `untracked` | `"?"` | There are untracked files in the working directory. |
|
||||||
| `stashed` | `"$"` | A stash exists for the local repository. |
|
| `stashed` | `"$"` | A stash exists for the local repository. |
|
||||||
| `modified` | `"!"` | There are file modifications in the working directory. |
|
| `modified` | `"!"` | There are file modifications in the working directory. |
|
||||||
| `staged` | `"+"` | A new file has been added to the staging area. |
|
| `staged` | `"+"` | A new file has been added to the staging area. |
|
||||||
| `renamed` | `"»"` | A renamed file has been added to the staging area. |
|
| `renamed` | `"»"` | A renamed file has been added to the staging area. |
|
||||||
| `deleted` | `"✘"` | A file's deletion has been added to the staging area. |
|
| `deleted` | `"✘"` | A file's deletion has been added to the staging area. |
|
||||||
| `show_sync_count` | `false` | Show ahead/behind count of the branch being tracked. |
|
| `show_sync_count` | `false` | Show ahead/behind count of the branch being tracked. |
|
||||||
| `style` | `"bold red"` | The style for the module. |
|
| `prefix` | `[` | Prefix to display immediately before git status. |
|
||||||
| `disabled` | `false` | Disables the `git_status` module. |
|
| `suffix` | `]` | Suffix to display immediately after git status. |
|
||||||
|
| `style` | `"bold red"` | The style for the module. |
|
||||||
|
| `disabled` | `false` | Disables the `git_status` module. |
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
@ -29,6 +29,8 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
const GIT_STATUS_ADDED: &str = "+";
|
const GIT_STATUS_ADDED: &str = "+";
|
||||||
const GIT_STATUS_RENAMED: &str = "»";
|
const GIT_STATUS_RENAMED: &str = "»";
|
||||||
const GIT_STATUS_DELETED: &str = "✘";
|
const GIT_STATUS_DELETED: &str = "✘";
|
||||||
|
const PREFIX: &str = "[";
|
||||||
|
const SUFFIX: &str = "] ";
|
||||||
|
|
||||||
let repo = context.get_repo().ok()?;
|
let repo = context.get_repo().ok()?;
|
||||||
let branch_name = repo.branch.as_ref()?;
|
let branch_name = repo.branch.as_ref()?;
|
||||||
@ -40,9 +42,23 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
let module_style = module
|
let module_style = module
|
||||||
.config_value_style("style")
|
.config_value_style("style")
|
||||||
.unwrap_or_else(|| Color::Red.bold());
|
.unwrap_or_else(|| Color::Red.bold());
|
||||||
|
let start_symbol = module
|
||||||
|
.config_value_str("prefix")
|
||||||
|
.unwrap_or(PREFIX)
|
||||||
|
.to_owned();
|
||||||
|
let end_symbol = module
|
||||||
|
.config_value_str("suffix")
|
||||||
|
.unwrap_or(SUFFIX)
|
||||||
|
.to_owned();
|
||||||
|
|
||||||
module.get_prefix().set_value("[").set_style(module_style);
|
module
|
||||||
module.get_suffix().set_value("] ").set_style(module_style);
|
.get_prefix()
|
||||||
|
.set_value(start_symbol)
|
||||||
|
.set_style(module_style);
|
||||||
|
module
|
||||||
|
.get_suffix()
|
||||||
|
.set_value(end_symbol)
|
||||||
|
.set_style(module_style);
|
||||||
module.set_style(module_style);
|
module.set_style(module_style);
|
||||||
|
|
||||||
let ahead_behind = get_ahead_behind(&repository, branch_name);
|
let ahead_behind = get_ahead_behind(&repository, branch_name);
|
||||||
|
@ -370,3 +370,45 @@ fn shows_deleted_file() -> io::Result<()> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn prefix() -> io::Result<()> {
|
||||||
|
let repo_dir = common::create_fixture_repo()?;
|
||||||
|
File::create(repo_dir.join("prefix"))?;
|
||||||
|
let output = common::render_module("git_status")
|
||||||
|
.arg("--path")
|
||||||
|
.arg(repo_dir)
|
||||||
|
.env_clear()
|
||||||
|
.use_config(toml::toml! {
|
||||||
|
[git_status]
|
||||||
|
prefix = "("
|
||||||
|
style = ""
|
||||||
|
})
|
||||||
|
.output()?;
|
||||||
|
let actual = String::from_utf8(output.stdout).unwrap();
|
||||||
|
let expected = "(";
|
||||||
|
assert!(actual.starts_with(&expected));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn suffix() -> io::Result<()> {
|
||||||
|
let repo_dir = common::create_fixture_repo()?;
|
||||||
|
File::create(repo_dir.join("suffix"))?;
|
||||||
|
let output = common::render_module("git_status")
|
||||||
|
.arg("--path")
|
||||||
|
.arg(repo_dir)
|
||||||
|
.env_clear()
|
||||||
|
.use_config(toml::toml! {
|
||||||
|
[git_status]
|
||||||
|
suffix = ")"
|
||||||
|
style = ""
|
||||||
|
})
|
||||||
|
.output()?;
|
||||||
|
let actual = String::from_utf8(output.stdout).unwrap();
|
||||||
|
let expected = ")";
|
||||||
|
assert!(actual.ends_with(&expected));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user