diff --git a/Cargo.lock b/Cargo.lock index aa9df7316..af137b4f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -129,9 +129,9 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.0.3" +version = "4.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfe581a2035db4174cdbdc91265e1aba50f381577f0510d0ad36c7bc59cc84a3" +checksum = "96b0fba905b035a30d25c1b585bf1171690712fbb0ad3ac47214963aa4acc36c" dependencies = [ "clap", ] diff --git a/Cargo.toml b/Cargo.toml index 878c1c5f5..6f57249c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,7 +50,7 @@ normpath = "0.3.2" chrono = "0.4" once_cell = "1.15.0" crossbeam-channel = "0.5.6" -clap_complete = {version = "4.0", optional = true} +clap_complete = {version = "4.0.5", optional = true} [dependencies.clap] version = "4.0.12" diff --git a/src/cli.rs b/src/cli.rs index bbd548eb4..9e648630b 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -682,32 +682,12 @@ impl Opts { self.gen_completions .map(|maybe_shell| match maybe_shell { Some(sh) => Ok(sh), - None => guess_shell(), + None => Shell::from_env().ok_or_else(|| anyhow!("Unable to get shell from environment")), }) .transpose() } } -#[cfg(feature = "completions")] -fn guess_shell() -> anyhow::Result { - let env_shell = std::env::var_os("SHELL").map(PathBuf::from); - if let Some(shell) = env_shell - .as_ref() - .and_then(|s| s.file_name()) - .and_then(|s| s.to_str()) - { - 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)] pub enum FileType { #[value(alias = "f")]