Skip to content

Commit

Permalink
Merge pull request #527 from Tirka/add-nushell-completions
Browse files Browse the repository at this point in the history
Feature: add shell completions for `nushell`
  • Loading branch information
Nukesor authored Apr 24, 2024
2 parents 82f3086 + fd65ae0 commit aeb3a0f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Nushell autocompletion script [#527](https://github.com/Nukesor/pueue/pull/527)

## [3.4.0] - 2024-03-22

### Added
Expand Down
11 changes: 11 additions & 0 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions pueue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ maintenance = { status = "actively-developed" }
anyhow = "1.0"
chrono = { workspace = true }
chrono-english = "0.1"
clap = { version = "4.3", features = ["derive", "cargo", "help"] }
clap_complete = "4.3"
clap = { version = "4.5.1", features = ["derive", "cargo", "help"] }
clap_complete = "4.5.1"
clap_complete_nushell = "4.5.1"
comfy-table = "7"
command-group = { workspace = true }
ctrlc = { version = "3", features = ["termination"] }
Expand Down
27 changes: 12 additions & 15 deletions pueue/src/bin/pueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,12 @@ fn create_shell_completion_file(shell: &Shell, output_directory: &Option<PathBuf
generate_to(shells::PowerShell, &mut app, "pueue", output_directory)
}
Shell::Zsh => generate_to(shells::Zsh, &mut app, "pueue", output_directory),
};
completion_result.context(format!("Failed to generate completions for {shell:?}"))?;

return Ok(());
}

if let Some(output_directory) = output_directory {
let completion_result = match shell {
Shell::Bash => generate_to(shells::Bash, &mut app, "pueue", output_directory),
Shell::Elvish => generate_to(shells::Elvish, &mut app, "pueue", output_directory),
Shell::Fish => generate_to(shells::Fish, &mut app, "pueue", output_directory),
Shell::PowerShell => {
generate_to(shells::PowerShell, &mut app, "pueue", output_directory)
}
Shell::Zsh => generate_to(shells::Zsh, &mut app, "pueue", output_directory),
Shell::Nushell => generate_to(
clap_complete_nushell::Nushell,
&mut app,
"pueue",
output_directory,
),
};
completion_result.context(format!("Failed to generate completions for {shell:?}"))?;

Expand All @@ -139,6 +130,12 @@ fn create_shell_completion_file(shell: &Shell, output_directory: &Option<PathBuf
Shell::Fish => generate(shells::Fish, &mut app, "pueue", &mut stdout),
Shell::PowerShell => generate(shells::PowerShell, &mut app, "pueue", &mut stdout),
Shell::Zsh => generate(shells::Zsh, &mut app, "pueue", &mut stdout),
Shell::Nushell => generate(
clap_complete_nushell::Nushell,
&mut app,
"pueue",
&mut stdout,
),
};

Ok(())
Expand Down
1 change: 1 addition & 0 deletions pueue/src/client/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ pub enum Shell {
Fish,
PowerShell,
Zsh,
Nushell,
}

#[derive(Parser, Debug)]
Expand Down
3 changes: 2 additions & 1 deletion pueue/tests/client/integration/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ use rstest::rstest;
#[case("bash")]
#[case("fish")]
#[case("power-shell")]
#[case("nushell")]
#[test]
fn autocompletion_generation(#[case] shell: &'static str) -> Result<()> {
let output = Command::cargo_bin("pueue")?
.arg("completions")
.arg("zsh")
.arg(shell)
.arg("./")
.stdout(Stdio::piped())
.stderr(Stdio::piped())
Expand Down

0 comments on commit aeb3a0f

Please sign in to comment.