Skip to content
This repository was archived by the owner on Aug 27, 2025. It is now read-only.

Commit 53b8498

Browse files
committed
Handle 3rd-level arguments appropriately
Before, `vcgencmd vcos 0` would inappropriately suggest display numbers.
1 parent 1edfb4e commit 53b8498

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

host_applications/linux/apps/gencmd/vcgencmd-completion-test.bats

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ complete_command() {
4040
fi
4141
}
4242

43+
is_pi4() {
44+
grep -qE '^Model.* Raspberry Pi 4' /proc/cpuinfo
45+
}
46+
4347
@test "vcgencmd - -> -t -h --help" {
4448
complete_command "vcgencmd -"
4549
[[ "${COMPREPLY[*]}" == "-t -h --help" ]]
@@ -108,11 +112,31 @@ complete_command() {
108112
[[ "${COMPREPLY[*]}" == "0 1" ]]
109113
}
110114

115+
# Pi 4B has two hdmi pixel freq limits 0 and 1, Pi 2 and 3 just have one
111116
@test "get_config hdmi_pixel_freq_li -> hdmi_pixel_freq_limit:0" {
117+
if is_pi4; then
118+
skip "test only valid with 1 hdmi (earlier pi models)"
119+
fi
112120
complete_command "vcgencmd get_config hdmi_pixel_freq_li"
113121
[[ "${COMPREPLY[*]}" == "hdmi_pixel_freq_limit:0" ]]
114122
}
115123

124+
@test "get_config hdmi_pixel_freq_li -> hdmi_pixel_freq_limit:" {
125+
if ! is_pi4; then
126+
skip "test requires Pi 4 with 2 hdmi outputs"
127+
fi
128+
complete_command "vcgencmd get_config hdmi_pixel_freq_li"
129+
[[ "${COMPREPLY[*]}" == "hdmi_pixel_freq_limit:0 hdmi_pixel_freq_limit:1" ]]
130+
}
131+
132+
@test "get_config hdmi_pixel_freq_limit: -> 0 1" {
133+
if ! is_pi4; then
134+
skip "test requires Pi 4 with 2 hdmi outputs"
135+
fi
136+
complete_command "vcgencmd get_config hdmi_pixel_freq_limit:"
137+
[[ "${COMPREPLY[*]}" == "0 1" ]]
138+
}
139+
116140
@test "vcos -> version log" {
117141
complete_command "vcgencmd vcos "
118142
echo "${COMPREPLY[*]}" | grep -Ewo "(version|log)"
@@ -168,3 +192,8 @@ complete_command() {
168192
complete_command "vcgencmd -t vcos log "
169193
[[ "${COMPREPLY[*]}" == "status" ]]
170194
}
195+
196+
@test "vcos 0 -> (nothing)" {
197+
complete_command "vcgencmd vcos 0 "
198+
[[ "${#COMPREPLY[@]}" -eq 0 ]]
199+
}

host_applications/linux/apps/gencmd/vcgencmd-completion.bash

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,20 @@ _vcgencmd() {
9696
fi
9797

9898
if [[ $args -eq 3 ]]; then
99-
case "$prev" in
100-
0|1|-1)
101-
opts='0 1 2 3 7'
99+
case "${words[cword - 2]}" in
100+
display_power)
101+
case "$prev" in
102+
0|1|-1)
103+
opts='0 1 2 3 7'
104+
;;
105+
esac
102106
;;
103-
esac
104-
case "$prev" in
105-
log)
106-
opts='status'
107+
vcos)
108+
case "$prev" in
109+
log)
110+
opts='status'
111+
;;
112+
esac
107113
;;
108114
esac
109115
fi

0 commit comments

Comments
 (0)