pub fn default_install_path(shell: Shell, program_name: &str) -> Result<PathBuf>Expand description
Returns the default managed install path for a shell and binary name.
The returned path follows the managed layout implemented by shellcomp for supported shells.
It validates program_name before constructing the path.
The concrete layout currently used by the production support set is:
- Bash:
$XDG_DATA_HOME/bash-completion/completions/<program> - Zsh:
$ZDOTDIR/.zfunc/_<program> - Fish:
$XDG_CONFIG_HOME/fish/completions/<program>.fish - PowerShell:
- Windows:
%USERPROFILE%\\Documents\\PowerShell\\Completions\\<program>.ps1 - Non-Windows:
$XDG_DATA_HOME/powershell/completions/<program>.ps1
- Windows:
- Elvish:
$XDG_CONFIG_HOME/elvish/lib/shellcomp/<program>.elv
§Errors
Returns an error if program_name is invalid, HOME-derived directories cannot be resolved,
or the shell is not in the current production support set.
§Examples
use shellcomp::{Shell, default_install_path};
let path = default_install_path(Shell::Fish, "demo")?;
assert!(path.ends_with("fish/completions/demo.fish"));Examples found in repository?
examples/inspect_managed_paths.rs (line 5)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 for shell in [Shell::Bash, Shell::Zsh, Shell::Fish] {
5 let path = default_install_path(shell.clone(), "demo")?;
6 let activation = detect_activation(shell.clone(), "demo")?;
7
8 println!("Shell: {shell}");
9 println!("Managed path: {}", path.display());
10 println!("Activation: {activation:#?}");
11 println!();
12 }
13
14 Ok(())
15}