mirror of
https://github.com/starship/starship.git
synced 2026-06-23 02:05:51 +07:00
feat(directory): Add directory substitutions (#1183)
Adds an option to provide a table of strings to substitute in the directory string. Fixes #1065. Co-authored-by: Radu Butoi <butoi@google.com>
This commit is contained in:
@@ -24,6 +24,50 @@ fn home_directory() -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn substituted_truncated_path() -> io::Result<()> {
|
||||
let output = common::render_module("directory")
|
||||
.arg("--path=/some/long/network/path/workspace/a/b/c/dev")
|
||||
.use_config(toml::toml! {
|
||||
[directory]
|
||||
truncation_length = 4
|
||||
[directory.substitutions]
|
||||
"/some/long/network/path" = "/some/net"
|
||||
"a/b/c" = "d"
|
||||
})
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = format!("in {} ", Color::Cyan.bold().paint("net/workspace/d/dev"));
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strange_substitution() -> io::Result<()> {
|
||||
let strange_sub = "/\\/;,!";
|
||||
let output = common::render_module("directory")
|
||||
.arg("--path=/foo/bar/regular/path")
|
||||
.use_config(toml::toml! {
|
||||
[directory]
|
||||
truncation_length = 0
|
||||
fish_style_pwd_dir_length = 2 // Overridden by substitutions
|
||||
[directory.substitutions]
|
||||
"regular" = strange_sub
|
||||
})
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = format!(
|
||||
"in {} ",
|
||||
Color::Cyan
|
||||
.bold()
|
||||
.paint(format!("/foo/bar/{}/path", strange_sub))
|
||||
);
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn directory_in_home() -> io::Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user