mirror of
https://github.com/nushell/nushell
synced 2025-01-28 04:45:18 +00:00
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
1 changed files with 19 additions and 14 deletions
|
@ -397,14 +397,25 @@ impl ExternalCommand {
|
||||||
|
|
||||||
/// Spawn a command without shelling out to an external shell
|
/// Spawn a command without shelling out to an external shell
|
||||||
pub fn spawn_simple_command(&self, cwd: &str) -> Result<std::process::Command, ShellError> {
|
pub fn spawn_simple_command(&self, cwd: &str) -> Result<std::process::Command, ShellError> {
|
||||||
let head = trim_enclosing_quotes(&self.name.item);
|
let is_path = |arg: &str| {
|
||||||
let head = if head.starts_with('~') || head.starts_with("..") {
|
let head = match arg.split_once(::std::path::is_separator) {
|
||||||
nu_path::expand_path_with(head, cwd)
|
Some((x, _)) => x,
|
||||||
.to_string_lossy()
|
None => arg,
|
||||||
.to_string()
|
};
|
||||||
} else {
|
head == "~" || head.chars().all(|ch| ch == '.')
|
||||||
head
|
|
||||||
};
|
};
|
||||||
|
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);
|
let mut process = std::process::Command::new(&head);
|
||||||
|
|
||||||
|
@ -413,13 +424,7 @@ impl ExternalCommand {
|
||||||
item: trim_enclosing_quotes(&arg.item),
|
item: trim_enclosing_quotes(&arg.item),
|
||||||
span: arg.span,
|
span: arg.span,
|
||||||
};
|
};
|
||||||
arg.item = if arg.item.starts_with('~') || arg.item.starts_with("..") {
|
arg.item = expand_path(arg.item);
|
||||||
nu_path::expand_path_with(&arg.item, cwd)
|
|
||||||
.to_string_lossy()
|
|
||||||
.to_string()
|
|
||||||
} else {
|
|
||||||
arg.item
|
|
||||||
};
|
|
||||||
|
|
||||||
let cwd = PathBuf::from(cwd);
|
let cwd = PathBuf::from(cwd);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue