Skip to content

Commit

Permalink
lilo: honor -C when completing labels
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Dec 7, 2019
1 parent 7dd16ad commit 5b12f1d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
12 changes: 10 additions & 2 deletions completions/lilo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
_lilo_labels()
{
COMPREPLY=( $(compgen -W "$(awk -F'=' '/label/ {print $2}' \
/etc/lilo.conf | command sed -e 's/\"//g')" -- "$cur") )
${1:-/etc/lilo.conf} 2>/dev/null | command sed -e 's/\"//g')" \
-- "$cur") )
}

_lilo()
Expand All @@ -22,7 +23,14 @@ _lilo()
;;
-I|-D|-R)
# label completion
_lilo_labels
local i conf
for i in ${!words[@]}; do
if [[ ${words[i]} == -C ]]; then
conf=${words[i+1]}
break
fi
done
_lilo_labels $conf
return
;;
-A|-b|-M|-u|-U)
Expand Down
34 changes: 34 additions & 0 deletions test/fixtures/lilo/lilo.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# global options:
boot=/dev/hda
prompt
timeout=150
lba32
compact
vga=normal
root=/dev/hda1
read-only
menu-title=" John's Computer "
#
### bootable kernel images ###
image=/boot/vmlinuz-2.6.29-1-i386
label=try
initrd=/boot/initrd.img-2.6.29-1-i386
image=/boot/vmlinuz-2.4.33-1-i386
label=2.4.33
image=/tamu/vmlinuz
label=tamu
initrd=/tamu/initrd.img
root=/dev/hdb2
vga=ask
#
### other operating systems ###
other=/dev/hda3
label=PCDOS
boot-as=0x80 # must be C:
other=/dev/hdb1
label=WinXP
boot-as=0x80 # must be C:
other=/dev/hdb5
label=oldDOS
loader=chain
table=/dev/hdb5
10 changes: 10 additions & 0 deletions test/t/test_lilo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@ class TestLilo:
@pytest.mark.complete("lilo -")
def test_1(self, completion):
assert completion

@pytest.mark.complete("lilo -C lilo/lilo.conf -D ")
def test_labels(self, completion):
assert completion == sorted(
"try 2.4.33 tamu PCDOS WinXP oldDOS".split()
)

@pytest.mark.complete("lilo -C -D ")
def test_labels_incorrect_command(self, completion):
assert not completion

0 comments on commit 5b12f1d

Please sign in to comment.