* [PATCH 1/1] mmc-utils: Add bash completion
@ 2026-05-12 17:12 Torstein Eide
2026-05-15 7:36 ` Avri Altman
0 siblings, 1 reply; 2+ messages in thread
From: Torstein Eide @ 2026-05-12 17:12 UTC (permalink / raw)
To: linux-mmc; +Cc: Torstein EIde
From: Torstein EIde <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>.
---
Makefile | 3 +++
completion/mmc | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++
docs/HOWTO.rst | 14 ++++++++++++
3 files changed, 79 insertions(+)
create mode 100644 completion/mmc
diff --git a/Makefile b/Makefile
index 11685b9..5389bf9 100644
--- a/Makefile
+++ b/Makefile
@@ -22,6 +22,7 @@ INSTALL = install
prefix ?= /usr/local
bindir = $(prefix)/bin
idsdir ?= /usr/share/misc
+bashcompletiondir ?= /usr/share/bash-completion/completions
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 45c440b..9a460e4 100644
--- a/docs/HOWTO.rst
+++ b/docs/HOWTO.rst
@@ -2,6 +2,13 @@
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.
+
+
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* RE: [PATCH 1/1] mmc-utils: Add bash completion
2026-05-12 17:12 [PATCH 1/1] mmc-utils: Add bash completion Torstein Eide
@ 2026-05-15 7:36 ` Avri Altman
0 siblings, 0 replies; 2+ messages in thread
From: Avri Altman @ 2026-05-15 7:36 UTC (permalink / raw)
To: Torstein Eide, linux-mmc@vger.kernel.org; +Cc: Torstein EIde
Hi Torstein,
> From: Torstein EIde <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>.
> ---
> Makefile | 3 +++
> completion/mmc | 62
> ++++++++++++++++++++++++++++++++++++++++++++++++++
> docs/HOWTO.rst | 14 ++++++++++++
> 3 files changed, 79 insertions(+)
> create mode 100644 completion/mmc
>
> diff --git a/Makefile b/Makefile
> index 11685b9..5389bf9 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -22,6 +22,7 @@ INSTALL = install
> prefix ?= /usr/local
> bindir = $(prefix)/bin
> idsdir ?= /usr/share/misc
depends on the .ids patch ?
Thanks for the patches - they look like nice and useful additions to mmc-utils. External .ids files, /dev/ path support, mmc list, and bash completion are all welcome improvements.
Unfortunately, I couldn't cleanly apply them - the diff hunks appear to be truncated (missing trailing context lines), which causes git am to fail with "corrupt patch" errors. This happens both when downloading from patchwork and via b4.
Better ordered as a series and resend.
Thanks,
Avri
> +bashcompletiondir ?= /usr/share/bash-completion/completions
> 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|g
> p|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 45c440b..9a460e4 100644
> --- a/docs/HOWTO.rst
> +++ b/docs/HOWTO.rst
> @@ -2,6 +2,13 @@
>
> 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.
> +
> +
>
> --
> 2.53.0
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-05-15 7:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-12 17:12 [PATCH 1/1] mmc-utils: Add bash completion Torstein Eide
2026-05-15 7:36 ` Avri Altman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.