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:
Radu Butoi
2020-05-31 13:32:35 -04:00
committed by GitHub
parent 329b3c791d
commit ab1c3d1c54
4 changed files with 92 additions and 4 deletions
+44
View File
@@ -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<()> {