Relay a subcommand completion candidate to another command completion candidate in zsh

27 Views Asked by At

I have aliases to other commands in the subcommand of the my command.

To give a concrete example, I want to create a subcommand like mycli dev gcloud, and I want the candidates completed with mycli dev gcloud [tab] to match the gcloud completion candidates.

I assume that _gcloud is available which can be used as compdef _gcloud gcloud.

I wrote the following code, but could not find how to write the relevant part.

_mycli() {
  local context curcontext=$curcontext state line
  declare -A opt_args
  local ret=1
  local cmd_name=mycli

  case $cmd_name in
    mycli)
      local -a __mycli_subcmds
      __mycli_subcmds=(
        dev''
      )

      _arguments -C \
        '1: :_values "subcommand" ${__mycli_subcmds[@]}' \
        '*:: :->args' \
        && ret=0

      cmd_name=$words[1]
      case $state in
        args)
          case $cmd_name in
            dev)
              local -a __dev_subcmds
              __dev_subcmds=(
                gcloud''
              )

              _arguments -C \
                '1: :_values "subcommand" ${__dev_subcmds[@]}' \
                '*:: :->args' \
                && ret=0

              cmd_name=$words[1]
              case $state in
                args)
                  case $cmd_name in
                    gcloud)
                      _gcloud # How should I write ???
                      ;;

                  esac
                  ;;

              esac
              ;;

          esac
          ;;

      esac
      ;;

  esac

  return ret
}

compdef _mycli mycli
0

There are 0 best solutions below