Skip to content

Commit 6fc53b3

Browse files
scopjdelvare
authored andcommitted
bash: add completions
Offer only long options, but recognize short ones, too, per rationale at https://github.com/scop/bash-completion/blob/4d0bffb791c34c96114aeb2e4f6726b80aa8698e/CONTRIBUTING.md?plain=1#L136-L153 Signed-off-by: Ville Skyttä <[email protected]>
1 parent 7dea248 commit 6fc53b3

File tree

5 files changed

+198
-2
lines changed

5 files changed

+198
-2
lines changed

Makefile

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ sbindir = $(prefix)/sbin
3636
mandir = $(prefix)/share/man
3737
man8dir = $(mandir)/man8
3838
docdir = $(prefix)/share/doc/dmidecode
39+
compdir = $(shell pkg-config --variable=completionsdir bash-completion 2>/dev/null || echo $(prefix)/etc/bash_completion.d)
3940

4041
INSTALL := install
4142
INSTALL_DATA := $(INSTALL) -m 644
@@ -113,9 +114,9 @@ util.o : util.c types.h util.h config.h
113114
strip : $(PROGRAMS)
114115
strip $(PROGRAMS)
115116

116-
install : install-bin install-man install-doc
117+
install : install-bin install-man install-doc install-completion
117118

118-
uninstall : uninstall-bin uninstall-man uninstall-doc
119+
uninstall : uninstall-bin uninstall-man uninstall-doc uninstall-completion
119120

120121
install-bin : $(PROGRAMS)
121122
$(INSTALL_DIR) $(DESTDIR)$(sbindir)
@@ -144,5 +145,18 @@ install-doc :
144145
uninstall-doc :
145146
$(RM) -r $(DESTDIR)$(docdir)
146147

148+
install-completion :
149+
if [ -d $(compdir) ] ; then \
150+
$(INSTALL_DIR) $(DESTDIR)$(compdir) ; \
151+
for program in $(PROGRAMS) ; do \
152+
$(INSTALL_DATA) completion/$$program.bash $(DESTDIR)$(compdir)/$$program ; done ; \
153+
fi
154+
155+
uninstall-completion :
156+
if [ -d $(DESTDIR)$(compdir) ]; then \
157+
for program in $(PROGRAMS) ; do \
158+
$(RM) $(DESTDIR)$(compdir)/$$program ; done ; \
159+
fi
160+
147161
clean :
148162
$(RM) *.o $(PROGRAMS) core

