-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
173 additions
and
26 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Shell Completions | ||
|
||
Env-select 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: Env-select 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 es)" >> ~/.bashrc | ||
``` | ||
|
||
## Elvish | ||
|
||
```elvish | ||
echo "eval (E:COMPLETE=elvish es | slurp)" >> ~/.elvish/rc.elv | ||
``` | ||
|
||
## Fish | ||
|
||
```fish | ||
echo "source (COMPLETE=fish es | psub)" >> ~/.config/fish/config.fish | ||
``` | ||
|
||
## Powershell | ||
|
||
```powershell | ||
echo "COMPLETE=powershell es | Invoke-Expression" >> $PROFILE | ||
``` | ||
|
||
## Zsh | ||
|
||
````zsh | ||
echo "source <(COMPLETE=zsh es)" >> ~/.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
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,44 @@ | ||
use crate::config::{Config, Name}; | ||
use clap_complete::CompletionCandidate; | ||
use std::ffi::OsStr; | ||
|
||
/// Provide completions for application names | ||
pub fn complete_application(current: &OsStr) -> Vec<CompletionCandidate> { | ||
let Ok(config) = Config::load() else { | ||
return Vec::new(); | ||
}; | ||
|
||
get_candidates(config.applications.keys().map(Name::as_str), current) | ||
} | ||
|
||
/// Provide completions for profile names | ||
pub fn complete_profile(current: &OsStr) -> Vec<CompletionCandidate> { | ||
let Ok(config) = Config::load() else { | ||
return Vec::new(); | ||
}; | ||
|
||
// Suggest all profiles for all applications. Ideally we could grab the | ||
// prior argument to tell us what application we're in, but I'm not sure if | ||
// clap exposes that at all | ||
get_candidates( | ||
config | ||
.applications | ||
.values() | ||
.flat_map(|application| application.profiles.keys()) | ||
.map(Name::as_str), | ||
current, | ||
) | ||
} | ||
|
||
fn get_candidates<'a>( | ||
iter: impl Iterator<Item = &'a str>, | ||
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(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
Oops, something went wrong.