get.porter.sh/porter@v1.3.0/scripts/mage-completion.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # Provide tab completion for mage
     4  # Copyright https://github.com/yohanyflores
     5  # https://github.com/magefile/mage/issues/113#issuecomment-437710124
     6  
     7  _mage_completions()
     8  {
     9      local cur prev opts
    10  
    11      # namespaces with colon
    12      _get_comp_words_by_ref -n : cur
    13  
    14      # prev word.
    15      prev="${COMP_WORDS[COMP_CWORD-1]}"
    16  
    17      case "${prev}" in
    18          -compile)
    19              COMPREPLY+=( $(compgen -f -- "${cur}") )
    20              ;;
    21          -d)
    22              COMPREPLY+=( $(compgen -d -- "${cur}") )
    23              ;;
    24          -gocmd)
    25              COMPREPLY+=( $(compgen -f -- "${cur}") )
    26              ;;
    27          -t)
    28              opts="30s 1m 1m30s 2m 2m30s 3m 3m30s 4m 4m30s 5m 10m 20m 30m 1h"
    29              COMPREPLY+=( $(compgen -W "${opts}" -- ${cur}) )
    30              ;;
    31          *)
    32              if [[ ${cur} == -* ]]; then
    33                  opts="$(mage -h | grep "^\\s*-" | awk '{print $1}')"
    34              else
    35                  opts="$(mage -l | tail -n +2 | awk '{print tolower($1)}')"
    36              fi
    37              COMPREPLY+=( $(compgen -W "${opts}" -- "${cur}"))
    38              ;;
    39      esac
    40  
    41      __ltrim_colon_completions "$cur"
    42  }
    43  
    44  complete -F _mage_completions mage