#!/bin/bash completion for {scriptname} _{scriptname}(){ local cur prev local -A ARGS MAP FORCE OPTS OPTS_SUB MULTI COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" OPTS=({opts}) ARGS=({args}) MAP=({map}) if [ ! -z "$prev" ]; then # if is an argument complete with list of choice if define prev_key=${MAP[$prev]} if [ ! -z "$prev_key" ] && [ -v "${ARGS[$prev_key]}" ]; then COMPREPLY=($(compgen -W "${ARGS[$prev_key]}" -- "${cur}")) return 0 fi fi for in_use in ${COMP_WORDS[@]:1}; do key=${MAP[$in_use]} # Unset option that is already use unset OPTS[$key] unset ARGS[$key] done compl="${OPTS[@]}" COMPREPLY=($(compgen -W "${compl}" -- "${cur}")) return 0 } complete -F _{scriptname} {scriptname}