forked from extern/nushell
I don't personally agree with this; I'd prefer less magic, and not expanding _anything_ except `~` as an initial path element Co-authored-by: nicole mazzuca <mazzucan@outlook.com>
This commit is contained in:
parent
a30930324d
commit
521e28dcdc
@ -397,14 +397,25 @@ impl ExternalCommand {
|
||||
|
||||
/// Spawn a command without shelling out to an external shell
|
||||
pub fn spawn_simple_command(&self, cwd: &str) -> Result<std::process::Command, ShellError> {
|
||||
let head = trim_enclosing_quotes(&self.name.item);
|
||||
let head = if head.starts_with('~') || head.starts_with("..") {
|
||||
nu_path::expand_path_with(head, cwd)
|
||||
.to_string_lossy()
|
||||
.to_string()
|
||||
} else {
|
||||
head
|
||||
let is_path = |arg: &str| {
|
||||
let head = match arg.split_once(::std::path::is_separator) {
|
||||
Some((x, _)) => x,
|
||||
None => arg,
|
||||
};
|
||||
head == "~" || head.chars().all(|ch| ch == '.')
|
||||
};
|
||||
let expand_path = |arg: String| {
|
||||
if is_path(&arg) {
|
||||
nu_path::expand_path_with(arg, cwd)
|
||||
.to_string_lossy()
|
||||
.to_string()
|
||||
} else {
|
||||
arg
|
||||
}
|
||||
};
|
||||
|
||||
let head = trim_enclosing_quotes(&self.name.item);
|
||||
let head = expand_path(head);
|
||||
|
||||
let mut process = std::process::Command::new(&head);
|
||||
|
||||
@ -413,13 +424,7 @@ impl ExternalCommand {
|
||||
item: trim_enclosing_quotes(&arg.item),
|
||||
span: arg.span,
|
||||
};
|
||||
arg.item = if arg.item.starts_with('~') || arg.item.starts_with("..") {
|
||||
nu_path::expand_path_with(&arg.item, cwd)
|
||||
.to_string_lossy()
|
||||
.to_string()
|
||||
} else {
|
||||
arg.item
|
||||
};
|
||||
arg.item = expand_path(arg.item);
|
||||
|
||||
let cwd = PathBuf::from(cwd);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user