dmidecode-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] bash: add completions


From: Ville Skyttä
Subject: [PATCH] bash: add completions
Date: Sat, 22 Jul 2023 22:55:31 +0300

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ä <ville.skytta@iki.fi>
---
 Makefile        | 14 ++++++--
 biosdecode.bash | 40 +++++++++++++++++++++
 dmidecode.bash  | 95 +++++++++++++++++++++++++++++++++++++++++++++++++
 ownership.bash  | 33 +++++++++++++++++
 vpddecode.bash  | 45 +++++++++++++++++++++++
 5 files changed, 225 insertions(+), 2 deletions(-)
 create mode 100644 biosdecode.bash
 create mode 100644 dmidecode.bash
 create mode 100644 ownership.bash
 create mode 100644 vpddecode.bash

diff --git a/Makefile b/Makefile
index 7aa729d..66dc2d9 100644
--- a/Makefile
+++ b/Makefile
@@ -36,6 +36,7 @@ sbindir = $(prefix)/sbin
 mandir  = $(prefix)/share/man
 man8dir = $(mandir)/man8
 docdir  = $(prefix)/share/doc/dmidecode
+compdir = $(shell pkg-config --variable=completionsdir bash-completion 
2>/dev/null || echo $(prefix)/etc/bash_completion.d)
 
 INSTALL         := install
 INSTALL_DATA    := $(INSTALL) -m 644
@@ -113,9 +114,9 @@ util.o : util.c types.h util.h config.h
 strip : $(PROGRAMS)
        strip $(PROGRAMS)
 
-install : install-bin install-man install-doc
+install : install-bin install-man install-doc install-completion
 
-uninstall : uninstall-bin uninstall-man uninstall-doc
+uninstall : uninstall-bin uninstall-man uninstall-doc uninstall-completion
 
 install-bin : $(PROGRAMS)
        $(INSTALL_DIR) $(DESTDIR)$(sbindir)
@@ -144,5 +145,14 @@ install-doc :
 uninstall-doc :
        $(RM) -r $(DESTDIR)$(docdir)
 
+install-completion :
+       $(INSTALL_DIR) $(DESTDIR)$(compdir)
+       for program in $(PROGRAMS) ; do \
+       $(INSTALL_DATA) $$program.bash $(DESTDIR)$(compdir)/$$program ; done
+
+uninstall-completion :
+       for program in $(PROGRAMS) ; do \
+       $(RM) $(DESTDIR)$(compdir)/$$program ; done
+
 clean :
        $(RM) *.o $(PROGRAMS) core
