1

I have a script that takes file like arguments (multi part arguments), I am fetching the possible values and putting them in an array called raw and then using

_multi_parts / "(${raw[@]})" 

to autocomplete. The problem is that this is case sensitive, how can I make it so that it I type mycommand get fo and press Tab it will autocomplete to mycommand get Foo/ if Foo is one of the things in raw.

The full completion is here for reference:

_mycommand() {
  local curcontext="$curcontext" state line

  _arguments "1: :->command" "*: :->label"

  case $state in
  command)
    _arguments "1: :(add get ls rm)"
  ;;
  *) 
    case $words[2] in
      add|get|ls|rm)
        if [ -f ~/.pts ]; then
          IFS=$'\n' read -d '' -r raw <<< "$(mycommand ls)"
          _multi_parts / "(${raw[@]})"
        fi
      ;;
      *)
        _files
      ;;
    esac
  esac
}

_mycommand "$@"

mycommand ls outputs path like names like the following:

Foo/Bar/x
Foo/Bar/y
Derp/z
Placeholder/z
Ross MacArthur
  • 4,735
  • 1
  • 24
  • 36

1 Answers1

0

Okay I figured it out:

Change lines

IFS=$'\n' read -d '' -r raw <<< "$(mycommand ls)"
_multi_parts / "(${raw[@]})"

To

IFS=$'\n' raw=($(mycommand ls))
_multi_parts -M "m:{[:lower:][:upper:]}={[:upper:][:lower:]}" / raw
Ross MacArthur
  • 4,735
  • 1
  • 24
  • 36