completion/biosdecode.bash

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# bash completion for biosdecode -*- shell-script -*-
2+
3+
_comp_cmd_biosdecode() {
4+
local cur prev
5+
COMPREPLY=()
6+
cur=${COMP_WORDS[COMP_CWORD]}
7+
prev=${COMP_WORDS[COMP_CWORD - 1]}
8+
9+
case $prev in
10+
-d | --dev-mem)
11+
: "${cur:=/dev/}"
12+
local IFS=$'\n'
13+
compopt -o filenames
14+
COMPREPLY=($(compgen -f -- "$cur"))
15+
return 0
16+
;;
17+
--pir)
18+
COMPREPLY=($(compgen -W '
19+
full
20+
' -- "$cur"))
21+
return 0
22+
;;
23+
-[hV] | --help | --version)
24+
return 0
25+
;;
26+
esac
27+
28+
if [[ $cur == -* ]]; then
29+
COMPREPLY=($(compgen -W '
30+
--dev-mem
31+
--pir
32+
--help
33+
--version
34+
' -- "$cur"))
35+
return 0
36+
fi
37+
38+
} && complete -F _comp_cmd_biosdecode biosdecode
39+
40+
# ex: filetype=sh

completion/dmidecode.bash

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# bash completion for dmidecode -*- shell-script -*-
2+
3+
_comp_cmd_dmidecode() {
4+
local cur prev
5+
COMPREPLY=()
6+
cur=${COMP_WORDS[COMP_CWORD]}
7+
prev=${COMP_WORDS[COMP_CWORD - 1]}
8+
9+
case $prev in
10+
-d | --dev-mem | --dump-bin | --from-dump)
11+
if [[ $prev == -d || $prev == --dev-mem ]]; then
12+
: "${cur:=/dev/}"
13+
fi
14+
local IFS=$'\n'
15+
compopt -o filenames
16+
COMPREPLY=($(compgen -f -- "$cur"))
17+
return 0
18+
;;
19+
-s | --string)
20+
COMPREPLY=($(compgen -W '$(
21+
"$1" --string 2>&1 | while IFS=\$'\\n' read -r line ; do
22+
[[ $line == " "* ]] && printf "%s\n" "$line"
23+
done
24+
)' -- "$cur"))
25+
return 0
26+
;;
27+
-t | --type)
28+
COMPREPLY=($(compgen -W '$(
29+
"$1" --type 2>&1 | while IFS=\$'\\n' read -r line ; do
30+
[[ $line == " "* ]] && printf "%s\n" "$line"
31+
done
32+
)' -- "$cur"))
33+
return 0
34+
;;
35+
--dump-bin | --from-dump)
36+
local IFS=$'\n'
37+
compopt -o filenames
38+
COMPREPLY=($(compgen -f -- "$cur"))
39+
return 0
40+
;;
41+
-[hVH] | --help | --version | --handle | --oem-string)
42+
return 0
43+
;;
44+
esac
45+
46+
if [[ $cur == -* ]]; then
47+
COMPREPLY=($(compgen -W '
48+
--dev-mem
49+
--help
50+
--quiet
51+
--string
52+
--type
53+
--handle
54+
--dump
55+
--dump-bin
56+
--from-dump
57+
--no-sysfs
58+
--oem-string
59+
--version
60+
' -- "$cur"))
61+
return 0
62+
fi
63+
64+
} && complete -F _comp_cmd_dmidecode dmidecode
65+
66+
# ex: filetype=sh

completion/ownership.bash

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# bash completion for ownership -*- shell-script -*-
2+
3+
_comp_cmd_ownership() {
4+
local cur prev
5+
COMPREPLY=()
6+
cur=${COMP_WORDS[COMP_CWORD]}
7+
prev=${COMP_WORDS[COMP_CWORD - 1]}
8+
9+
case $prev in
10+
-d | --dev-mem)
11+
: "${cur:=/dev/}"
12+
local IFS=$'\n'
13+
compopt -o filenames
14+
COMPREPLY=($(compgen -f -- "$cur"))
15+
return 0
16+
;;
17+
-[hV] | --help | --version)
18+
return 0
19+
;;
20+
esac
21+
22+
if [[ $cur == -* ]]; then
23+
COMPREPLY=($(compgen -W '
24+
--dev-mem
25+
--help
26+
--version
27+
' -- "$cur"))
28+
return 0
29+
fi
30+
31+
} && complete -F _comp_cmd_ownership ownership
32+
33+
# ex: filetype=sh

completion/vpddecode.bash

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# bash completion for vpddecode -*- shell-script -*-
2+
3+
_comp_cmd_vpddecode() {
4+
local cur prev
5+
COMPREPLY=()
6+
cur=${COMP_WORDS[COMP_CWORD]}
7+
prev=${COMP_WORDS[COMP_CWORD - 1]}
8+
9+
case $prev in
10+
-d | --dev-mem)
11+
: "${cur:=/dev/}"
12+
local IFS=$'\n'
13+
compopt -o filenames
14+
COMPREPLY=($(compgen -f -- "$cur"))
15+
return 0
16+
;;
17+
-s | --string)
18+
COMPREPLY=($(compgen -W '$(
19+
"$1" --string 2>&1 | while IFS=\$'\\n' read -r line ; do
20+
[[ $line == " "* ]] && printf "%s\n" "$line"
21+
done
22+
' -- "$cur"))
23+
return 0
24+
;;
25+
-[hV] | --help | --version)
26+
return 0
27+
;;
28+
esac
29+
30+
if [[ $cur == -* ]]; then
31+
COMPREPLY=($(compgen -W '
32+
--dev-mem
33+
--help
34+
--string
35+
--dump
36+
--version
37+
' -- "$cur"))
38+
return 0
39+
fi
40+
41+
} && complete -F _comp_cmd_vpddecode vpddecode
42+
43+
# ex: filetype=sh

0 commit comments

Comments
 (0)