~darkmuggle-deactivatedaccount/ubuntu/quantal/grub2/fix-872244

« back to all changes in this revision

Viewing changes to util/bash-completion.d/grub-completion.bash.in

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Evan Broder, Mario Limonciello
  • Date: 2010-11-24 13:59:55 UTC
  • mfrom: (1.17.6 upstream) (17.6.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20101124135955-r6ii5sepayr7jt53
Tags: 1.99~20101124-1ubuntu1
[ Colin Watson ]
* Resynchronise with Debian experimental.  Remaining changes:
  - Adjust for default Ubuntu boot options ("quiet splash").
  - Default to hiding the menu; holding down Shift at boot will show it.
  - Set a monochromatic theme for Ubuntu.
  - Apply Ubuntu GRUB Legacy changes to legacy update-grub script: title,
    recovery mode, quiet option, tweak how memtest86+ is displayed, and
    use UUIDs where appropriate.
  - Fix backslash-escaping in merge_debconf_into_conf.
  - Remove "GNU/Linux" from default distributor string.
  - Add crashkernel= options if kdump and makedumpfile are available.
  - If other operating systems are installed, then automatically unhide
    the menu.  Otherwise, if GRUB_HIDDEN_TIMEOUT is 0, then use keystatus
    if available to check whether Shift is pressed.  If it is, show the
    menu, otherwise boot immediately.  If keystatus is not available, then
    fall back to a short delay interruptible with Escape.
  - Allow Shift to interrupt 'sleep --interruptible'.
  - Don't display introductory message about line editing unless we're
    actually offering a shell prompt.  Don't clear the screen just before
    booting if we never drew the menu in the first place.
  - Remove some verbose messages printed before reading the configuration
    file.
  - Suppress progress messages as the kernel and initrd load for
    non-recovery kernel menu entries.
  - Change prepare_grub_to_access_device to handle filesystems
    loop-mounted on file images.
  - Ignore devices loop-mounted from files in 10_linux.
  - Show the boot menu if the previous boot failed, that is if it failed
    to get to the end of one of the normal runlevels.
  - Don't generate /boot/grub/device.map during grub-install or
    grub-mkconfig by default.
  - Adjust upgrade version checks for Ubuntu.
  - Don't display "GRUB loading" unless Shift is held down.
  - Adjust versions of grub-doc and grub-legacy-doc conflicts to tolerate
    our backport of the grub-doc split.
  - Fix LVM/RAID probing in the absence of /boot/grub/device.map.
  - Look for .mo files in /usr/share/locale-langpack as well, in
    preference.
  - Make sure GRUB_TIMEOUT isn't quoted unnecessarily.
  - Probe all devices in 'grub-probe --target=drive' if
    /boot/grub/device.map is missing.
  - Build-depend on qemu-kvm rather than qemu-system for grub-pc tests.
  - Use qemu rather than qemu-system-i386.
  - Program vesafb on BIOS systems rather than efifb.
  - Add a grub-rescue-efi-amd64 package containing a rescue CD-ROM image
    for EFI-AMD64.
  - On Wubi, don't ask for an install device, but just update wubildr
    using the diverted grub-install.
  - When embedding the core image in a post-MBR gap, check for and avoid
    sectors matching any of a list of known signatures.
  - Disable video_bochs and video_cirrus on PC BIOS systems, as probing
    PCI space seems to break on some systems.
* Downgrade "ACPI shutdown failed" error to a debug message, since it can
  cause spurious test failures.

[ Evan Broder ]
* Enable lua from grub-extras.
* Incorporate the bitop library into lua.
* Add enum_pci function to grub module in lua.
* Switch back to gfxpayload=keep by default, unless the video hardware
  is known to not support it.

[ Mario Limonciello ]
* Built part_msdos and vfat into bootx64.efi (LP: #677758)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Bash completion for grub
 
3
#
 
4
# Copyright (C) 2010  Free Software Foundation, Inc.
 
5
#
 
6
# GRUB 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, either version 3 of the License, or
 
9
# (at your option) any later version.
 
10
#
 
11
# GRUB is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License
 
17
# along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 
18
# bash completion for grub
 
19
 
 
20
__grub_dir() {
 
21
    local i c=1 boot_dir
 
22
 
 
23
    for (( c=1; c <= ${#COMP_WORDS[@]}; c++ )); do
 
24
        i="${COMP_WORDS[c]}"
 
25
        case "$i" in
 
26
            --boot-directory)
 
27
                c=$((++c))
 
28
                i="${COMP_WORDS[c]}"
 
29
                boot_dir="${i##*=}";
 
30
                break
 
31
                ;;
 
32
        esac
 
33
    done
 
34
    boot_dir=${boot_dir-/@bootdirname@}
 
35
    echo "${boot_dir%/}/@grubdirname@"
 
36
}
 
37
 
 
38
 
 
39
# This function generates completion reply with compgen
 
40
# - arg: accepts 1, 2, 3, or 4 arguments
 
41
#        $1 wordlist separate by space, tab or newline
 
42
#        $2 (optional) prefix to add
 
43
#        $3 (optional) current word to complete
 
44
#        $4 (optional) suffix to add
 
45
__grubcomp () {
 
46
    local cur="${COMP_WORDS[COMP_CWORD]}"
 
47
    if [ $# -gt 2 ]; then
 
48
        cur="$3"
 
49
    fi
 
50
    case "$cur" in
 
51
    --*=)
 
52
        COMPREPLY=()
 
53
        ;;
 
54
    *)
 
55
        local IFS=' '$'\t'$'\n'
 
56
        COMPREPLY=($(compgen -P "${2-}" -W "${1-}" -S "${4-}" -- "$cur"))
 
57
        ;;
 
58
    esac
 
59
}
 
60
 
 
61
# Function that return long options from the help of the command
 
62
# - arg: $1 (optional) command to get the long options from
 
63
__grub_get_options_from_help () {
 
64
     local prog
 
65
 
 
66
     if [ $# -ge 1 ]; then
 
67
         prog="$1"
 
68
     else
 
69
         prog="${COMP_WORDS[0]}"
 
70
     fi
 
71
 
 
72
     local i IFS=" "$'\t'$'\n'
 
73
     for i in $(LC_ALL=C $prog --help)
 
74
     do
 
75
        case $i in
 
76
             --*) echo "${i%=*}";;
 
77
         esac
 
78
     done
 
79
}
 
80
 
 
81
# Function that return long options from the usage of the command
 
82
# - arg: $1 (optional) command to get the long options from
 
83
__grub_get_options_from_usage () {
 
84
     local prog
 
85
 
 
86
     if [ $# -ge 1 ]; then
 
87
         prog="$1"
 
88
     else
 
89
         prog="${COMP_WORDS[0]}"
 
90
     fi
 
91
 
 
92
     local i IFS=" "$'\t'$'\n'
 
93
     for i in $(LC_ALL=C $prog --usage)
 
94
     do
 
95
        case $i in
 
96
            \[--*\]) i=${i#[}           # Remove leading [
 
97
                     echo ${i%%?(=*)]}  # Remove optional value and trailing ]
 
98
                     ;;
 
99
         esac
 
100
     done
 
101
}
 
102
 
 
103
__grub_get_last_option () {
 
104
    local i
 
105
    for (( i=$COMP_CWORD-1; i > 0; i-- )); do
 
106
        if [[ "${COMP_WORDS[i]}" == -* ]]; then
 
107
            echo "${COMP_WORDS[i]}"
 
108
            break;
 
109
        fi
 
110
    done
 
111
}
 
112
 
 
113
__grub_list_menuentries () {
 
114
    local cur="${COMP_WORDS[COMP_CWORD]}"
 
115
    local config_file=$(__grub_dir)/grub.cfg
 
116
 
 
117
    if [ -f "$config_file" ];then
 
118
        local IFS=$'\n'
 
119
        COMPREPLY=( $(compgen \
 
120
            -W "$( awk -F "[\"']" '/menuentry/ { print $2 }' $config_file )" \
 
121
            -- "$cur" )) #'# Help emacs syntax highlighting
 
122
    fi
 
123
}
 
124
 
 
125
__grub_list_modules () {
 
126
    local grub_dir=$(__grub_dir)
 
127
    local IFS=$'\n'
 
128
    COMPREPLY=( $( compgen -f -X '!*/*.mod' -- "${grub_dir}/$cur" | {
 
129
         while read -r tmp; do
 
130
             [ -n $tmp ] && {
 
131
                 tmp=${tmp##*/}
 
132
                 printf '%s\n' ${tmp%.mod}
 
133
             }
 
134
         done
 
135
         }
 
136
        ))
 
137
}
 
138
 
 
139
#
 
140
# grub-set-default & grub-reboot
 
141
#
 
142
_grub_set_entry () {
 
143
    local cur prev split=false
 
144
 
 
145
    COMPREPLY=()
 
146
    cur=`_get_cword`
 
147
    prev=${COMP_WORDS[COMP_CWORD-1]}
 
148
 
 
149
    _split_longopt && split=true
 
150
 
 
151
    case "$prev" in
 
152
        --boot-directory)
 
153
            _filedir -d
 
154
            return
 
155
            ;;
 
156
    esac
 
157
 
 
158
    $split && return 0
 
159
 
 
160
    if [[ "$cur" == -* ]]; then
 
161
        __grubcomp "$(__grub_get_options_from_help)"
 
162
    else
 
163
        # Default complete with a menuentry
 
164
        __grub_list_menuentries
 
165
    fi
 
166
}
 
167
 
 
168
__grub_set_default_program=$( echo grub-set-default | sed "@program_transform_name@" )
 
169
have ${__grub_set_default_program} && \
 
170
    complete -F _grub_set_entry -o filenames ${__grub_set_default_program}
 
171
unset __grub_set_default_program
 
172
 
 
173
__grub_reboot_program=$( echo grub-reboot | sed "@program_transform_name@" )
 
174
have ${__grub_reboot_program} && \
 
175
 complete -F _grub_set_entry -o filenames ${__grub_reboot_program}
 
176
unset __grub_reboot_program
 
177
 
 
178
 
 
179
#
 
180
# grub-editenv
 
181
#
 
182
_grub_editenv () {
 
183
    local cur prev
 
184
 
 
185
    COMPREPLY=()
 
186
    cur=`_get_cword`
 
187
    prev=${COMP_WORDS[COMP_CWORD-1]}
 
188
 
 
189
    case "$prev" in
 
190
        create|list|set|unset)
 
191
            COMPREPLY=( "" )
 
192
            return
 
193
            ;;
 
194
    esac
 
195
 
 
196
    __grubcomp "$(__grub_get_options_from_help)
 
197
                create list set unset"
 
198
}
 
199
 
 
200
__grub_editenv_program=$( echo grub-editenv | sed "@program_transform_name@" )
 
201
have ${__grub_editenv_program} && \
 
202
 complete -F _grub_editenv -o filenames ${__grub_editenv_program}
 
203
unset __grub_editenv_program
 
204
 
 
205
 
 
206
#
 
207
# grub-mkconfig
 
208
#
 
209
_grub_mkconfig () {
 
210
    local cur prev
 
211
 
 
212
    COMPREPLY=()
 
213
    cur=`_get_cword`
 
214
 
 
215
    if [[ "$cur" == -* ]]; then
 
216
        __grubcomp "$(__grub_get_options_from_help)"
 
217
    else
 
218
        _filedir
 
219
    fi
 
220
}
 
221
__grub_mkconfig_program=$( echo grub-mkconfig | sed "@program_transform_name@" )
 
222
have ${__grub_mkconfig_program} && \
 
223
 complete -F _grub_mkconfig -o filenames ${__grub_mkconfig_program}
 
224
unset __grub_mkconfig_program
 
225
 
 
226
 
 
227
#
 
228
# grub-setup
 
229
#
 
230
_grub_setup () {
 
231
    local cur prev split=false
 
232
 
 
233
    COMPREPLY=()
 
234
    cur=`_get_cword`
 
235
    prev=${COMP_WORDS[COMP_CWORD-1]}
 
236
 
 
237
    _split_longopt && split=true
 
238
 
 
239
    case "$prev" in
 
240
        -d|--directory)
 
241
            _filedir -d
 
242
            return
 
243
            ;;
 
244
    esac
 
245
 
 
246
    $split && return 0
 
247
 
 
248
    if [[ "$cur" == -* ]]; then
 
249
        __grubcomp "$(__grub_get_options_from_help)"
 
250
    else
 
251
        # Default complete with a filename
 
252
        _filedir
 
253
    fi
 
254
}
 
255
__grub_setup_program=$( echo grub-setup | sed "@program_transform_name@" )
 
256
have ${__grub_setup_program} && \
 
257
 complete -F _grub_setup -o filenames ${__grub_setup_program}
 
258
unset __grub_setup_program
 
259
 
 
260
 
 
261
#
 
262
# grub-install
 
263
#
 
264
_grub_install () {
 
265
    local cur prev last split=false
 
266
 
 
267
    COMPREPLY=()
 
268
    cur=`_get_cword`
 
269
    prev=${COMP_WORDS[COMP_CWORD-1]}
 
270
    last=$(__grub_get_last_option)
 
271
 
 
272
    _split_longopt && split=true
 
273
 
 
274
    case "$prev" in
 
275
        --boot-directory)
 
276
            _filedir -d
 
277
            return
 
278
            ;;
 
279
        --disk-module)
 
