Skip to content

Commit

Permalink
cli: add nushell completion support
Browse files Browse the repository at this point in the history
  • Loading branch information
NyCodeGHG committed Oct 8, 2023
1 parent 71a3045 commit e4d228b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### New features

* `jj util completion` now supports nushell completion generation with `--nushell`.

### Fixed bugs

* Updating the working copy to a commit where a file that's currently ignored
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.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ bytes = "1.5.0"
cargo_metadata = "0.17.0"
clap = { version = "4.4.6", features = ["derive", "deprecated", "wrap_help"] }
clap_complete = "4.4.3"
clap_complete_nushell = "4.4.1"
clap_mangen = "0.2.10"
chrono = { version = "0.4.31", default-features = false, features = [
"std",
Expand Down
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ cargo_metadata = { workspace = true }
chrono = { workspace = true }
clap = { workspace = true }
clap_complete = { workspace = true }
clap_complete_nushell = { workspace = true }
clap_mangen = { workspace = true }
config = { workspace = true }
criterion = { workspace = true, optional = true }
Expand Down
22 changes: 17 additions & 5 deletions cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,15 @@ struct UtilCompletionArgs {
/// source <(jj util completion --zsh)
#[arg(long, verbatim_doc_comment)]
zsh: bool,
/// Print a completion script for Nushell
///
/// Apply it by running this:
///
/// jj util completion --nushell | save ~/.config/nushell/jj.nu
/// 'use ~/.config/nushell/jj.nu' | save --append $nu.config-path
/// source $nu.config-path
#[arg(long, verbatim_doc_comment)]
nushell: bool,
}

/// Print a ROFF (manpage)
Expand Down Expand Up @@ -3653,16 +3662,19 @@ fn cmd_util(
) -> Result<(), CommandError> {
match subcommand {
UtilCommands::Completion(completion_matches) => {
use clap_complete::{generate, Shell};

let mut app = command.app().clone();
let mut buf = vec![];
let shell = if completion_matches.zsh {
clap_complete::Shell::Zsh
if completion_matches.zsh {
generate(Shell::Zsh, &mut app, "jj", &mut buf);
} else if completion_matches.fish {
clap_complete::Shell::Fish
generate(Shell::Fish, &mut app, "jj", &mut buf);
} else if completion_matches.nushell {
generate(clap_complete_nushell::Nushell, &mut app, "jj", &mut buf);
} else {
clap_complete::Shell::Bash
generate(Shell::Bash, &mut app, "jj", &mut buf);
};
clap_complete::generate(shell, &mut app, "jj", &mut buf);
ui.stdout_formatter().write_all(&buf)?;
}
UtilCommands::Mangen(_mangen_matches) => {
Expand Down
10 changes: 9 additions & 1 deletion docs/install-and-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ $ jj config set --user user.email "[email protected]"
## Command-line completion

To set up command-line completion, source the output of
`jj util completion --bash/--zsh/--fish`. Exactly how to source it
`jj util completion --bash/--zsh/--fish/--nushell`. Exactly how to source it
depends on your shell.

### Bash
Expand Down Expand Up @@ -170,3 +170,11 @@ jj util completion --fish | source
```shell
source-bash $(jj util completion)
```

### Nushell

```shell
jj util completion --nushell | save ~/.config/nushell/jj.nu
'use ~/.config/nushell/jj.nu' | save --append $nu.config-path
source $nu.config-path
```

0 comments on commit e4d228b

Please sign in to comment.