Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

How to solve completion of "git command" and "git-command"



Currently, _git completes both ways of invoking git and it's subcommands:

if [[ $words[1] == git ]]; then
  if (( CURRENT == 2 )); then
    _git_commands
  else
    shift words
    (( CURRENT-- ))
    curcontext="${curcontext%:*:*}:git-$words[1]:"
    _call_function ret _git-$words[1]
  fi
else
  _call_function ret _$words[1]
fi

However, the "git" command now also takes options, not just
subcommands as its argument.  How do I best solve this, so that I can
still get the functionality implied in the example above (just calling
the correct function, e.g., _git-commit for both "git commit ..." and
"git-commit ...")?

The "git" command currently takes three options: "--version",
"--help", and "--exec-path[=PATH]".

The _git_commands function currently invokes _describe:

_describe -t commands 'git command' commands && ret=0

on an array of commands-descriptions.

I was thinking that something like

if [[ $words[1] == git ]]; then
  local context state line
  typeset -A opt_args
  _arguments \
    '(- :)--version[display version information]' \
    '(- :)--help[display help]' \
    '--exec-path=-[execution path for git]:directory:_directories' \
    ':command:->command' \
    '*::options:->options' && ret=0
  case $state in
    (command)
      _git_commands
      ;;
    (options)
      curcontext="${curcontext%:*:*}:git-$words[1]:"
      _call_function ret _git-$words[1]
      ;;
  esac
else
  _call_function ret _$words[1]
fi

might work, but I want to make seru that I'm not missing something here?

Any help towards reaching a satisfactory solution will be greatly appreciated.

Thanks.

  nikolai



Messages sorted by: Reverse Date, Date, Thread, Author