mirror of
https://github.com/starship/starship.git
synced 2024-11-23 08:43:16 +01:00
feat: Use tilde for home_directory when under version control (#439)
This commit is contained in:
parent
8c56729d26
commit
63a45d01f9
@ -8,7 +8,8 @@ use super::{Context, Module};
|
||||
///
|
||||
/// Will perform path contraction and truncation.
|
||||
/// **Contraction**
|
||||
/// - Paths beginning with the home directory will be contracted to `~`
|
||||
/// - Paths beginning with the home directory or with a git repo right
|
||||
/// inside the home directory will be contracted to `~`
|
||||
/// - Paths containing a git repo will contract to begin at the repo root
|
||||
///
|
||||
/// **Truncation**
|
||||
@ -57,7 +58,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
let repo = &context.get_repo().ok()?;
|
||||
|
||||
let dir_string = match &repo.root {
|
||||
Some(repo_root) if truncate_to_repo => {
|
||||
Some(repo_root) if truncate_to_repo && (repo_root != &home_dir) => {
|
||||
let repo_folder_name = repo_root.file_name().unwrap().to_str().unwrap();
|
||||
|
||||
// Contract the path to the git repo root
|
||||
|
@ -419,6 +419,37 @@ fn directory_in_git_repo_truncate_to_repo_true() -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
fn git_repo_in_home_directory_truncate_to_repo_true() -> io::Result<()> {
|
||||
let tmp_dir = TempDir::new_in(dirs::home_dir().unwrap())?;
|
||||
let dir = tmp_dir.path().join("src/meters/fuel-gauge");
|
||||
fs::create_dir_all(&dir)?;
|
||||
Repository::init(&tmp_dir).unwrap();
|
||||
|
||||
let output = common::render_module("directory")
|
||||
.use_config(toml::toml! {
|
||||
[directory]
|
||||
// `truncate_to_repo = true` should attmpt to display the truncated path
|
||||
truncate_to_repo = true
|
||||
truncation_length = 5
|
||||
})
|
||||
// Set home directory to the temp repository
|
||||
.env("HOME", tmp_dir.path())
|
||||
.arg("--path")
|
||||
.arg(dir)
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = format!(
|
||||
"in {} ",
|
||||
Color::Cyan.bold().paint("~/src/meters/fuel-gauge")
|
||||
);
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn use_logical_and_physical_paths() -> io::Result<()> {
|
||||
|
Loading…
Reference in New Issue
Block a user