auto
      ˆl–Ãa¾”ªClÊq@†ãN\må1hßÃ0ÁÀ  "   ˆl–Ým_Jµ!®Å8 ¸Èn 
bÑ¿Äƒ}áÂÁ &^    # bash completion for dpll(8)                             -*- shell-script -*-

# Get all the optional commands for dpll
_dpll_get_optional_commands()
{
    local object=$1; shift

    local filter_options=""
    local options="$(dpll $object help 2>&1 \
        | command sed -n -e "s/^.*dpll $object //p" \
        | cut -d " " -f 1)"

    # Remove duplicate options from "dpll $OBJECT help" command
    local opt
    for opt in $options; do
        if [[ $filter_options =~ $opt ]]; then
            continue
        else
            filter_options="$filter_options $opt"
        fi
    done

    echo $filter_options
}

# Complete based on given word
_dpll_direct_complete()
{
    local device_id pin_id value

    case $1 in
        device_id)
            value=$(dpll -j device show 2>/dev/null \
                    | jq '.device[].id' 2>/dev/null)
            ;;
        pin_id)
            value=$(dpll -j pin show 2>/dev/null \
                    | jq '.pin[].id' 2>/dev/null)
            ;;
        module_name)
            value=$(dpll -j device show 2>/dev/null \
                    | jq -r '.device[]."module-name"' 2>/dev/null \
                    | sort -u)
            ;;
    esac

    echo $value
}

# Handle device subcommands
_dpll_device()
{
    local command=$1

    case $command in
        show)
            case $prev in
                id)
                    COMPREPLY=( $( compgen -W \
                        "$(_dpll_direct_complete device_id)" -- "$cur" ) )
                    return 0
                    ;;
                *)
                    COMPREPLY=( $( compgen -W "id" -- "$cur" ) )
                    return 0
                    ;;
            esac
            ;;
        set)
            case $prev in
                id)
                    COMPREPLY=( $( compgen -W \
                        "$(_dpll_direct_complete device_id)" -- "$cur" ) )
                    return 0
                    ;;
                phase-offset-monitor)
                    COMPREPLY=( $( compgen -W "enable disable true false 0 1" -- "$cur" ) )
                    return 0
                    ;;
                phase-offset-avg-factor)
                    # numeric value, no completion
                    return 0
                    ;;
                *)
                    COMPREPLY=( $( compgen -W "id phase-offset-monitor \
                        phase-offset-avg-factor" -- "$cur" ) )
                    return 0
                    ;;
            esac
            ;;
        id-get)
            case $prev in
                module-name)
                    COMPREPLY=( $( compgen -W \
                        "$(_dpll_direct_complete module_name)" -- "$cur" ) )
                    return 0
                    ;;
                clock-id)
                    # numeric value, no completion
                    return 0
                    ;;
                type)
                    COMPREPLY=( $( compgen -W "pps eec" -- "$cur" ) )
                    return 0
                    ;;
                *)
                    COMPREPLY=( $( compgen -W "module-name clock-id type" \
                        -- "$cur" ) )
                    return 0
                    ;;
            esac
            ;;
    esac
}

# Handle pin subcommands
_dpll_pin()
{
    local command=$1

    case $command in
        show)
            case $prev in
                id)
                    COMPREPLY=( $( compgen -W \
                        "$(_dpll_direct_complete pin_id)" -- "$cur" ) )
                    return 0
                    ;;
                device)
                    COMPREPLY=( $( compgen -W \
                        "$(_dpll_direct_complete device_id)" -- "$cur" ) )
                    return 0
                    ;;
                *)
                    COMPREPLY=( $( compgen -W "id device" -- "$cur" ) )
                    return 0
                    ;;
            esac
            ;;
        set)
            case $prev in
          