1# bash completion for cdrecord/wodim                       -*- shell-script -*-
2
3_cdrecord()
4{
5    local cur prev words cword
6    _init_completion -n = || return
7
8    local generic_options track_options track_mode
9
10    # foo=bar style option
11    if [[ $cur == *=* ]]; then
12        prev=${cur%%=*}
13        cur=${cur#*=}
14        case $prev in
15            textfile | cuefile | msifile)
16                _filedir
17                ;;
18            blank)
19                COMPREPLY=($(compgen -W 'help all fast track unreserve trtail
20                    unclose session' -- "$cur"))
21                ;;
22            driveropts)
23                if [[ $cur == *=* ]]; then
24                    prev=${cur%%=*}
25                    cur=${cur#*=}
26                    case $prev in
27                        varirec)
28                            COMPREPLY=($(compgen -W "-2 -1 0 1 2" -- "$cur"))
29                            ;;
30                        gigarec)
31                            COMPREPLY=($(compgen -W "0.6 0.7 0.8 1.0 1.2 1.3
32                                1.4" -- "$cur"))
33                            ;;
34                        tattoofile)
35                            _filedir
36                            ;;
37                    esac
38                else
39                    COMPREPLY=($(compgen -W 'burnfree noburnfree varirec=
40                        gigarec= audiomaster forcespeed noforcespeed speedread
41                        nospeedread singlesession nosinglesession hidecdr
42                        nohidecdr tattooinfo tattoofile=' -- "$cur"))
43                    [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
44                fi
45                ;;
46            driver)
47                COMPREPLY=($(compgen -W "$($1 driver=help 2>&1 |
48                    awk 'NR > 1 { print $1 }') help" -- "$cur"))
49                ;;
50            minbuf)
51                COMPREPLY=($(compgen -W '{25..95}' -- "$cur"))
52                ;;
53        esac
54        return
55    fi
56
57    generic_options=(-version -v -V -d -silent -force -immed -dummy -clone
58        -dao -sao -tao -raw -raw96r -raw96p -raw16 -multi -msinfo -toc -atip
59        -fix -nofix -waiti -load -lock -eject -format -setdropts -checkdrive
60        -prcap -inq -scanbus --devices -reset -abort -overburn -ignsize
61        -useinfo -packet -noclose -text "debug=" "kdebug=" "minbuf="
62        "msifile=" "speed=" "blank=" "fs=" "ts=" "dev=" "gracetime="
63        "timeout=" "driver=" "driveropts=" "defpregap=" "pktsize=" "mcn="
64        "textfile=" "cuefile=")
65    track_options=(-audio -swab -data -mode2 -xa -xa1 -xa2 -xamix -cdi
66        -isosize -pad -nopad -shorttrack -noshorttrack -preemp -nopreemp
67        -copy -nocopy -scms "isrc=" "index=" "padsize=" "pregap=" "tsize=")
68    # look if previous was either a file or a track option
69    track_mode=0
70    if ((cword > 1)); then
71        if [[ -f $prev ]]; then
72            track_mode=1
73        else
74            local opt
75            for opt in "${track_options[@]}"; do
76                if [[ $opt == "$prev" ]]; then
77                    track_mode=1
78                    break
79                fi
80            done
81        fi
82    fi
83
84    # files are always eligible completion
85    _filedir
86    # track options are always available
87    COMPREPLY+=($(compgen -W '${track_options[@]}' -- "$cur"))
88    # general options are no more available after file or track option
89    if ((track_mode == 0)); then
90        COMPREPLY+=($(compgen -W '${generic_options[@]}' -- "$cur"))
91    fi
92    [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
93} &&
94    complete -F _cdrecord cdrecord wodim
95
96# ex: filetype=sh
97