From 5b9e302e9b51eb156851f93e3c47a35dff51430b Mon Sep 17 00:00:00 2001 From: Thayne McCombs Date: Sun, 9 Oct 2022 00:02:28 -0600 Subject: [PATCH] Support powershell when guessing shell for completions --- src/cli.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 88d323c..2af1fa3 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -591,14 +591,21 @@ impl Opts { #[cfg(feature = "completions")] fn guess_shell() -> anyhow::Result { let env_shell = std::env::var_os("SHELL").map(PathBuf::from); - let shell = env_shell + if let Some(shell) = env_shell .as_ref() .and_then(|s| s.file_name()) .and_then(|s| s.to_str()) - .ok_or_else(|| anyhow!("Unable to get shell from environment"))?; - shell - .parse::() - .map_err(|_| anyhow!("Unknown shell {}", shell)) + { + shell + .parse::() + .map_err(|_| anyhow!("Unknown shell {}", shell)) + } else { + // Assume powershell on windows + #[cfg(windows)] + return Ok(Shell::Powershell); + #[cfg(not(windows))] + return Err(anyhow!("Unable to get shell from environment")); + } } #[derive(Copy, Clone, PartialEq, Eq, ValueEnum)]