-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
160 additions
and
40 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use clap_complete::CompletionCandidate; | ||
|
||
use crate::cli_util::dyn_completion_state; | ||
|
||
pub fn branch(current: &std::ffi::OsStr) -> Vec<CompletionCandidate> { | ||
let Some(current) = current.to_str() else { | ||
return Vec::new(); | ||
}; | ||
|
||
let mut ui = dyn_completion_state::UI.take().unwrap(); | ||
let command = dyn_completion_state::COMMAND_HELPER.take().unwrap(); | ||
let ui = &mut ui; | ||
|
||
let workspace_command = command.workspace_helper(ui).unwrap(); | ||
let repo = workspace_command.repo(); | ||
let view = repo.view(); | ||
|
||
view.bookmarks() | ||
.map(|(local, _)| local) | ||
.filter(|branch| branch.starts_with(current)) | ||
.map(CompletionCandidate::new) | ||
.collect() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -206,6 +206,25 @@ $ jj config set --user user.email "[email protected]" | |
|
||
## Command-line completion | ||
|
||
TODO: update this section if appropriate. | ||
|
||
I think we can simply update the output of `jj util completion $SHELL` to be | ||
- `source <(COMPLETE=bash jj)`' | ||
- `COMPLETE=fish jj | source` | ||
etc. instead of the actual script. | ||
That will honor the recommendation of clap to regenerate and source the hooks on | ||
every startup of the shell. | ||
(see the recommendation here: https://docs.rs/clap_complete/latest/clap_complete/env/index.html) | ||
|
||
Nushell is not yet supported for dynamic completions, I presume we can simply | ||
continue to emit the normal, static completions for Nushell. | ||
|
||
Another option would be to have some kind of beta-phase for the dynamic | ||
completions, where we tell users to manually add `COMPLETE=fish jj | source` | ||
to their shell init files if they want to opt into the beta. If there are no | ||
issues found, we change `jj util completion` to emit the dynamic completion | ||
hooks instead. | ||
|
||
To set up command-line completion, source the output of | ||
`jj util completion bash/zsh/fish`. Exactly how to source it | ||
depends on your shell. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters