]> Pileus Git - ~andy/sunrise/blob - dev-lang/dmd/files/dmd.bashcomp
dev-lang/dmd: New Ebuild for bug 376519, builds dmd from source, 64-bit support....
[~andy/sunrise] / dev-lang / dmd / files / dmd.bashcomp
1 _dmd_opts="$(dmd --help 2>&1 | sed -n 's/^\s*\(-\+\w*=*-*\).*/\1/p' | \
2              sed 's/filename\|docdir\|directory\|path\|linkerflag\|objdir//g')"
3 _ld_opts_dmd="$(ld --help 2>&1 | sed -n 's/.*\(--[-a-z0-9]\{1,\}\).*/-L\1/p')"
4 _env_vars_dmd="$(printenv | cut -d = -f 1 | sort -u)"
5
6
7 _filedir_dmd()
8 {
9     cur=$(echo "${cur}" | sed 's:^'${1}'::')
10     if test "${2}" == "(*)" ;then
11         _filedir
12     else
13         _filedir '@'${2}
14     fi
15     cur="${1}${cur}"
16     J=0
17     F=0
18     for I in ${COMPREPLY[@]}
19     do
20         if test -d ${I} ;then
21             COMPREPLY[${J}]="${1}${I}/"
22         else
23             COMPREPLY[${J}]="${1}${I}"
24             F=1
25         fi
26         J=$((J + 1))
27     done
28     if test ${F} -eq 1 -a ${J} -eq 1 ;then
29         compopt +o nospace
30     fi
31 }
32
33
34 _dmd()
35 {
36     COMPREPLY=()
37     local cur
38     _get_comp_words_by_ref -n = cur
39     local IFS=$'\t\n'
40
41     case "${cur}" in
42         -L-L*) # match linker paths
43             compopt -o nospace
44             _filedir_dmd "-L-L" "(/)"
45             ;;
46         -L--*) # match linker options
47             COMPREPLY=( $( compgen -W "${_ld_opts_dmd}" -- ${cur} ) )
48             ;;
49         -L*) # match linker options
50             local opts=$(echo -e "-L-L\n-L--")
51             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
52             ;;
53         -*) # match dmd options
54             compopt -o nospace
55             if [[ "${cur}" == "-Dd"* ]] ;then
56                 _filedir_dmd "-Dd" "(/)"
57             elif [[ "${cur}" == "-Df"* ]] ;then
58                 _filedir_dmd "-Df" "(*)"
59             elif [[ "${cur}" == "-debug="* ]] ;then
60                 cur=${cur#*=}
61             elif [[ "${cur}" == "-debuglib="* ]] ;then
62                 cur=${cur#*=}
63                 _filedir
64                 if [ ${#COMPREPLY[@]} -eq 1 ] && [ -f ${COMPREPLY[@]} ] ;then
65                     compopt +o nospace
66                 fi
67             elif [[ "${cur}" == "-defaultlib="* ]] ;then
68                 cur=${cur#*=}
69                 _filedir
70                 if [ ${#COMPREPLY[@]} -eq 1 ] && [ -f ${COMPREPLY[@]} ] ;then
71                     compopt +o nospace
72                 fi
73             elif [[ "${cur}" == "-deps="* ]] ;then
74                 cur=${cur#*=}
75                 _filedir
76                 if [ ${#COMPREPLY[@]} -eq 1 ] && [ -f ${COMPREPLY[@]} ] ;then
77                     compopt +o nospace
78                 fi
79             elif [[ "${cur}" == "-Hd"* ]] ;then
80                 _filedir_dmd "-Hd" "(/)"
81             elif [[ "${cur}" == "-Hf"* ]] ;then
82                 _filedir_dmd "-Hf" "(*)"
83             elif [[ "${cur}" == "-I"* ]] ;then
84                 _filedir_dmd "-I" "(/)"
85             elif [[ "${cur}" == "-J"* ]] ;then
86                 _filedir_dmd "-J" "(/)"
87             elif [[ "${cur}" == "-od"* ]] ;then
88                 _filedir_dmd "-od" "(/)"
89             elif [[ "${cur}" == "-of"* ]] ;then
90                 _filedir_dmd "-of" "(*)"
91             elif [[ "${cur}" == "-version="* ]] ;then
92                 cur=${cur#*=}
93             elif [[ "${cur}" == "-Xf"* ]] ;then
94                 _filedir_dmd "-Xf" "(*)"
95             else
96                 COMPREPLY=( $(compgen -W "${_dmd_opts}" -- ${cur}) )
97                 C='\n'
98                 L=$(echo -e "-cov${C}-fPIC${C}-gc${C}--help${C}-ignore\
99                     ${C}-inline${C}-lib${C}-m32${C}-m64${C}-man${C}-map\
100                     ${C}-noboundscheck${C}-nofloat${C}-O${C}-o-${C}-op\
101                     ${C}-profile${C}-property${C}-quiet${C}-release\
102                     ${C}-run${C}-unittest${C}-vtls${C}-wi" | sed 's: ::g')
103                 if test ${#COMPREPLY[@]} -eq 1 ;then
104                     for I in ${L}
105                     do
106                         if test "${COMPREPLY[@]}" == "$I" ; then
107                             compopt +o nospace
108                         fi
109                     done
110                 fi
111             fi
112             ;;
113         @*) # match arguments variable/file
114             compopt -o nospace
115             TMP=( $(compgen -W "${_env_vars_dmd}" -P "@" -- ${cur#@}) )
116             _filedir_dmd "@" "(*)"
117             COMPREPLY=( "${TMP[@]}" "${COMPREPLY[@]}" )
118             if test ${#COMPREPLY[@]} -eq 1 ;then  compopt +o nospace ; fi
119             ;;
120         *) # match d files
121             _filedir '@(d|dd|di|o|a|/)'
122             ;;
123     esac
124     return 0
125 }
126
127
128 complete -F _dmd dmd