use clap_complete::Shell;
pub fn git_subcommand_wrapper(shell: Shell) -> &'static str {
match shell {
Shell::Bash => GIT_SUBCMD_BASH,
Shell::Zsh => GIT_SUBCMD_ZSH,
Shell::Fish => GIT_SUBCMD_FISH,
_ => "",
}
}
const GIT_SUBCMD_BASH: &str = r#"
# --- git subcommand wrapper -------------------------------------------
# Enable completion for "git std" (git subcommand invocation).
# Git's bash completion calls _git_<subcmd> for custom subcommands.
_git_std() {
local _save_words=("${COMP_WORDS[@]}")
local _save_cword=$COMP_CWORD
# Merge "git std" into "git-std" so _git-std sees the expected layout.
COMP_WORDS=("git-std" "${COMP_WORDS[@]:2}")
(( COMP_CWORD -= 1 ))
local _cur="${COMP_WORDS[$COMP_CWORD]}"
local _prev="${COMP_WORDS[$((COMP_CWORD > 0 ? COMP_CWORD - 1 : 0))]}"
_git-std "git-std" "$_cur" "$_prev"
COMP_WORDS=("${_save_words[@]}")
COMP_CWORD=$_save_cword
}
"#;
const GIT_SUBCMD_ZSH: &str = r#"
# --- git subcommand wrapper -------------------------------------------
# Register "std" as a git user-command so "git std <TAB>" triggers _git-std.
zstyle ':completion:*:*:git:*' user-commands std:'Conventional commit standards'
"#;
const GIT_SUBCMD_FISH: &str = r#"
# --- git subcommand wrapper -------------------------------------------
# Register "std" as a git subcommand for "git std <TAB>" completion.
complete -f -c git -n __fish_git_needs_command -a std -d 'Conventional commit standards'
complete -f -c git -n '__fish_git_using_command std' -a commit -d 'Interactive conventional commit builder'
complete -f -c git -n '__fish_git_using_command std' -a lint -d 'Validate commit messages'
complete -f -c git -n '__fish_git_using_command std' -a bump -d 'Version bump, changelog, commit, and tag'
complete -f -c git -n '__fish_git_using_command std' -a version -d 'Query the current project version'
complete -f -c git -n '__fish_git_using_command std' -a changelog -d 'Generate a changelog'
complete -f -c git -n '__fish_git_using_command std' -a init -d 'Scaffold hooks, bootstrap script, and README section'
complete -f -c git -n '__fish_git_using_command std' -a bootstrap -d 'Post-clone environment setup'
complete -f -c git -n '__fish_git_using_command std' -a hook -d 'Git hooks management'
complete -f -c git -n '__fish_git_using_command std' -a doctor -d 'Run health checks'
"#;