]>
Commit | Line | Data |
---|---|---|
7dbca9be HH |
1 | #!/bin/bash |
2 | # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- | |
3 | # ex: ts=8 sw=4 sts=4 et filetype=sh | |
4 | # | |
5 | # Copyright 2013 Red Hat, Inc. All rights reserved. | |
6 | # | |
7 | # This program is free software; you can redistribute it and/or modify | |
8 | # it under the terms of the GNU General Public License as published by | |
9 | # the Free Software Foundation; either version 2 of the License, or | |
10 | # (at your option) any later version. | |
11 | # | |
12 | # This program is distributed in the hope that it will be useful, | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU General Public License for more details. | |
16 | # | |
17 | # You should have received a copy of the GNU General Public License | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | # | |
20 | ||
21 | __contains_word () { | |
22 | local word=$1; shift | |
23 | for w in $*; do [[ $w = $word ]] && return 0; done | |
24 | return 1 | |
25 | } | |
26 | ||
27 | _lsinitrd() { | |
28 | local field_vals= cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} | |
29 | local -A OPTS=( | |
30 | [STANDALONE]='-s --size -h --help' | |
31 | ||
32 | [ARG]='-f --file -k --kver' | |
33 | ) | |
34 | ||
35 | if __contains_word "$prev" ${OPTS[ARG]}; then | |
36 | case $prev in | |
37 | --file|-f) | |
38 | comps=$(compgen -f -- "$cur") | |
39 | compopt -o filenames | |
40 | ;; | |
41 | --kver|-k) | |
42 | comps=$(cd /lib/modules; echo [0-9]*) | |
43 | ;; | |
44 | *) | |
45 | return 0 | |
46 | ;; | |
47 | esac | |
48 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
49 | return 0 | |
50 | fi | |
51 | ||
52 | if [[ $cur = -* ]]; then | |
53 | COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) | |
54 | return 0 | |
55 | fi | |
56 | ||
57 | comps=$(compgen -f -- "$cur") | |
58 | compopt -o filenames | |
59 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
60 | return 0 | |
61 | } | |
62 | ||
63 | complete -F _lsinitrd lsinitrd |