diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs index 5f73a15..7fc8991 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use ctrlc; use std::fs; use std::io; use std::io::Write; +use std::path::Path; use std::process::Command; fn eval(paths: &[&str], prompt: &str) { @@ -42,7 +43,7 @@ fn eval(paths: &[&str], prompt: &str) { // Parse command and arguments let mut split = input.split(' '); - let cmd = match split.next() { + let mut cmd = match split.next() { Some(str) if str.trim().is_empty() => continue, Some(str) => str.trim(), None => continue, @@ -74,14 +75,19 @@ fn eval(paths: &[&str], prompt: &str) { } } - // Check if the command exists - let cmd = match bins.iter().find(|b| b.split("/").last().unwrap() == cmd) { - Some(cmd) => cmd, - None => { - println!("Command not found"); - continue; - } - }; + // Check if the file exists, if given a pull or relative path + // TODO: Check if file at the path is executable (i.e. +x) + if !Path::new(cmd).exists() { + // Check if the command exists in $PATH if a full or relative path + // was not given, or if the path does not exist + cmd = match bins.iter().find(|b| b.split("/").last().unwrap() == cmd) { + Some(cmd) => cmd, + None => { + println!("Command not found"); + continue; + } + }; + } // Run the command (and wait for it to finish) let mut child = match Command::new(cmd).args(args).spawn() { |