280
            __grubcomp "biosdisk ata"
 
281
            return
 
282
            ;;
 
283
    esac
 
284
 
 
285
    $split && return 0
 
286
 
 
287
    if [[ "$cur" == -* ]]; then
 
288
        __grubcomp "$(__grub_get_options_from_help)"
 
289
    else
 
290
        case "$last" in
 
291
            --modules)
 
292
                __grub_list_modules
 
293
                return
 
294
                ;;
 
295
        esac
 
296
 
 
297
        # Default complete with a filename
 
298
        _filedir
 
299
    fi
 
300
}
 
301
__grub_install_program=$( echo grub-install | sed "@program_transform_name@" )
 
302
have ${__grub_install_program} && \
 
303
 complete -F _grub_install -o filenames ${__grub_install_program}
 
304
unset __grub_install_program
 
305
 
 
306
 
 
307
#
 
308
# grub-mkfont
 
309
#
 
310
_grub_mkfont () {
 
311
    local cur
 
312
 
 
313
    COMPREPLY=()
 
314
    cur=`_get_cword`
 
315
 
 
316
    if [[ "$cur" == -* ]]; then
 
317
        __grubcomp "$(__grub_get_options_from_help)"
 
318
    else
 
319
        # Default complete with a filename
 
320
        _filedir
 
321
    fi
 
322
}
 
