| 1 |
# Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2. |
| 2 |
# Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2. |
| 3 |
# Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2. |
| 4 |
# This file is part of Coccinelle. |
| 5 |
# |
| 6 |
# Coccinelle is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation, according to version 2 of the License. |
| 9 |
# |
| 10 |
# Coccinelle is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with Coccinelle. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
# |
| 18 |
# The authors reserve the right to distribute this or future versions of |
| 19 |
# Coccinelle under other licenses. |
| 20 |
# |
| 21 |
# http://coccinelle.lip6.fr/ |
| 22 |
|
| 23 |
|
| 24 |
# From bash completion of git: __gitcomp_1 |
| 25 |
__spatchcomp_1 () |
| 26 |
{ |
| 27 |
local c IFS=' '$'\t'$'\n' |
| 28 |
for c in $1; do |
| 29 |
case "$c" in |
| 30 |
-*) printf %s$'\n' "$c " ;; |
| 31 |
*/) printf %s$'\n' "$c" ;; |
| 32 |
*) printf %s$'\n' "$c " ;; |
| 33 |
esac |
| 34 |
done |
| 35 |
} |
| 36 |
|
| 37 |
have spatch && |
| 38 |
_spatch() |
| 39 |
{ |
| 40 |
local cur prev xspec |
| 41 |
|
| 42 |
COMPREPLY=() |
| 43 |
cur=${COMP_WORDS[COMP_CWORD]} |
| 44 |
prev=${COMP_WORDS[COMP_CWORD-1]} |
| 45 |
_spatch_options="--parse-cocci --sp-file -I --dir --patch |
| 46 |
--iso-file --macro-file --macro-file-builtins |
| 47 |
--in-place --out-place -h --help --shorthelp --longhelp -o --ignore-unknown-options |
| 48 |
--use-glimpse --use-idutils |
| 49 |
--include-headers --no-includes --all-includes --local-includes --preprocess |
| 50 |
--quiet --very-quiet --debug --timeout --test" |
| 51 |
|
| 52 |
if [[ $COMP_CWORD -eq 1 ]]; then |
| 53 |
local IFS=$'\n' |
| 54 |
COMPREPLY=( $(compgen -W "$(__spatchcomp_1 "${_spatch_options}")" -- $cur) ) |
| 55 |
return 0 |
| 56 |
fi |
| 57 |
case "$prev" in |
| 58 |
--parse-cocci|--sp-file) |
| 59 |
xspec="!*.cocci" |
| 60 |
;; |
| 61 |
--iso-file) |
| 62 |
xspec="!*.iso" |
| 63 |
;; |
| 64 |
--macro-file|--macro-file-builtins) |
| 65 |
xspec="!*.h" |
| 66 |
;; |
| 67 |
-I|--dir|--patch) |
| 68 |
xspec="" |
| 69 |
;; |
| 70 |
*) |
| 71 |
xspec="!*.c" |
| 72 |
;; |
| 73 |
esac |
| 74 |
if [[ "$xspec" == "" ]]; then |
| 75 |
COMPREPLY=( $( compgen -d -o nospace -S '/' -- "$cur" ) ) |
| 76 |
elif [[ "$cur" == -* ]]; then |
| 77 |
local IFS=$'\n' |
| 78 |
COMPREPLY=( $(compgen -W "$(__spatchcomp_1 "${_spatch_options}")" -- $cur) ) |
| 79 |
elif [[ "$xspec" == "!*.c" ]]; then |
| 80 |
COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \ |
| 81 |
$( compgen -d -o nospace -S '/' -- "$cur" ) ) |
| 82 |
else |
| 83 |
COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \ |
| 84 |
$( compgen -d -o nospace -S '/' -- "$cur" ) ) |
| 85 |
fi |
| 86 |
return 0 |
| 87 |
} |
| 88 |
|
| 89 |
complete -F _spatch -o bashdefault -o default -o nospace spatch \ |
| 90 |
|| complete -F _spatch -o default -o nospace spatch |
| 91 |
|
| 92 |
complete -F _spatch -o bashdefault -o default -o nospace spatch.opt \ |
| 93 |
|| complete -F _spatch -o default -o nospace spatch.opt |
| 94 |
|
| 95 |
# Local variables: |
| 96 |
# mode: shell-script |
| 97 |
# sh-basic-offset: 4 |
| 98 |
# indent-tabs-mode: nil |
| 99 |
# End: |
| 100 |
# ex: ts=4 sw=4 et filetype=sh |