summaryrefslogtreecommitdiffstats
path: root/src/modules
diff options
context:
space:
mode:
authorNeil Kistner <neil.kistner@gmail.com>2019-09-20 09:37:55 -0500
committerMatan Kushner <hello@matchai.me>2019-09-20 10:37:55 -0400
commitcd892ebb60231cce84bd5c2cfed280571026ad9d (patch)
treeb89c32a6f8dd2e0532dc408337d5d2639cbe1192 /src/modules
parentac151f0ae8360a7318d22ff72476c92a445ce6ea (diff)
fix: fish_pwd option handles repeated directories properly (#399)
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/directory.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/modules/directory.rs b/src/modules/directory.rs
index 096b07646..fa6b5c7a3 100644
--- a/src/modules/directory.rs
+++ b/src/modules/directory.rs
@@ -145,7 +145,7 @@ fn truncate(dir_string: String, length: usize) -> String {
/// Contracted Path: `in_a/repo/but_nested`
/// With Fish Style: `/s/P/n/in_a/repo/but_nested`
fn to_fish_style(pwd_dir_length: usize, dir_string: String, truncated_dir_string: &str) -> String {
- let replaced_dir_string = dir_string.replace(truncated_dir_string, "");
+ let replaced_dir_string = dir_string.trim_end_matches(truncated_dir_string).to_owned();
let components = replaced_dir_string.split('/').collect::<Vec<&str>>();
if components.is_empty() {
@@ -283,4 +283,11 @@ mod tests {
let output = to_fish_style(2, path.to_string(), "repo/but_nested");
assert_eq!(output, "/ab/Pa/no/in/");
}
+
+ #[test]
+ fn fish_style_with_duplicate_directories() {
+ let path = "~/starship/tmp/C++/C++/C++";
+ let output = to_fish_style(1, path.to_string(), "C++");
+ assert_eq!(output, "~/s/t/C/C/");
+ }
}