323
__grub_mkfont_program=$( echo grub-mkfont | sed "@program_transform_name@" )
 
324
have ${__grub_mkfont_program} && \
 
325
 complete -F _grub_mkfont -o filenames ${__grub_mkfont_program}
 
326
unset __grub_mkfont_program
 
327
 
 
328
 
 
329
#
 
330
# grub-mkrescue
 
331
#
 
332
_grub_mkrescue () {
 
333
    local cur prev last
 
334
 
 
335
    COMPREPLY=()
 
336
    cur=`_get_cword`
 
337
    prev=${COMP_WORDS[COMP_CWORD-1]}
 
338
    last=$(__grub_get_last_option)
 
339
 
 
340
    if [[ "$cur" == -* ]]; then
 
341
        __grubcomp "$(__grub_get_options_from_help)"
 
342
    else
 
343
        case "$last" in
 
344
            --modules)
 
345
                __grub_list_modules
 
346
                return
 
347
                ;;
 
348
        esac
 
349
 
 
350
        # Default complete with a filename
 
351
        _filedir
 
352
    fi
 
353
}
 
354
__grub_mkrescue_program=$( echo grub-mkrescue | sed "@program_transform_name@" )
 
355
have ${__grub_mkrescue_program} && \
 
356
 complete -F _grub_mkrescue -o filenames ${__grub_mkrescue_program}
 
