diff --git a/src/cmd/shell/files/bash/kbs.source b/src/cmd/shell/files/bash/kbs.source new file mode 100644 index 0000000..1f34bf0 --- /dev/null +++ b/src/cmd/shell/files/bash/kbs.source @@ -0,0 +1,12 @@ +alias _inline_fzf="fzf --height=50% --reverse -0 --inline-info --border" +alias _kbs_bin="$(type -p kbs)" + +function kbs() { + if [ $# -eq 0 ]; then + # if no parameters are passed, we want to run fzf on available kubeconfigs and set the selected one as active kubeconfig + eval "$(_kbs_bin use $(_kbs_bin ls | _inline_fzf))" + else + # if parameters are passed, we just call the kbs binary directly + ${_kbs_bin} $@ + fi +} diff --git a/src/cmd/shell/files/zsh/kbs.source b/src/cmd/shell/files/zsh/kbs.source index 52e7509..ffcba73 100644 --- a/src/cmd/shell/files/zsh/kbs.source +++ b/src/cmd/shell/files/zsh/kbs.source @@ -1,10 +1,10 @@ alias _inline_fzf="fzf --height=50% --reverse -0 --inline-info --border" +alias _kbs_bin="$(whence -cp kbs)" function kbs() { - local _kbs_bin="$(whereis -q kbs)" if [ $# -eq 0 ]; then # if no parameters are passed, we want to run fzf on available kubeconfigs and set the selected one as active kubeconfig - eval "$(eval ${_kbs_bin} use $(echo "$(eval ${_kbs_bin} ls)" | _inline_fzf))" + eval "$(_kbs_bin use $(_kbs_bin ls | _inline_fzf))" else # if parameters are passed, we just call the kbs binary directly ${_kbs_bin} $@ diff --git a/src/cmd/shell/magic.rs b/src/cmd/shell/magic.rs index 95bdbe0..2fbb7b6 100644 --- a/src/cmd/shell/magic.rs +++ b/src/cmd/shell/magic.rs @@ -21,12 +21,11 @@ pub fn execute(matches: &ArgMatches) -> Result<(), Box> { .get_one::("shell") .ok_or("cannot read shell")?; - match shell { - Shell::Zsh => { - let zsh_magic = include_str!("./files/zsh/kbs.source"); - print!("{zsh_magic}"); - } - } + let magic = match shell { + Shell::Zsh => include_str!("./files/zsh/kbs.source"), + Shell::Bash => include_str!("./files/bash/kbs.source"), + }; + print!("{magic}"); Ok(()) } @@ -35,16 +34,18 @@ pub fn execute(matches: &ArgMatches) -> Result<(), Box> { #[non_exhaustive] enum Shell { Zsh, + Bash, } impl clap::ValueEnum for Shell { fn value_variants<'a>() -> &'a [Self] { - &[Shell::Zsh] + &[Shell::Zsh, Shell::Bash] } fn to_possible_value<'a>(&self) -> Option { Some(match self { Shell::Zsh => PossibleValue::new("zsh"), + Shell::Bash => PossibleValue::new("bash"), }) } }