Module: Kotoshu::Cli::Completions::ScriptBuilders::Zsh

Defined in:
lib/kotoshu/cli/completions_command.rb

Class Method Summary collapse

Class Method Details

.build(commands, language_argument_commands) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/kotoshu/cli/completions_command.rb', line 94

def build(commands, language_argument_commands)
  describe_block = commands.map { |c| "'#{c.name}:#{escape(c.description)}'" }.join(" ")
  lang_case = language_case(language_argument_commands)
  <<~ZSH
    #compdef kotoshu
    # kotoshu zsh completion — install with:
    #   kotoshu completions zsh > "${fpath[1]}/_kotoshu"

    _kotoshu() {
      local -a commands
      commands=(
        #{describe_block}
      )

      if (( CURRENT == 2 )); then
        _describe 'command' commands
        return
      fi

    #{ScriptBuilders.indent(lang_case, 2)}
    }

    _kotoshu "$@"
  ZSH
end