Linux MultiMedia Card development
 help / color / mirror / Atom feed
From: Torstein Eide <torsteine@gmail.com>
To: linux-mmc@vger.kernel.org
Cc: Torstein Eide <torsteine+linux@gmail.com>
Subject: [PATCH 4/4] mmc-utils: Add bash completion
Date: Fri, 15 May 2026 10:34:57 +0200	[thread overview]
Message-ID: <20260515083457.3690804-5-torsteine+linux@gmail.com> (raw)
In-Reply-To: <20260515083457.3690804-1-torsteine+linux@gmail.com>

Add a bash completion script in completion/mmc that completes subcommands
and /dev/mmcblkN device paths for all mmc commands.

The completion directory is named 'completion/' rather than
'bash-completion/' so shell-specific scripts for other shells (zsh,
fish, etc.) can be placed alongside it without renaming.

Add bashcompletiondir variable to the Makefile (defaulting to the
standard /usr/share/bash-completion/completions) and install the
script as part of 'make install'. The install path can be overridden
at build time with make bashcompletiondir=<path>.

Signed-off-by: Torstein Eide <torsteine+linux@gmail.com>
---
 Makefile       |  5 +++-
 completion/mmc | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++
 docs/HOWTO.rst |  6 +++++
 3 files changed, 72 insertions(+), 1 deletion(-)
 create mode 100644 completion/mmc

diff --git a/Makefile b/Makefile
index 11685b9..e447e54 100644
--- a/Makefile
+++ b/Makefile
@@ -5,6 +5,8 @@ AM_CFLAGS = -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 \
 	    -DSD_IDS_PATH=\"$(idsdir)/sdcard.ids\" \
 	    -DMMC_IDS_PATH=\"$(idsdir)/multimediacard.ids\"
 CFLAGS ?= -g -O2
+idsdir = /usr/share/misc
+bashcompletiondir = /usr/share/bash-completion/completions
 objects = \
 	mmc.o \
 	mmc_cmds.o \
@@ -21,7 +23,6 @@ override CFLAGS := $(CHECKFLAGS) $(AM_CFLAGS) $(CFLAGS)
 INSTALL = install
 prefix ?= /usr/local
 bindir = $(prefix)/bin
-idsdir ?= /usr/share/misc
 LIBS=
 RESTORE_LIBS=
 mandir = /usr/share/man
@@ -61,6 +62,8 @@ install: $(progs)
 	$(INSTALL) -m755 -d $(DESTDIR)$(idsdir)
 	$(INSTALL) -m 644 sdcard.ids $(DESTDIR)$(idsdir)
 	$(INSTALL) -m 644 multimediacard.ids $(DESTDIR)$(idsdir)
+	$(INSTALL) -m755 -d $(DESTDIR)$(bashcompletiondir)
+	$(INSTALL) -m 644 completion/mmc $(DESTDIR)$(bashcompletiondir)/mmc
 
 -include $(foreach obj,$(objects), $(dir $(obj))/.$(notdir $(obj)).d)
 
