diff options
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index 3ebcee5..2cc5ea9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,11 +6,11 @@ use std::path::Path; mod parser; -fn substitute_vars(word: &String) -> String { - match word.as_str() { +fn substitute_vars(word: &str) -> String { + match word { "~" => env::var("HOME").unwrap(), - w if w.chars().nth(0).unwrap() == '~' => w.replace("~", env::var("HOME").unwrap().as_str()), - w if w.chars().nth(0).unwrap() == '$' => { + w if w.starts_with('~') => w.replace('~', env::var("HOME").unwrap().as_str()), + w if w.starts_with('$') => { match env::var(&w[1..]) { Ok(val) => val, Err(_) => String::from_str("").unwrap() @@ -32,7 +32,7 @@ fn main() -> io::Result<()> { let c = parser::command_line(&line).unwrap().1; // for (c,l) in command { - let mut parts = c.iter().map(substitute_vars); + let mut parts = c.iter().map(|s| substitute_vars(s)); let command = parts.next().unwrap(); match command.as_str() { |
