From 9f42d7693fa4c1022ab6b585ac8657f93f8bb67c Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Wed, 27 Nov 2019 06:34:02 +1300 Subject: [PATCH] expand tilde in externals --- src/commands/classified/external.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/commands/classified/external.rs b/src/commands/classified/external.rs index f668abad12..c72c487b3c 100644 --- a/src/commands/classified/external.rs +++ b/src/commands/classified/external.rs @@ -98,6 +98,8 @@ impl Command { arg_string.push_str(&arg); } + let home_dir = dirs::home_dir(); + trace!(target: "nu::run::external", "command = {:?}", self.name); let mut process; @@ -129,6 +131,13 @@ impl Command { if arg.chars().all(|c| c.is_whitespace()) { None } else { + // Let's also replace ~ as we shell out + let arg = if let Some(ref home_dir) = home_dir { + arg.replace("~", home_dir.to_str().unwrap()) + } else { + arg.replace("~", "~") + }; + Some(arg.replace("$it", &i)) } }); @@ -140,6 +149,13 @@ impl Command { } else { process = Exec::cmd(&self.name); for arg in &self.args.list { + // Let's also replace ~ as we shell out + let arg = if let Some(ref home_dir) = home_dir { + arg.replace("~", home_dir.to_str().unwrap()) + } else { + arg.replace("~", "~") + }; + let arg_chars: Vec<_> = arg.chars().collect(); if arg_chars.len() > 1 && arg_chars[0] == '"' @@ -149,7 +165,7 @@ impl Command { let new_arg: String = arg_chars[1..arg_chars.len() - 1].iter().collect(); process = process.arg(new_arg); } else { - process = process.arg(arg.arg.clone()); + process = process.arg(arg.clone()); } } }