357
unset __grub_mkrescue_program
 
358
 
 
359
 
 
360
#
 
361
# grub-mkimage
 
362
#
 
363
_grub_mkimage () {
 
364
    local cur prev split=false
 
365
 
 
366
    COMPREPLY=()
 
367
    cur=`_get_cword`
 
368
    prev=${COMP_WORDS[COMP_CWORD-1]}
 
369
 
 
370
    _split_longopt && split=true
 
371
 
 
372
    case "$prev" in
 
373
        -d|--directory|-p|--prefix)
 
374
            _filedir -d
 
375
            return
 
376
            ;;
 
377
        -O|--format)
 
378
            # Get available format from help
 
379
            local prog=${COMP_WORDS[0]}
 
380
            __grubcomp "$(LC_ALL=C $prog --help | \
 
381
                        awk -F ":" '/available formats/ { print $2 }' | \
 
382
                        sed 's/, / /g')"
 
383
            return
 
384
            ;;
 
385
    esac
 
386
 
 
387
    $split && return 0
 
388
 
 
389
    if [[ "$cur" == -* ]]; then
 
390
        __grubcomp "$(__grub_get_options_from_help)"
 
391
    else
 
392
        # Default complete with a filename
 
393
        _filedir
 
394
    fi
 
395
}
 