diff --git a/biosdecode.bash b/biosdecode.bash
new file mode 100644
index 0000000..42e0fae
--- /dev/null
+++ b/biosdecode.bash
@@ -0,0 +1,40 @@
+# bash completion for biosdecode                           -*- shell-script -*-
+
+_comp_cmd_biosdecode() {
+       local cur prev
+       COMPREPLY=()
+       cur=${COMP_WORDS[COMP_CWORD]}
+       prev=${COMP_WORDS[COMP_CWORD - 1]}
+
+       case $prev in
+       -d | --dev-mem)
+               : "${cur:=/dev/}"
+               local IFS=$'\n'
+               compopt -o filenames
+               COMPREPLY=($(compgen -f -- "$cur"))
+               return 0
+               ;;
+       --pir)
+               COMPREPLY=($(compgen -W '
+                       full
+               ' -- "$cur"))
+               return 0
+               ;;
+       -[hV] | --help | --version)
+               return 0
+               ;;
+       esac
+
+       if [[ $cur == -* ]]; then
+               COMPREPLY=($(compgen -W '
+                       --dev-mem
+                       --pir
+                       --help
+                       --version
+               ' -- "$cur"))
+               return 0
+       fi
+
+} && complete -F _comp_cmd_biosdecode biosdecode
+
+# ex: filetype=sh
diff --git a/dmidecode.bash b/dmidecode.bash
new file mode 100644
index 0000000..9b659a9
--- /dev/null
+++ b/dmidecode.bash
@@ -0,0 +1,95 @@
+# bash completion for dmidecode                            -*- shell-script -*-
+
+_comp_cmd_dmidecode() {
+       local cur prev
+       COMPREPLY=()
+       cur=${COMP_WORDS[COMP_CWORD]}
+       prev=${COMP_WORDS[COMP_CWORD - 1]}
+
+       case $prev in
+       -d | --dev-mem | --dump-bin | --from-dump)
+               if [[ $prev == -d || $prev == --dev-mem ]]; then
+                       : "${cur:=/dev/}"
+               fi
+               local IFS=$'\n'
+               compopt -o filenames
+               COMPREPLY=($(compgen -f -- "$cur"))
+               return 0
+               ;;
+       -s | --string)
+               COMPREPLY=($(compgen -W '
+                       bios-vendor
+                       bios-version
+                       bios-release-date
+                       bios-revision
+                       firmware-revision
+                       system-manufacturer
+                       system-product-name
+                       system-version
+                       system-serial-number
+                       system-uuid
+                       system-sku-number
+                       system-family
+                       baseboard-manufacturer
+                       baseboard-product-name
+                       baseboard-version
+                       baseboard-serial-number
+                       baseboard-asset-tag
+                       chassis-manufacturer
+                       chassis-type
+                       chassis-version
+                       chassis-serial-number
+                       chassis-asset-tag
+                       processor-family
+                       processor-manufacturer
+                       processor-version
+                       processor-frequency
+               ' -- "$cur"))
+               return 0
+               ;;
+       -t | --type)
+               COMPREPLY=($(compgen -W '
+                       bios
+                       system
+                       baseboard
+                       chassis
+                       processor
+                       memory
+                       cache
+                       connector
+                       slot
+               ' -- "$cur"))
+               return 0
+               ;;
+       --dump-bin | --from-dump)
+               local IFS=$'\n'
+               compopt -o filenames
+               COMPREPLY=($(compgen -f -- "$cur"))
+               return 0
+               ;;
+       -[hVH] | --help | --version | --handle | --oem-string)
+               return 0
+               ;;
+       esac
+
+       if [[ $cur == -* ]]; then
+               COMPREPLY=($(compgen -W '
+                       --dev-mem
+                       --help
+                       --quiet
+                       --string
+                       --type
+                       --handle
+                       --dump
+                       --dump-bin
+                       --from-dump
+                       --no-sysfs
+                       --oem-string
+                       --version
+               ' -- "$cur"))
+               return 0
+       fi
+
+} && complete -F _comp_cmd_dmidecode dmidecode
+
+# ex: filetype=sh
diff --git a/ownership.bash b/ownership.bash
new file mode 100644
index 0000000..6a25d29
--- /dev/null
+++ b/ownership.bash
@@ -0,0 +1,33 @@
+# bash completion for ownership                            -*- shell-script -*-
+
+_comp_cmd_ownership() {
+       local cur prev
+       COMPREPLY=()
+       cur=${COMP_WORDS[COMP_CWORD]}
+       prev=${COMP_WORDS[COMP_CWORD - 1]}
+
+       case $prev in
+       -d | --dev-mem)
+               : "${cur:=/dev/}"
+               local IFS=$'\n'
+               compopt -o filenames
+               COMPREPLY=($(compgen -f -- "$cur"))
+               return 0
+               ;;
+       -[hV] | --help | --version)
+               return 0
+               ;;
+       esac
+
+       if [[ $cur == -* ]]; then
+               COMPREPLY=($(compgen -W '
+                       --dev-mem
+                       --help
+                       --version
+               ' -- "$cur"))
+               return 0
+       fi
+
+} && complete -F _comp_cmd_ownership ownership
+
+# ex: filetype=sh
diff --git a/vpddecode.bash b/vpddecode.bash
new file mode 100644
index 0000000..85ef2eb
--- /dev/null
+++ b/vpddecode.bash
@@ -0,0 +1,45 @@
+# bash completion for vpddecode                            -*- shell-script -*-
+
+_comp_cmd_vpddecode() {
+       local cur prev
+       COMPREPLY=()
+       cur=${COMP_WORDS[COMP_CWORD]}
+       prev=${COMP_WORDS[COMP_CWORD - 1]}
+
+       case $prev in
+       -d | --dev-mem)
+               : "${cur:=/dev/}"
+               local IFS=$'\n'
+               compopt -o filenames
+               COMPREPLY=($(compgen -f -- "$cur"))
+               return 0
+               ;;
+       -s | --string)
+               COMPREPLY=($(compgen -W '
+                       bios-build-id
+                       box-serial-number
+                       motherboard-serial-number
+                       machine-type-model
+                       bios-release-date
+               ' -- "$cur"))
+               return 0
+               ;;
+       -[hV] | --help | --version)
+               return 0
+               ;;
+       esac
+
+       if [[ $cur == -* ]]; then
+               COMPREPLY=($(compgen -W '
+                       --dev-mem
+                       --help
+                       --string
+                       --dump
+                       --version
+               ' -- "$cur"))
+               return 0
+       fi
+
+} && complete -F _comp_cmd_vpddecode vpddecode
+
+# ex: filetype=sh
-- 
2.25.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]