aboutsummaryrefslogtreecommitdiff
path: root/src/utils.rs
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2022-02-15 19:16:27 +0000
committerdiogo464 <[email protected]>2022-02-15 19:16:27 +0000
commit80bcbb07c92ebe737376ecfb867917c8324d77d8 (patch)
tree1c62926a0a04df045e1fb46d9a32c428c4a0180d /src/utils.rs
parent2b04d646aec90e0fe28e84356b13758b8a956e8a (diff)
improved link command
if the destination path ends with a slash then it is considered a directory and the links will be made under that directory. otherwise all the links will have the same destination.
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/utils.rs b/src/utils.rs
index a7e945a..556bad3 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -125,6 +125,13 @@ pub fn current_working_directory() -> PathBuf {
125 std::env::current_dir().expect("Failed to obtain current working directory") 125 std::env::current_dir().expect("Failed to obtain current working directory")
126} 126}
127 127
128pub fn path_ends_with_slash(path: impl AsRef<Path>) -> bool {
129 path.as_ref()
130 .to_str()
131 .map(|s| s.ends_with('/'))
132 .unwrap_or_default()
133}
134
128#[cfg(test)] 135#[cfg(test)]
129mod tests { 136mod tests {
130 use super::*; 137 use super::*;
@@ -153,4 +160,19 @@ mod tests {
153 weakly_canonical_cwd("configs/nvim/lua/setup.lua", cwd) 160 weakly_canonical_cwd("configs/nvim/lua/setup.lua", cwd)
154 ); 161 );
155 } 162 }
163
164 #[test]
165 fn test_path_ends_with_slash() {
166 assert!(!path_ends_with_slash(""));
167 assert!(!path_ends_with_slash("/f1"));
168 assert!(!path_ends_with_slash("/f1/f2"));
169 assert!(!path_ends_with_slash("./f1/f2"));
170 assert!(!path_ends_with_slash("./f1/f2/../f3"));
171
172 assert!(path_ends_with_slash("/"));
173 assert!(path_ends_with_slash("/f1/"));
174 assert!(path_ends_with_slash("f1/"));
175 assert!(path_ends_with_slash("f1/f2/"));
176 assert!(path_ends_with_slash("f1/f2/../f3/"));
177 }
156} 178}