mirror of
https://github.com/sharkdp/fd
synced 2024-10-04 14:59:15 +00:00
Use new Shell::from_env method in clap_complete
Instead of having an fd specific implementation.
This commit is contained in:
parent
9e88f91c22
commit
2c3e40c9d9
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -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",
|
||||
]
|
||||
|
|
|
@ -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"
|
||||
|
|
22
src/cli.rs
22
src/cli.rs
|
@ -673,32 +673,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")]
|
||||
|
|
Loading…
Reference in a new issue