PageRenderTime 73ms CodeModel.GetById 59ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/bash_completion.d/apport_completion

http://github.com/brinkman83/bashrc
#! | 256 lines | 203 code | 53 blank | 0 comment | 0 complexity | 25401049b34a9a3270edef042f69e2e7 MD5 | raw file
  1# 
  2# Apport bash-completion
  3#
  4###############################################################################
  5
  6# get available symptoms
  7_apport_symptoms ()
  8{
  9    local syms
 10    for FILE in $(ls /usr/share/apport/symptoms); do
 11       syms="$syms ${FILE%.py}"
 12    done
 13    echo $syms
 14
 15}
 16
 17# completion when used without parameters
 18_apport_parameterless ()
 19{
 20    local param
 21    # parameter-less completion
 22    # param= COMMAND parameters
 23    #        package names
 24    #        PIDs
 25    #        Symptoms
 26    #        .crash/.apport files
 27    param="$dashoptions \
 28           $( apt-cache pkgnames $cur 2> /dev/null ) \
 29           $( command ps axo pid | sed 1d ) \
 30           $( _apport_symptoms ) \
 31           $( compgen -G "${cur}*.apport"
 32              compgen -G "${cur}*.crash" )"
 33    COMPREPLY=( $( compgen -W "$param" -- $cur) )
 34
 35}
 36
 37# apport-bug ubuntu-bug completion
 38_apport-bug ()
 39{
 40    local cur dashoptions prev param
 41
 42    COMPREPLY=()
 43    cur=`_get_cword`
 44    prev=${COMP_WORDS[COMP_CWORD-1]}
 45
 46
 47    # available options
 48    dashoptions='-h --help -f --file-bug -u --update-bug -s --symptom -p \
 49                 --package -P --pid -c --crash-file --save -v --version'
 50
 51    case "$prev" in
 52    ubuntu-bug | apport-bug)
 53        case "$cur" in
 54        -*)
 55            # parameter completion
 56            COMPREPLY=( $( compgen -W "$dashoptions" -- $cur ) )
 57
 58        ;;
 59        *)
 60            # no parameter given
 61            _apport_parameterless 
 62
 63        ;;
 64        esac
 65
 66    ;;
 67    -f | --file-bug)
 68        param="-P --pid -p --package -s --symptom"
 69        COMPREPLY=( $( compgen -W "$param $(_apport_symptoms)" -- $cur) )
 70
 71    ;;
 72    -p | --package)
 73        COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) )
 74
 75    ;;
 76    -u | --update-bug)
 77        param="-p --package"
 78        COMPREPLY=( $( compgen -W "$param" -- $cur) )
 79
 80    ;;
 81    -s | --symptom)
 82        COMPREPLY=( $( compgen -W "$(_apport_symptoms)" -- $cur) )
 83
 84    ;;
 85    -P | --pid)
 86	COMPREPLY=( $( compgen -W '$( command ps axo pid | sed 1d )' -- $cur ) )
 87
 88    ;;
 89    --save)
 90        COMPREPLY=( $( compgen -o default -G "$cur*" ) )
 91    
 92    ;;
 93    -c | --crash-file)
 94        # only show *.apport *.crash files
 95        COMPREPLY=( $( compgen -G "${cur}*.apport"
 96                       compgen -G "${cur}*.crash" ) )
 97
 98    ;;
 99    -h | --help | -v | --version)
100        # standalone parameters
101        return 0
102
103    ;;
104    *)
105        if [ "${COMP_WORDS[COMP_CWORD-2]}" == "--save" ]; then
106            # use same completion as if no parameter is given
107            case "$cur" in
108            -*)
109                # parameter completion
110                COMPREPLY=( $( compgen -W "$dashoptions" -- $cur ) )
111
112            ;;
113            *)
114                _apport_parameterless 
115
116            ;;
117            esac
118
119        else
120            # save is allowed for most parameters
121            param="--save"
122            COMPREPLY=( $( compgen -W "$param" -- $cur) )
123
124        fi
125
126    ;;
127    esac
128}
129
130# apport-cli completion
131_apport-cli ()
132{
133    local cur dashoptions prev param
134
135    COMPREPLY=()
136    cur=`_get_cword`
137    prev=${COMP_WORDS[COMP_CWORD-1]}
138
139
140    # available options
141    dashoptions='-h --help -f --file-bug -u --update-bug -s --symptom \
142                 -c --crash-file --save -v --version'
143
144    case "$prev" in
145    apport-cli)
146        case "$cur" in
147        -*)
148            # parameter completion
149            COMPREPLY=( $( compgen -W "$dashoptions" -- $cur ) )
150
151        ;;
152        *)
153            # no parameter given
154            _apport_parameterless 
155
156        ;;
157        esac
158
159    ;;
160    -f | --file-bug)
161        param="-P --pid -p --package -s --symptom"
162        COMPREPLY=( $( compgen -W "$param $(_apport_symptoms)" -- $cur) )
163
164    ;;
165    -s | --symptom)
166        COMPREPLY=( $( compgen -W "$(_apport_symptoms)" -- $cur) )
167
168    ;;
169    --save)
170        COMPREPLY=( $( compgen -o default -G "$cur*" ) )
171    
172    ;;
173    -c | --crash-file)
174        # only show *.apport *.crash files
175        COMPREPLY=( $( compgen -G "${cur}*.apport"
176                       compgen -G "${cur}*.crash" ) )
177
178    ;;
179    -h | --help | -v | --version)
180        # standalone parameters
181        return 0
182
183    ;;
184    *)
185        if [ "${COMP_WORDS[COMP_CWORD-2]}" == "--save" ]; then
186            # use same completion as if no parameter is given
187            case "$cur" in
188            -*)
189                # parameter completion
190                COMPREPLY=( $( compgen -W "$dashoptions" -- $cur ) )
191
192            ;;
193            *)
194                _apport_parameterless 
195
196            ;;
197            esac
198
199        else
200            # save is allowed for most parameters
201            param="--save"
202            COMPREPLY=( $( compgen -W "$param" -- $cur) )
203
204        fi
205
206    ;;
207    esac
208}
209
210# apport-unpack completion
211_apport-unpack ()
212{
213    local cur prev
214
215    COMPREPLY=()
216    cur=`_get_cword`
217    prev=${COMP_WORDS[COMP_CWORD-1]}
218
219    case "$prev" in
220    apport-unpack)
221        # only show *.apport *.crash files
222        COMPREPLY=( $( compgen -G "${cur}*.apport"
223                       compgen -G "${cur}*.crash" ) )
224
225    ;;
226    esac
227}
228
229# apport-collect completion
230_apport-collect ()
231{
232    local cur prev
233
234    COMPREPLY=()
235    cur=`_get_cword`
236    prev=${COMP_WORDS[COMP_CWORD-1]}
237
238    case "$prev" in 
239    apport-collect)
240            COMPREPLY=( $( compgen -W "-p --package" -- $cur) )
241
242    ;;
243    -p | --package)
244        # list package names
245        COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) )
246
247    ;;
248    esac
249}
250
251# bind completion to apport commands
252complete -F _apport-bug -o filenames -o dirnames ubuntu-bug
253complete -F _apport-bug -o filenames -o dirnames apport-bug
254complete -F _apport-cli -o filenames -o dirnames apport-cli
255complete -F _apport-unpack -o filenames -o dirnames apport-unpack
256complete -F _apport-collect apport-collect