mirror of
https://github.com/starship/starship.git
synced 2026-06-23 02:05:51 +07:00
feat: Add ability to use an alternate directory truncation style (#239)
* Add ability to use an alternate directory truncation style
This commit is contained in:
committed by
Matan Kushner
parent
81ea165cec
commit
e034253a5e
@@ -61,6 +61,28 @@ fn truncated_directory_in_home() -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn fish_directory_in_home() -> io::Result<()> {
|
||||
let dir = home_dir().unwrap().join("starship/engine/schematics");
|
||||
fs::create_dir_all(&dir)?;
|
||||
|
||||
let output = common::render_module("directory")
|
||||
.use_config(toml::toml! {
|
||||
[directory]
|
||||
truncation_length = 1
|
||||
fish_style_pwd_dir_length = 2
|
||||
})
|
||||
.arg("--path")
|
||||
.arg(dir)
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = format!("in {} ", Color::Cyan.bold().paint("~/st/en/schematics"));
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn root_directory() -> io::Result<()> {
|
||||
let output = common::render_module("directory")
|
||||
@@ -141,6 +163,31 @@ fn truncated_directory_config_large() -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn fish_style_directory_config_large() -> io::Result<()> {
|
||||
let dir = Path::new("/tmp/starship/thrusters/rocket");
|
||||
fs::create_dir_all(&dir)?;
|
||||
|
||||
let output = common::render_module("directory")
|
||||
.use_config(toml::toml! {
|
||||
[directory]
|
||||
truncation_length = 1
|
||||
fish_style_pwd_dir_length = 100
|
||||
})
|
||||
.arg("--path")
|
||||
.arg(dir)
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = format!(
|
||||
"in {} ",
|
||||
Color::Cyan.bold().paint("/tmp/starship/thrusters/rocket")
|
||||
);
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn truncated_directory_config_small() -> io::Result<()> {
|
||||
@@ -162,6 +209,28 @@ fn truncated_directory_config_small() -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn fish_directory_config_small() -> io::Result<()> {
|
||||
let dir = Path::new("/tmp/starship/thrusters/rocket");
|
||||
fs::create_dir_all(&dir)?;
|
||||
|
||||
let output = common::render_module("directory")
|
||||
.use_config(toml::toml! {
|
||||
[directory]
|
||||
truncation_length = 2
|
||||
fish_style_pwd_dir_length = 1
|
||||
})
|
||||
.arg("--path")
|
||||
.arg(dir)
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = format!("in {} ", Color::Cyan.bold().paint("/t/s/thrusters/rocket"));
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn git_repo_root() -> io::Result<()> {
|
||||
@@ -255,6 +324,70 @@ fn directory_in_git_repo_truncate_to_repo_false() -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn fish_path_directory_in_git_repo_truncate_to_repo_false() -> io::Result<()> {
|
||||
let tmp_dir = TempDir::new_in(dirs::home_dir().unwrap())?;
|
||||
let repo_dir = tmp_dir.path().join("above-repo").join("rocket-controls");
|
||||
let dir = repo_dir.join("src/meters/fuel-gauge");
|
||||
fs::create_dir_all(&dir)?;
|
||||
Repository::init(&repo_dir).unwrap();
|
||||
|
||||
let output = common::render_module("directory")
|
||||
.use_config(toml::toml! {
|
||||
[directory]
|
||||
// Don't truncate the path at all.
|
||||
truncation_length = 5
|
||||
truncate_to_repo = false
|
||||
fish_style_pwd_dir_length = 1
|
||||
})
|
||||
.arg("--path")
|
||||
.arg(dir)
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = format!(
|
||||
"in {} ",
|
||||
Color::Cyan
|
||||
.bold()
|
||||
.paint("~/.t/above-repo/rocket-controls/src/meters/fuel-gauge")
|
||||
);
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn fish_path_directory_in_git_repo_truncate_to_repo_true() -> io::Result<()> {
|
||||
let tmp_dir = TempDir::new_in(dirs::home_dir().unwrap())?;
|
||||
let repo_dir = tmp_dir.path().join("above-repo").join("rocket-controls");
|
||||
let dir = repo_dir.join("src/meters/fuel-gauge");
|
||||
fs::create_dir_all(&dir)?;
|
||||
Repository::init(&repo_dir).unwrap();
|
||||
|
||||
let output = common::render_module("directory")
|
||||
.use_config(toml::toml! {
|
||||
[directory]
|
||||
// `truncate_to_repo = true` should display the truncated path
|
||||
truncation_length = 5
|
||||
truncate_to_repo = true
|
||||
fish_style_pwd_dir_length = 1
|
||||
})
|
||||
.arg("--path")
|
||||
.arg(dir)
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = format!(
|
||||
"in {} ",
|
||||
Color::Cyan
|
||||
.bold()
|
||||
.paint("~/.t/a/rocket-controls/src/meters/fuel-gauge")
|
||||
);
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn directory_in_git_repo_truncate_to_repo_true() -> io::Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user