diff --git a/completion/mmc b/completion/mmc
new file mode 100644
index 0000000..07e4c25
--- /dev/null
+++ b/completion/mmc
@@ -0,0 +1,62 @@
+_mmc_complete() {
+	local cur prev words cword
+	_init_completion || return
+
+	local devices
+	devices=$(compgen -G "/dev/mmcblk[0-9]" 2>/dev/null)
+
+	case $cword in
+	1)
+		local verbs="extcsd writeprotect disable gp enh_area \
+			write_reliability status bootpart bootbus hwreset bkops \
+			sanitize rpmb cache csd cid scr ffu opt_ffu1 opt_ffu2 \
+			opt_ffu3 opt_ffu4 erase gen_cmd softreset preidle \
+			boot_operation list"
+		COMPREPLY=($(compgen -W "$verbs" -- "$cur"))
+		;;
+	2)
+		case $prev in
+		extcsd)
+			COMPREPLY=($(compgen -W "read write" -- "$cur")) ;;
+		writeprotect)
+			COMPREPLY=($(compgen -W "boot user" -- "$cur")) ;;
+		bootpart)
+			COMPREPLY=($(compgen -W "enable" -- "$cur")) ;;
+		bootbus)
+			COMPREPLY=($(compgen -W "set" -- "$cur")) ;;
+		hwreset)
+			COMPREPLY=($(compgen -W "enable disable" -- "$cur")) ;;
+		bkops)
+			COMPREPLY=($(compgen -W "enable" -- "$cur")) ;;
+		rpmb)
+			COMPREPLY=($(compgen -W "read-counter read-block write-block write-key" -- "$cur")) ;;
+		cache)
+			COMPREPLY=($(compgen -W "enable disable" -- "$cur")) ;;
+		csd|cid|scr)
+			COMPREPLY=($(compgen -W "read" -- "$cur")) ;;
+		gen_cmd)
+			COMPREPLY=($(compgen -W "read" -- "$cur")) ;;
+		status)
+			COMPREPLY=($(compgen -W "get" -- "$cur")) ;;
+		gp)
+			COMPREPLY=($(compgen -W "create" -- "$cur")) ;;
+		enh_area|write_reliability)
+			COMPREPLY=($(compgen -W "set" -- "$cur")) ;;
+		sanitize|softreset|preidle|ffu|opt_ffu1|opt_ffu2|opt_ffu3|opt_ffu4|erase|boot_operation)
+			COMPREPLY=($(compgen -W "$devices" -- "$cur")) ;;
+		esac
+		;;
+	3)
+		case ${words[1]} in
+		writeprotect)
+			COMPREPLY=($(compgen -W "get set" -- "$cur")) ;;
+		csd|cid|scr|extcsd|gen_cmd|status|bootpart|bootbus|hwreset|bkops|cache|gp|enh_area|write_reliability)
+			COMPREPLY=($(compgen -W "$devices" -- "$cur")) ;;
+		esac
+		;;
+	*)
+		COMPREPLY=($(compgen -W "$devices" -- "$cur")) ;;
+	esac
+}
+
+complete -F _mmc_complete mmc
diff --git a/docs/HOWTO.rst b/docs/HOWTO.rst
index 167a153..460d016 100644
--- a/docs/HOWTO.rst
+++ b/docs/HOWTO.rst
@@ -2,6 +2,12 @@
 
 Running mmc-utils
 -----------------
+**Bash completion**
+    Source ``completion/mmc`` to enable tab-completion for all subcommands and
+    device paths. When installed via ``make install``, the file is placed in
+    ``$(bashcompletiondir)`` (default: ``/usr/share/bash-completion/completions/mmc``)
+    and loaded automatically by bash-completion.
+
 **Name**
     mmc - a tool for configuring MMC storage devices
 **Synopsis**
-- 
2.53.0


  parent reply	other threads:[~2026-05-15  8:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-15  8:34 [PATCH 0/4] mmc-utils: improve lsmmc usability Torstein Eide
2026-05-15  8:34 ` [PATCH 1/4] mmc-utils: lsmmc: Use external .ids files for manufacturer lookup Torstein Eide
2026-05-15 15:05   ` Avri Altman
2026-05-15  8:34 ` [PATCH 2/4] mmc-utils: lsmmc: Accept /dev and /sys/block paths for register reads Torstein Eide
2026-05-15 15:26   ` Avri Altman
2026-05-15  8:34 ` [PATCH 3/4] mmc-utils: lsmmc: Add mmc list command Torstein Eide
2026-05-15  8:34 ` Torstein Eide [this message]
2026-05-15 14:29 ` [PATCH 0/4] mmc-utils: improve lsmmc usability Avri Altman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260515083457.3690804-5-torsteine+linux@gmail.com \
    --to=torsteine@gmail.com \
    --cc=linux-mmc@vger.kernel.org \
    --cc=torsteine+linux@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox