summaryrefslogtreecommitdiffstats
path: root/src/verbs.rs
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2019-03-04 22:34:09 +0100
committerCanop <cano.petrole@gmail.com>2019-03-04 22:34:09 +0100
commitd2837e16b074ccb53847fb6fa667559933c6b5fc (patch)
treea103b11ea81375773e2de5790646813acd59b972 /src/verbs.rs
parent98ec2758b2259f8cf47fccb865f5209f1d5d7c0b (diff)
smart path normalization
Given a verb like this one: [[verbs]] invocation = "create {subpath}" execution = "/usr/bin/nvim {directory}/{subpath}" it's possible for example to type an argument starting with ../../ and thus get a non normalized path which isn't pretty on screen. When broot recognizes a path, and the file/dir exists, it normalizes it. Bonus: this makes it clear when the typed subpath produces a path to an existing file/dir (which matters for example when the command is `mv`.
Diffstat (limited to 'src/verbs.rs')
-rw-r--r--src/verbs.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/verbs.rs b/src/verbs.rs
index 764c276..6efc3c6 100644
--- a/src/verbs.rs
+++ b/src/verbs.rs
@@ -194,7 +194,22 @@ impl Verb {
} else {
format!("{{{}}}", name)
}
- }).to_string()
+ })
+ .to_string()
+ .split_whitespace()
+ .map(|token| {
+ let path = Path::new(token);
+ if path.exists() {
+ if let Ok(path) = path.canonicalize() {
+ if let Some(path) = path.to_str() {
+ return path.to_string();
+ }
+ }
+ }
+ token.to_string()
+ })
+ .collect()
+
}
// build the cmd result for a verb defined with an exec pattern.
// Calling this function on a built-in doesn't make sense