Skip to content

Commit

Permalink
Use new Shell::from_env method in clap_complete
Browse files Browse the repository at this point in the history
Instead of having an fd specific implementation.
  • Loading branch information
tmccombs committed Nov 8, 2022
1 parent 3e154a0 commit b6b2bcf
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -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"
Expand Down
22 changes: 1 addition & 21 deletions src/cli.rs
Expand Up @@ -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<Shell> {
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::<Shell>()
.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")]
Expand Down

0 comments on commit b6b2bcf

Please sign in to comment.