go-jira / jira

simple jira command line client in Go
Apache License 2.0
2.68k stars 326 forks source link

Support auto-completion for fish #189

Open tuukkamustonen opened 6 years ago

tuukkamustonen commented 6 years ago

With bash and zsh already supported, maybe adding support for fish, too, wouldn't hurt.

coryb commented 6 years ago

the jira autocompletion for bash/zsh is available because of a Go library named "kingping" that we use: https://github.com/alecthomas/kingpin/tree/v2.2.6#bashzsh-shell-completion

They do not support fish, sending them a PR to support fish would be required currently.

glukki commented 4 years ago

In case you're open to big changes... 😬

Seems that kingpin author switched to using kong. And it has a kongplete plugin to generate completions for bash/zsh/fish by complete

jrschumacher commented 1 year ago

Add this file to your ~/.config/fish/completions/jira.fish

function __jira_perform_completion
  # echo "Performing completion"
  set -l args (commandline -opc)
  # echo (string escape -- (commandline -ct))

  set -l commands 0
  for subcommand in ("$args" --help)
    # echo "Checking $subcommand"
    if test "$subcommand" = "Commands:"
      set commands 1
    else if test "$commands" -eq 1
      # echo "Found command $subcommand"
      set -l parts (string split -m 1 ":" $subcommand)
      set -l subcommand (string trim $parts[1])
      set -l help (string trim $parts[2])

      if not contains "$subcommand" help version
        complete --command jira --exclusive --arguments $subcommand --condition __fish_use_subcommand --description "$help"
      end
    end
  end
end

function __jira_prepare_completions
  __jira_perform_completion
end

# Remove any pre-existing completions for the program since we will be handling all of them.
complete -c jira -e

# The call to __jira_prepare_completions will setup __jira_comp_results
# which provides the program's completion choices.
__jira_prepare_completions

CleanShot 2023-09-02 at 05 39 37