Module: Kotoshu::Cli::Completions::ScriptBuilders::Fish

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

Class Method Summary collapse

Class Method Details

.build(commands, language_argument_commands) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/kotoshu/cli/completions_command.rb', line 145

def build(commands, language_argument_commands)
  command_lines = commands.map do |c|
    "complete -c kotoshu -n \"__fish_use_subcommand\" -a \"#{c.name}\" -d \"#{escape(c.description)}\""
  end.join("\n")
  language_lines = language_argument_commands.map do |cmd|
    matcher = "__fish_seen_subcommand_from #{cmd}"
    "complete -c kotoshu -n \"#{matcher}\" -a \"(kotoshu completions languages 2>/dev/null)\""
  end.join("\n")
  <<~FISH
    # kotoshu fish completion — install with:
    #   kotoshu completions fish > ~/.config/fish/completions/kotoshu.fish
    #{command_lines}
    #{language_lines}
  FISH
end