/** * Shell completion command */ export async function completionCommand(options: { shell?: string }): Promise { const shell = options.shell || detectShell(); const scripts: Record = { bash: BASH_COMPLETION, zsh: ZSH_COMPLETION, fish: FISH_COMPLETION, }; const script = scripts[shell]; if (!script) { console.error(`Unsupported shell: ${shell}`); console.log('Supported shells: bash, zsh, fish'); process.exit(1); } console.log(script); console.log(''); console.log(`# To enable completion, add this to your shell config:`); console.log(getInstallInstructions(shell)); } function detectShell(): string { const shell = process.env.SHELL || ''; if (shell.includes('bash')) return 'bash'; if (shell.includes('zsh')) return 'zsh'; if (shell.includes('fish')) return 'fish'; return 'bash'; // default } function getInstallInstructions(shell: string): string { const instructions: Record = { bash: `# ~/.bashrc or ~/.bash_profile eval "$(neohub completion --shell bash)"`, zsh: `# ~/.zshrc eval "$(neohub completion --shell zsh)"`, fish: `# ~/.config/fish/config.fish neohub completion --shell fish | source`, }; return instructions[shell] || ''; } const BASH_COMPLETION = `# neohub bash completion _neohub_completions() { local cur prev commands COMPREPLY=() cur="\${COMP_WORDS[COMP_CWORD]}" prev="\${COMP_WORDS[COMP_CWORD-1]}" commands="init chat edit analyze models recommend config completion" case "\${prev}" in neohub) COMPREPLY=( $(compgen -W "\${commands}" -- "\${cur}") ) return 0 ;; --type|-t) COMPREPLY=( $(compgen -W "review explain security performance" -- "\${cur}") ) return 0 ;; --file|-f) COMPREPLY=( $(compgen -f -- "\${cur}") ) return 0 ;; --shell) COMPREPLY=( $(compgen -W "bash zsh fish" -- "\${cur}") ) return 0 ;; edit) if [[ "\${cur}" == -* ]]; then COMPREPLY=( $(compgen -W "--file --instruction --backup" -- "\${cur}") ) fi return 0 ;; analyze) if [[ "\${cur}" == -* ]]; then COMPREPLY=( $(compgen -W "--type" -- "\${cur}") ) else COMPREPLY=( $(compgen -f -- "\${cur}") ) fi return 0 ;; esac } complete -F _neohub_completions neohub`; const ZSH_COMPLETION = `# neohub zsh completion #compdef neohub _neohub() { local -a commands commands=( 'init:Initialize NeoHub configuration' 'chat:Start an interactive chat session' 'edit:Edit a file with AI assistance' 'analyze:Analyze code' 'models:List available Ollama models' 'recommend:Get intelligent model recommendation' 'config:Show current configuration' 'completion:Generate shell completion script' ) local -a edit_opts edit_opts=( '--file[File to edit]:file:_files' '--instruction[Edit instruction]:instruction:' '--backup[Create backup before editing]' ) local -a analyze_opts analyze_opts=( '--type[Analysis type]:type:(review explain security performance)' ) _arguments -C \\ '1: :->command' \\ '*:: :->args' case $state in command) _describe 'neohub commands' commands ;; args) case $words[1] in edit) _arguments $edit_opts ;; analyze) _arguments $analyze_opts '*:path:_files' ;; completion) _arguments '--shell[Shell type]:shell:(bash zsh fish)' ;; esac ;; esac } _neohub "$@"`; const FISH_COMPLETION = `# neohub fish completion complete -c neohub -f # Commands complete -c neohub -n "__fish_use_subcommand" -a init -d "Initialize NeoHub configuration" complete -c neohub -n "__fish_use_subcommand" -a chat -d "Start an interactive chat session" complete -c neohub -n "__fish_use_subcommand" -a edit -d "Edit a file with AI assistance" complete -c neohub -n "__fish_use_subcommand" -a analyze -d "Analyze code" complete -c neohub -n "__fish_use_subcommand" -a models -d "List available Ollama models" complete -c neohub -n "__fish_use_subcommand" -a recommend -d "Get intelligent model recommendation" complete -c neohub -n "__fish_use_subcommand" -a config -d "Show current configuration" complete -c neohub -n "__fish_use_subcommand" -a completion -d "Generate shell completion script" # edit command options complete -c neohub -n "__fish_seen_subcommand_from edit" -s f -l file -d "File to edit" -r complete -c neohub -n "__fish_seen_subcommand_from edit" -s i -l instruction -d "Edit instruction" -r complete -c neohub -n "__fish_seen_subcommand_from edit" -s b -l backup -d "Create backup before editing" # analyze command options complete -c neohub -n "__fish_seen_subcommand_from analyze" -s t -l type -d "Analysis type" -a "review explain security performance" # completion command options complete -c neohub -n "__fish_seen_subcommand_from completion" -l shell -d "Shell type" -a "bash zsh fish"`;