fix docs
This commit is contained in:
parent
65fc61f7e4
commit
be4bc4abe1
16
README.md
16
README.md
@ -1,2 +1,18 @@
|
||||
# untildify
|
||||
Utility to replace ~ with user home directory
|
||||
|
||||
## Example
|
||||
|
||||
```rust
|
||||
extern crate untildify;
|
||||
|
||||
fn main() {
|
||||
println!("Untildify : {}", untildify::untildify("~/Desktop"));
|
||||
// prints /Users/<user_name>/Desktop
|
||||
|
||||
// Other Examples
|
||||
// assert_eq!(untildify("~/a/b/c/d/e"), "/User/Untildify/a/b/c/d/e");
|
||||
// assert_eq!(untildify("~/"), "/User/Untildify/");
|
||||
}
|
||||
|
||||
```
|
||||
14
src/lib.rs
14
src/lib.rs
@ -2,6 +2,20 @@ use regex::Regex;
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Convert a tilde path to an absolute path: ~/Desktop → /Users/sathish/Desktop
|
||||
///
|
||||
/// Example
|
||||
///
|
||||
/// ```
|
||||
/// use untildify::untildify;
|
||||
///
|
||||
/// fn main() {
|
||||
/// println!("Untildify : {}", untildify::untildify("~/Desktop")); // prints /Users/<user_name>/Desktop
|
||||
/// println!("Untildify : {}", untildify("~/a/b/c/d/e")); // prints "/User/Untildify/a/b/c/d/e"
|
||||
/// println!("Untildify : {}", untildify("~/")); // prints "/User/Untildify/"
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
pub fn untildify(input_path: &str) -> String {
|
||||
if input_path.is_empty() {
|
||||
return String::from(input_path);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user