# bash completion for plastimatch
# James Shackleford (tshack@drexel.edu)
# Last updated: Oct 25th, 2010

# To use this file to enable command auto completion in bash:
#   1) Copy this file to:
#      /etc/bash_completion.d/
#
#   2) Refresh the auto completion system by running:
#      $ . /etc/bash_completion
#
#   3) Enjoy!


#have plastimatch &&
_plastimatch() 
{
    local cur prev command
    local ft_img ft_gen ft_opt
    local opts_main opts_add opts_adjust opts_crop opts_compare \
          opts_compose opts_convert opts_diff opts_dvh opts_header \
          opts_mask opts_register opts_resample opts_slice opts_stats \
          opts_warp

    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
#    prev="${COMP_WORDS[COMP_CWORD-1]}"
    command="${COMP_WORDS[1]}"

    # main plastimatch commands
    opts_main="add adjust crop compare compose convert diff dvh header mask register resample slice stats warp"

    # specific options for the various commands
    opts_add=""
    opts_adjust="--input --output --output-type --scale --ab-scale --stretch --truncate-above --truncate-below"
    opts_crop="--input --output --voxels"
    opts_compare=""
    opts_compose=""
    opts_convert="--input --xf --interpolation --fixed --offset --spacing --dims --default-val --output-type --algorithm --patient-pos --dicom-dir --ctatts --dif --input-ss-img --input-ss-list --prune-empty --input-dose-img --input-dose-xio --input-dose-ast --input-dose-mc --output-cxt --output-dicom --output-dij --output-dose-img --output-img --output-labelmap --output-colormap --output-prefix --output-ss-img --output-ss-list --output-vf --output-xio"
    opts_diff=""
    opts_dvh="--input-ss-img --input-ss-list --input-dose --output-csv --input-uints --cumulative --num-bins --bin-width"
    opts_header=""
    opts_mask="--input --output --mask --negate-mask --mask-value --output-format --output-type"
    opts_register=""
    opts_resample="--input --output --subsample --fixed --origin --spacing --size --output_type --interpolation --default_val"
    opts_slice="--input --output --thumbnail-dim --thumbnail-spacing --slice-loc"
    opts_stats=""
    opts_warp="--input --xf --interpolation --fixed --offset --spacing --dims --default-val --output-type --algorithm --patient-pos --dicom-dir --ctatts --dif --input-ss-img --input-ss-list --prune-empty --input-dose-img --input-dose-xio --input-dose-ast --input-dose-mc --output-cxt --output-dicom --output-dij --output-dose-img --output-labelmap --output-colormap --output-prefix --output-ss-img --output-ss-list --output-vf --output-xio"

    # supported image file types
    ft_img="mha|MHA|mhd|MHD|nrrd|NRRD"

    # possible extensions for "generic" file types
    ft_gen="txt|TXT|csv|CSV|cfg|CFG|cmd|CMD|tfm|TFM|plm|PLM"

    # 3rd party/vendor filetypes
    ft_opt="dcm|DCM|xio|XIO"

 




# --- Completion Logic ---
    case "${command}" in
    add)
        if [[ "$cur" == -* ]]; then
            COMPREPLY=( $(compgen -W "${opts_add}" -- "${cur}") )
        else
            _filedir '@('${ft_img}')'
        fi
        return 0
        ;;
    adjust)
        if [[ "$cur" == -* ]]; then
            COMPREPLY=( $(compgen -W "${opts_adjust}" -- "${cur}") )
        else
            _filedir '@('${ft_img}')'
        fi
        return 0
        ;;
    crop)
        if [[ "$cur" == -* ]]; then
            COMPREPLY=( $(compgen -W "${opts_crop}" -- "${cur}") )
        else
            _filedir '@('${ft_img}')'
        fi
        return 0
        ;;
    compare)
        if [[ "$cur" == -* ]]; then
            COMPREPLY=( $(compgen -W "${opts_compare}" -- "${cur}") )
        else
            _filedir '@('${ft_img}')'
        fi
        return 0
        ;;
    compose)
        if [[ "$cur" == -* ]]; then
            COMPREPLY=( $(compgen -W "${opts_compose}" -- "${cur}") )
        else
            _filedir '@('${ft_img}'|'${ft_gen}')'
        fi
        return 0
        ;;
    convert)
        if [[ "$cur" == -* ]]; then
            COMPREPLY=( $(compgen -W "${opts_convert}" -- "${cur}") )
        else
            _filedir '@('${ft_img}'|'${ft_gen}'|'${ft_opt}')'
        fi
        return 0
        ;;
    diff)
        if [[ "$cur" == -* ]]; then
            COMPREPLY=( $(compgen -W "${opts_diff}" -- "${cur}") )
        else
            _filedir '@('${ft_img}')'
        fi
        return 0
        ;;
    dvh)
        if [[ "$cur" == -* ]]; then
            COMPREPLY=( $(compgen -W "${opts_dvh}" -- "${cur}") )
        else
            _filedir '@('${ft_img}'|'${ft_gen}')'
        fi
        return 0
        ;;
    header)
        if [[ "$cur" == -* ]]; then
            COMPREPLY=( $(compgen -W "${opts_header}" -- "${cur}") )
        else
            _filedir '@('${ft_img}')'
        fi
        return 0
        ;;
    mask)
        if [[ "$cur" == -* ]]; then
            COMPREPLY=( $(compgen -W "${opts_mask}" -- "${cur}") )
        else
            _filedir '@('${ft_img}')'
        fi
        return 0
        ;;
    register)
        if [[ "$cur" == -* ]]; then
            COMPREPLY=( $(compgen -W "${opts_register}" -- "${cur}") )
        else
            _filedir '@('${ft_gen}')'
        fi
        return 0
        ;;
    resample)
        if [[ "$cur" == -* ]]; then
            COMPREPLY=( $(compgen -W "${opts_resample}" -- "${cur}") )
        else
            _filedir '@('${ft_img}')'
        fi
        return 0
        ;;
    slice)
        if [[ "$cur" == -* ]]; then
            COMPREPLY=( $(compgen -W "${opts_slice}" -- "${cur}") )
        else
            _filedir '@('${ft_img}')'
        fi
        return 0
        ;;
    stats)
        if [[ "$cur" == -* ]]; then
            COMPREPLY=( $(compgen -W "${opts_stats}" -- "${cur}") )
        else
            _filedir '@('${ft_img}')'
        fi
        return 0
        ;;
    warp)
        if [[ "$cur" == -* ]]; then
            COMPREPLY=( $(compgen -W "${opts_warp}" -- "${cur}") )
        else
            _filedir '@('${ft_img}'|'${ft_gen}')'
        fi
        return 0
        ;;
    *)
        COMPREPLY=( $(compgen -W "${opts_main}" "${cur}") )
        return 0
        ;;
    esac
}
complete -F _plastimatch plastimatch

# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh
