%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/share/bash-completion/completions/
Upload File :
Create Path :
Current File : //usr/share/bash-completion/completions/apport-cli

# Apport bash-completion for apport-bug and apport-cli

# get available symptoms
_apport_symptoms ()
{
    local filename path symptoms
    for path in /usr/share/apport/symptoms/*; do
        [[ -e "$path" ]] || continue
        filename="${path##*/}"
        # hide utility files and symptoms that don't have a run() function
        [[ ! "$filename" =~ ^_.* ]] || continue
        grep -Eq "^def run\s*\(.*\):" "$path" || continue
        symptoms+=("${filename%.py}")
    done
    echo "${symptoms[*]}"
}

# completion when used without parameters
_apport_parameterless ()
{
    local param
    # parameter-less completion
    # param= COMMAND parameters
    #        package names
    #        PIDs
    #        Symptoms
    #        any file
    param="$dashoptions \
           $( apt-cache pkgnames $cur 2> /dev/null ) \
           $( command ps axo pid | sed 1d ) \
           $( _apport_symptoms ) \
           $( compgen -G "${cur}*" )"
    COMPREPLY=( $( compgen -W "$param" -- $cur) )

}

# apport-bug ubuntu-bug completion
_apport-bug ()
{
    local cur dashoptions prev param

    COMPREPLY=()
    cur=`_get_cword`
    prev=${COMP_WORDS[COMP_CWORD-1]}


    # available options
    dashoptions='-h --help --save -v --version --tag -w --window'

    case "$prev" in
    ubuntu-bug | apport-bug)
        case "$cur" in
        -*)
            # parameter completion
            COMPREPLY=( $( compgen -W "$dashoptions" -- $cur ) )

        ;;
        *)
            # no parameter given
            _apport_parameterless 

        ;;
        esac

    ;;
    --save)
        COMPREPLY=( $( compgen -o default -G "$cur*" ) )
    
    ;;
    -w | --window)
        dashoptions="--save --tag"
        COMPREPLY=( $( compgen -W "$dashoptions" -- $cur ) )
    ;;
    -h | --help | -v | --version | --tag)
        # standalone parameters
        return 0

    ;;
    *)
        # --save and --window make only sense once
        dashoptions="--tag"
        if ! [[ "${COMP_WORDS[*]}" =~ .*--save.* ]]; then
            dashoptions="--save $dashoptions"
        fi
        if ! [[ "${COMP_WORDS[*]}" =~ .*--window.* || "${COMP_WORDS[*]}" =~ .*\ -w\ .* ]]; then
            dashoptions="-w --window $dashoptions"
        fi

        case "$cur" in
        -*)
            # parameter completion
            COMPREPLY=( $( compgen -W "$dashoptions" -- $cur ) )

        ;;
        *)
            _apport_parameterless 

        ;;
        esac

    ;;
    esac
}

# apport-cli completion
_apport-cli ()
{
    local cur dashoptions prev param

    COMPREPLY=()
    cur=`_get_cword`
    prev=${COMP_WORDS[COMP_CWORD-1]}


    # available options
    dashoptions='-h --help -f --file-bug -u --update-bug -s --symptom \
                 -c --crash-file --save -v --version --tag -w --window'

    case "$prev" in
    apport-cli)
        case "$cur" in
        -*)
            # parameter completion
            COMPREPLY=( $( compgen -W "$dashoptions" -- $cur ) )

        ;;
        *)
            # no parameter given
            _apport_parameterless 

        ;;
        esac

    ;;
    -f | --file-bug)
        param="-P --pid -p --package -s --symptom"
        COMPREPLY=( $( compgen -W "$param $(_apport_symptoms)" -- $cur) )

    ;;
    -s | --symptom)
        COMPREPLY=( $( compgen -W "$(_apport_symptoms)" -- $cur) )

    ;;
    --save)
        COMPREPLY=( $( compgen -o default -G "$cur*" ) )
    
    ;;
    -c | --crash-file)
        # only show *.apport *.crash files
        COMPREPLY=( $( compgen -G "${cur}*.apport"
                       compgen -G "${cur}*.crash" ) )

    ;;
    -w | --window)
        dashoptions="--save --tag"
        COMPREPLY=( $( compgen -W "$dashoptions" -- $cur ) )
    ;;
    -h | --help | -v | --version | --tag)
        # standalone parameters
        return 0

    ;;
    *)
        dashoptions='--tag'

        # most parameters only make sense once
        if ! [[ "${COMP_WORDS[*]}" =~ .*--save.* ]]; then
            dashoptions="--save $dashoptions"
        fi
        if ! [[ "${COMP_WORDS[*]}" =~ .*--window.* || "${COMP_WORDS[*]}" =~ .*\ -w\ .* ]]; then
            dashoptions="-w --window $dashoptions"
        fi
        if ! [[ "${COMP_WORDS[*]}" =~ .*--symptom.* || "${COMP_WORDS[*]}" =~ .*\ -s\ .* ]]; then
            dashoptions="-s --symptom $dashoptions"
        fi
        if ! [[ "${COMP_WORDS[*]}" =~ .*--update.* || "${COMP_WORDS[*]}" =~ .*\ -u\ .* ]]; then
            dashoptions="-u --update $dashoptions"
        fi
        if ! [[ "${COMP_WORDS[*]}" =~ .*--file-bug.* || "${COMP_WORDS[*]}" =~ .*\ -f\ .* ]]; then
            dashoptions="-f --file-bug $dashoptions"
        fi
        if ! [[ "${COMP_WORDS[*]}" =~ .*--crash-file.* || "${COMP_WORDS[*]}" =~ .*\ -c\ .* ]]; then
            dashoptions="-c --crash-file $dashoptions"
        fi

        # use same completion as if no parameter is given
        case "$cur" in
        -*)
            # parameter completion
            COMPREPLY=( $( compgen -W "$dashoptions" -- $cur ) )

        ;;
        *)
            _apport_parameterless 

        ;;
        esac

    ;;
    esac
}

# bind completion to apport commands
complete -F _apport-bug -o filenames -o dirnames ubuntu-bug
complete -F _apport-bug -o filenames -o dirnames apport-bug
complete -F _apport-cli -o filenames -o dirnames apport-cli

Zerion Mini Shell 1.0