396
__grub_mkimage_program=$( echo grub-mkimage | sed "@program_transform_name@" )
 
397
have ${__grub_mkimage_program} && \
 
398
 complete -F _grub_mkimage -o filenames ${__grub_mkimage_program}
 
399
unset __grub_mkimage_program
 
400
 
 
401
 
 
402
#
 
403
# grub-mkpasswd-pbkdf2
 
404
#
 
405
_grub_mkpasswd-pbkdf2 () {
 
406
    local cur
 
407
 
 
408
    COMPREPLY=()
 
409
    cur=`_get_cword`
 
410
 
 
411
    if [[ "$cur" == -* ]]; then
 
412
        __grubcomp "$(__grub_get_options_from_help)"
 
413
    else
 
414
        # Default complete with a filename
 
415
        _filedir
 
416
    fi
 
417
}
 
418
__grub_mkpasswd_pbkdf2_program=$( echo grub-mkpasswd-pbkdf2 | sed "@program_transform_name@" )
 
419
have ${__grub_mkpasswd_pbkdf2_program} && \
 
420
 complete -F _grub_mkpasswd-pbkdf2 -o filenames ${__grub_mkpasswd_pbkdf2_program}
 
421
unset __grub_mkpasswd_pbkdf2_program
 
422
 
 
423
 
 
424
#
 
425
# grub-probe
 
426
#
 
427
_grub_probe () {
 
428
    local cur prev split=false
 
429
 
 
430
    COMPREPLY=()
 
431
    cur=`_get_cword`
 
432
    prev=${COMP_WORDS[COMP_CWORD-1]}
 
433
 
 
434
    _split_longopt && split=true
 
435
 
 
436
    case "$prev" in
 
437
        -t|--target)
 
438
            # Get target type from help
 
439
            local prog=${COMP_WORDS[0]}
 
440
            __grubcomp "$(LC_ALL=C $prog --help | \
 
441
                        awk -F "[()]" '/--target=/ { print $2 }' | \
 
442
                        sed 's/|/ /g')"
 
443
            return
 
444
            ;;
 
445
    esac
 
446
 
 
447
    $split && return 0
 
448
 
 
449
    if [[ "$cur" == -* ]]; then
 
450
        __grubcomp "$(__grub_get_options_from_help)"
 
451
    else
 
452
        # Default complete with a filename
 
453
        _filedir
 
454
    fi
 
455
}
 
456
__grub_probe_program=$( echo grub-probe | sed "@program_transform_name@" )
 
457
have ${__grub_probe_program} && \
 
458
 complete -F _grub_probe -o filenames ${__grub_probe_program}
 
459
unset __grub_probe_program
 
460
 
 
461
 
 
462
#
 
463
# grub-script-check
 
464
#
 
465
_grub_script-check () {
 
466
    local cur
 
467
 
 
468
    COMPREPLY=()
 
469
    cur=`_get_cword`
 
470
 
 
471
    if [[ "$cur" == -* ]]; then
 
472
        __grubcomp "$(__grub_get_options_from_help)"
 
473
    else
 
474
        # Default complete with a filename
 
475
        _filedir
 
476
    fi
 
477
}
 
478
__grub_script_check_program=$( echo grub-script-check | sed "@program_transform_name@" )
 
479
have ${__grub_script_check_program} && \
 
480
 complete -F _grub_script-check -o filenames ${__grub_script_check_program}
 
481
 
 
482
 
 
483
# Local variables:
 
484
# mode: shell-script
 
485
# sh-basic-offset: 4
 
486
# sh-indent-comment: t
 
487
# indent-tabs-mode: nil
 
488
# End:
 
489
# ex: ts=4 sw=4 et filetype=sh