aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2018-02-24 01:03:52 -0500
committerJesse Luehrs <doy@tozt.net>2018-02-24 01:03:52 -0500
commit8d6fea3555989bfe3a46e48c98405eb5e441759d (patch)
tree38ffc261356e20f6b22cec20edda4f55cc1e8c67
parent124b7fdc0571c53926e99e0c8b256e1ec747c6b2 (diff)
downloadfancy-prompt-8d6fea3555989bfe3a46e48c98405eb5e441759d.tar.gz
fancy-prompt-8d6fea3555989bfe3a46e48c98405eb5e441759d.zip
fix up the compress functions a bit
-rw-r--r--src/prompt.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/prompt.rs b/src/prompt.rs
index 4a574a4..5ebdf48 100644
--- a/src/prompt.rs
+++ b/src/prompt.rs
@@ -355,7 +355,7 @@ fn compress_path<T, U>(
if path_str.len() > len {
path_str = String::from(&path_str[..len - 6])
+ "..."
- + &path_str[len - 3..len]
+ + &path_str[path_str.len() - 3..]
}
path_str
@@ -368,21 +368,21 @@ fn compress_path<T, U>(
fn compress_vcs(vcs: &str, len: usize) -> String {
if vcs.len() > len {
let vcs_parts_re = regex::Regex::new(
- r"^([^:]+):.*:([^:])$"
+ r"^([^:]+):.*?(?::([^:]+))?$"
).unwrap();
vcs_parts_re
.captures(vcs)
.map(|cap| {
let prefix_len = cap.get(1)
- .map(|mat| mat.end() - mat.start())
+ .map(|mat| mat.end() - mat.start() + 1)
.unwrap_or(0);
let suffix_len = cap.get(2)
- .map(|mat| mat.end() - mat.start())
+ .map(|mat| mat.end() - mat.start() + 1)
.unwrap_or(0);
- let branch_len = len - prefix_len - suffix_len - 2;
+ let branch_len = len - prefix_len - suffix_len;
let branch_re = regex::Regex::new(
&format!(
- r"(:[^:]{{{}}})[^:]*([^:]{{3}}:)",
+ r"(:[^:]{{{}}})[^:]*([^:]{{3}}:?)",
(branch_len - 6).to_string()
)
).unwrap();