television_utils/
shell.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use color_eyre::Result;

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Shell {
    Bash,
    Zsh,
    Fish,
    PowerShell,
    Cmd,
}

const COMPLETION_ZSH: &str = include_str!("../shell/completion.zsh");
const COMPLETION_BASH: &str = include_str!("../shell/completion.bash");
const COMPLETION_FISH: &str = include_str!("../shell/completion.fish");

pub fn completion_script(shell: Shell) -> Result<&'static str> {
    match shell {
        Shell::Bash => Ok(COMPLETION_BASH),
        Shell::Zsh => Ok(COMPLETION_ZSH),
        Shell::Fish => Ok(COMPLETION_FISH),
        _ => color_eyre::eyre::bail!(
            "This shell is not yet supported: {:?}",
            shell
        ),
    }
}