Skip to content

Commit 062e8fd

Browse files
committed
Add bash-completion for some utilities
Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
1 parent 38ec3c6 commit 062e8fd

File tree

6 files changed

+168
-1
lines changed

6 files changed

+168
-1
lines changed

Makefile.in

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ projectdir = @projectdir@
2626
rulesdir = ${projectdir}/mk
2727

2828
libcdir := $(shell $(CURDIR)/tools/get-libc-dir)
29+
completionsdir := $(shell pkg-config --variable=completionsdir bash-completion 2>/dev/null ||:)
2930

3031
runtime_srcdir = runtime/src
3132
utils_srcdir = utils
@@ -418,7 +419,8 @@ installdirs:
418419
$(DESTDIR)$(execdir)/$(FEATURESDIR) \
419420
$(DESTDIR)$(runtimedir)/bin \
420421
$(DESTDIR)$(runtimedir)/sbin \
421-
$(DESTDIR)$(runtimedir)/$(libcdir)
422+
$(DESTDIR)$(runtimedir)/$(libcdir) \
423+
$(DESTDIR)$(completionsdir)
422424

423425
install: build-progs build-manpages installdirs
424426
$(Q)cp -at "$(DESTDIR)$(bindir)" -- $(addprefix $(dest_bindir)/,$(BIN_NAMES))
@@ -440,6 +442,8 @@ install: build-progs build-manpages installdirs
440442
$(Q)cp -at "$(DESTDIR)$(runtimedir)/bin" -- $(addprefix $(dest_data_bindir)/,$(RUNTIME_BIN_NAMES))
441443
$(Q)cp -at "$(DESTDIR)$(runtimedir)/sbin" -- $(addprefix $(dest_data_sbindir)/,$(RUNTIME_SBIN_NAMES))
442444
$(Q)cp -at "$(DESTDIR)$(runtimedir)/$(libcdir)" -- $(dest_data_libdir)/lib*
445+
$(Q)[ -z "$(completionsdir)" ] || \
446+
cp -at "$(DESTDIR)$(completionsdir)" -- $(wildcard contrib/bash-completion/*)
443447
ifneq ($(SCDOC),)
444448
$(Q)cp -at "$(DESTDIR)$(man1dir)" -- $(addprefix $(dest_man1dir)/,$(MANPAGE_NAMES))
445449
endif
@@ -454,4 +458,6 @@ uninstall:
454458
$(Q)rm -f -- $(addprefix $(DESTDIR)$(bindir)/,$(BIN_NAMES))
455459
$(Q)rm -f -- $(addprefix $(DESTDIR)$(sbindir)/,$(SBIN_NAMES))
456460
$(Q)rm -f -- $(addprefix $(DESTDIR)$(man1dir)/,$(MANPAGE_NAMES))
461+
$(Q)[ -z "$(completionsdir)" ] || \
462+
rm -f -- $(addprefix $(DESTDIR)$(completionsdir)/,$(notdir $(wildcard contrib/bash-completion/*)))
457463
$(Q)rm -rf -- $(DESTDIR)$(rulesdir) $(DESTDIR)$(projectdir) $(DESTDIR)$(execdir) $(DESTDIR)$(runtimedir)

contrib/bash-completion/depinfo

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
_depinfo()
2+
{
3+
local cur prev opts
4+
_init_completion || return
5+
6+
opts="
7+
-t --tree
8+
-D --no-deps
9+
-P --no-prefix
10+
-M --no-modules
11+
-F --no-firmware
12+
-B --no-builtin
13+
-k --set-version=
14+
-b --base-dir=
15+
-f --firmware-dir=
16+
--use-blacklist
17+
--missing-firmware
18+
-i --input=
19+
-V --version
20+
-h --help
21+
"
22+
23+
case "$prev" in
24+
-k|--set-version)
25+
local kernels=$(find /lib/modules -mindepth 1 -maxdepth 1 -type d -printf '%f ')
26+
COMPREPLY=( $(compgen -W "$kernels" -- "$cur") )
27+
return 0
28+
;;
29+
-b|--base-dir|-f|--firmware-dir)
30+
COMPREPLY=( $(compgen -d -- "$cur") )
31+
return 0
32+
;;
33+
-i|--input)
34+
COMPREPLY=( $(compgen -f -- "$cur") )
35+
return 0
36+
;;
37+
esac
38+
39+
if [[ "$cur" == -* ]]; then
40+
COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
41+
fi
42+
}
43+
complete -F _depinfo depinfo
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
_initrd_extract()
2+
{
3+
local cur prev opts
4+
_init_completion || return
5+
6+
opts="
7+
-a --archive=
8+
-o --output=
9+
-V --version
10+
-h --help
11+
"
12+
13+
if [[ "$cur" == -* ]]; then
14+
COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
15+
fi
16+
}
17+
complete -F _initrd_extract initrd-extract

contrib/bash-completion/initrd-ls

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
_initrd_ls()
2+
{
3+
local cur prev opts
4+
_init_completion || return
5+
6+
opts="
7+
--no-mtime
8+
-b --brief
9+
-n --name
10+
-C --compression
11+
-V --version
12+
-h --help
13+
"
14+
15+
if [[ "$cur" == -* ]]; then
16+
COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
17+
fi
18+
}
19+
complete -F _initrd_ls initrd-ls
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
_initrd_scanmod()
2+
{
3+
local cur prev opts
4+
_init_completion || return
5+
6+
opts="
7+
-k --set-version=
8+
-b --base-dir=
9+
-v --verbose
10+
-V --version
11+
-h --help
12+
"
13+
14+
case "$prev" in
15+
-k|--set-version)
16+
local kernels=$(find /lib/modules -mindepth 1 -maxdepth 1 -type d -printf '%f ')
17+
COMPREPLY=( $(compgen -W "$kernels" -- "$cur") )
18+
return 0
19+
;;
20+
-b|--base-dir)
21+
COMPREPLY=( $(compgen -d -- "$cur") )
22+
return 0
23+
;;
24+
esac
25+
26+
if [[ "$cur" == -* ]]; then
27+
COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
28+
fi
29+
}
30+
complete -F _initrd_scanmod initrd-scanmod
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
_make_initrd()
2+
{
3+
local cur prev words cword
4+
_init_completion || return
5+
6+
local subcommands="guess-modules guess-config bug-report feature-info uki"
7+
local opts="
8+
-D --no-depmod
9+
-N --no-checks
10+
-c --config=
11+
-b --bootdir=
12+
-k --kernel=
13+
-v --verbose
14+
-V --version
15+
-h --help
16+
"
17+
18+
case "${prev}" in
19+
-c|--config)
20+
_filedir
21+
return 0
22+
;;
23+
-b|--bootdir)
24+
_filedir -d
25+
return 0
26+
;;
27+
-k|--kernel)
28+
local kernels=$(find /lib/modules -mindepth 1 -maxdepth 1 -type d -printf '%f ')
29+
COMPREPLY=( $(compgen -W "$kernels" -- "$cur") )
30+
return 0
31+
;;
32+
feature-info)
33+
local features=$(make-initrd feature-info 2>/dev/null)
34+
COMPREPLY=( $(compgen -W "$features" -- "$cur") )
35+
return 0
36+
;;
37+
guess-modules)
38+
local devices=$(lsblk -ndo NAME 2>/dev/null | sed 's|^|/dev/|')
39+
local mounts=$(findmnt -nl -o TARGET)
40+
COMPREPLY=( $(compgen -W "$devices $mounts" -- "$cur") )
41+
__ltrim_colon_completions "$cur"
42+
return 0
43+
;;
44+
esac
45+
46+
if [[ ${COMP_CWORD} -eq 1 ]]; then
47+
COMPREPLY=( $(compgen -W "$subcommands $opts" -- "$cur") )
48+
else
49+
COMPREPLY+=( $(compgen -W "$opts" -- "$cur") )
50+
fi
51+
}
52+
complete -F _make_initrd make-initrd

0 commit comments

Comments
 (0)