-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This replaces the subcommand with an env var to enable completions
- Loading branch information
1 parent
b9d9bd9
commit c95ff95
Showing
12 changed files
with
155 additions
and
52 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
pub mod collections; | ||
pub mod completions; | ||
pub mod generate; | ||
pub mod history; | ||
pub mod import; | ||
|
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//! Shell completion utilities | ||
use clap_complete::CompletionCandidate; | ||
use slumber_core::collection::{Collection, CollectionFile}; | ||
use std::{ffi::OsStr, ops::Deref}; | ||
|
||
/// Provide completions for profile IDs | ||
pub fn complete_profile(current: &OsStr) -> Vec<CompletionCandidate> { | ||
let Ok(collection) = load_collection() else { | ||
return Vec::new(); | ||
}; | ||
|
||
get_candidates(collection.profiles.keys(), current) | ||
} | ||
|
||
/// Provide completions for recipe IDs | ||
pub fn complete_recipe(current: &OsStr) -> Vec<CompletionCandidate> { | ||
let Ok(collection) = load_collection() else { | ||
return Vec::new(); | ||
}; | ||
|
||
get_candidates( | ||
collection | ||
.recipes | ||
.iter() | ||
// Include recipe IDs only. Folder IDs are never passed to the CLI | ||
.filter_map(|(_, node)| Some(&node.recipe()?.id)), | ||
current, | ||
) | ||
} | ||
|
||
fn load_collection() -> anyhow::Result<Collection> { | ||
// For now we just lean on the default collection paths. In the future we | ||
// should be able to look for a --file arg in the command and use that path | ||
let path = CollectionFile::try_path(None, None)?; | ||
Collection::load(&path) | ||
} | ||
|
||
fn get_candidates<'a, T: 'a + Deref<Target = String>>( | ||
iter: impl Iterator<Item = &'a T>, | ||
current: &OsStr, | ||
) -> Vec<CompletionCandidate> { | ||
let Some(current) = current.to_str() else { | ||
return Vec::new(); | ||
}; | ||
// Only include IDs prefixed by the input we've gotten so far | ||
iter.filter(|value| value.starts_with(current)) | ||
.map(|value| CompletionCandidate::new(value.as_str())) | ||
.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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Install | ||
|
||
See [installation instructions](/artifacts) | ||
See [installation instructions](/artifacts). Optionally, after installation you can [enable shell completions](./troubleshooting/shell_completions.md). |
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,46 @@ | ||
# Shell Completions | ||
|
||
Slumber provides tab completions for most shells. For the full list of supported shells, [see the clap docs](https://docs.rs/clap_complete/latest/clap_complete/aot/enum.Shell.html). | ||
|
||
> Note: Slumber uses clap's native shell completions, which are still experimental. [This issue](https://github.com/clap-rs/clap/issues/3166) outlines the remaining work to be done. | ||
To source your completions: | ||
|
||
**WARNING:** We recommend re-sourcing your completions on upgrade. | ||
These completions work by generating shell code that calls into `your_program` while completing. | ||
That interface is unstable and a mismatch between the shell code and `your_program` may result | ||
in either invalid completions or no completions being generated. | ||
|
||
For this reason, we recommend generating the shell code anew on shell startup so that it is | ||
"self-correcting" on shell launch, rather than writing the generated completions to a file. | ||
|
||
## Bash | ||
|
||
```bash | ||
echo "source <(COMPLETE=bash slumber)" >> ~/.bashrc | ||
``` | ||
|
||
## Elvish | ||
|
||
```elvish | ||
echo "eval (E:COMPLETE=elvish slumber | slurp)" >> ~/.elvish/rc.elv | ||
``` | ||
|
||
## Fish | ||
|
||
```fish | ||
echo "source (COMPLETE=fish slumber | psub)" >> ~/.config/fish/config.fish | ||
``` | ||
|
||
## Powershell | ||
|
||
```powershell | ||
echo "COMPLETE=powershell slumber | Invoke-Expression" >> $PROFILE | ||
``` | ||
|
||
## Zsh | ||
|
||
````zsh | ||
echo "source <(COMPLETE=zsh slumber)" >> ~/.zshrc | ||
``` | ||
```` |
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