Skip to contentSkip to conversation

bash-completion

GIT PULL In review Sami Kerola 3 participants 33 messages Mar 27, 2013 – Apr 5, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hello,

Here is a pull request, which does two things; an introduction of bash completetion to util-linux, and most FIXME items ever sent to review in single batch (26).

Most of the brokenness in this batch series has got to do with a comma separate value list, e.g., 'value1,another,foobar', which one would expect to continue filling with 'value1,<tab>' but that does not work. I am almost sure that one might achieve continue the list by setting comma to COMP_WORDBREAKS, and check if $prev is in known words list, but I simply did not get that to work (I suspect PEBKAC).

Some FIXME's are slightly more difficult to fix. For example I do not know how to get list of possible TERM values distribution agnostic way. And with 'wdctl' I have no how to determine flags. Same goes for SELinux labels & Apparmor provilles for setpriv. Anyhow, if someone wants to help, give hints, or even directly fix something feel free to reply the later patches what could be done to an instance of a problem.

Of course any other sort of feedback is also welcome.

The following changes since commit 4cd271adc1dd3231e705c9e074491a7f49a721b8:

libmount: make mnt_table_find_* more robust [coverity scan] (2013-03-27 16:47:46 +0100)

are available in the git repository at:

git://github.com/kerolasa/lelux-utiliteetit.git shell-completion

for you to fetch changes up to e8b90f9baffd36a95bab408a3859b04543577a1b:

bash-completion: add completion files to Makefile.am (2013-03-27 21:31:25 +0000)

----------------------------------------------------------------
Sami Kerola (10):
bash-completion: add bash completetion configure option
bash-completion: disk-utils
bash-completion: fdisks
bash-completion: login-utils
bash-completion: misc-utils
bash-completion: schedutils
bash-completion: sys-utils
bash-completion: term-utils
bash-completion: text-utils
bash-completion: add completion files to Makefile.am

 Documentation/TODO             |   6 -
 Makefile.am                    |   5 +
 configure.ac                   |  13 +++
 shell-completion/Makemodule.am | 260 +++++++++++++++++++++++++++++++++++++++++
 shell-completion/addpart       |  25 ++++
 shell-completion/agetty        |  70 +++++++++++
 shell-completion/blkdiscard    |  25 ++++
 shell-completion/blkid         |  62 ++++++++++
 shell-completion/blockdev      |  44 +++++++
 shell-completion/cal           |  15 +++
 shell-completion/cfdisk        |  31 +++++
 shell-completion/chcpu         |  44 +++++++
 shell-completion/chfn          |  31 +++++
 shell-completion/chrt          |  32 +++++
 shell-completion/chsh          |  23 ++++
 shell-completion/col           |  24 ++++
 shell-completion/colcrt        |  20 ++++
 shell-completion/colrm         |  23 ++++
 shell-completion/column        |  34 ++++++
 shell-completion/ctrlaltdel    |  11 ++
 shell-completion/cytune        |  37 ++++++
 shell-completion/delpart       |  19 +++
 shell-completion/dmesg         |  53 +++++++++
 shell-completion/eject         |  61 ++++++++++
 shell-completion/fallocate     |  24 ++++
 shell-completion/fdformat      |  11 ++
 shell-completion/fdisk         |  41 +++++++
 shell-completion/findmnt       | 114 ++++++++++++++++++
 shell-completion/flock         |  42 +++++++
 shell-completion/fsck          |  36 ++++++
 shell-completion/fsck.cramfs   |  18 +++
 shell-completion/fsck.minix    |  11 ++
 shell-completion/fsfreeze      |  18 +++
 shell-completion/fstrim        |  25 ++++
 shell-completion/getopt        |  34 ++++++
 shell-completion/hexdump       |  32 +++++
 shell-completion/hwclock       |  53 +++++++++
 shell-completion/ionice        |  34 ++++++
 shell-completion/ipcrm         |  52 +++++++++
 shell-completion/ipcs          |  30 +++++
 shell-completion/isosize       |  17 +++
 shell-completion/last          |  38 ++++++
 shell-completion/ldattach      |  54 +++++++++
 shell-completion/logger        |  43 +++++++
 shell-completion/login         |  27 +++++
 shell-completion/look          |  24 ++++
 shell-completion/losetup       |  64 ++++++++++
 shell-completion/lsblk         |  60 ++++++++++
 shell-completion/lscpu         |  39 +++++++
 shell-completion/lslocks       |  43 +++++++
 shell-completion/mcookie       |  23 ++++
 shell-completion/mesg          |  16 +++
 shell-completion/mkfs          |  25 ++++
 shell-completion/mkfs.bfs      |  28 +++++
 shell-completion/mkfs.cramfs   |  40 +++++++
 shell-completion/mkfs.minix    |  33 ++++++
 shell-completion/mkswap        |  36 ++++++
 shell-completion/more          |  22 ++++
 shell-completion/mountpoint    |  24 ++++
 shell-completion/namei         |  17 +++
 shell-completion/newgrp        |  16 +++
 shell-completion/nsenter       |  47 ++++++++
 shell-completion/partx         |  37 ++++++
 shell-completion/pg            |  29 +++++
 shell-completion/pivot_root    |  14 +++
 shell-completion/prlimit       |  55 +++++++++
 shell-completion/raw           |  17 +++
 shell-completion/readprofile   |  33 ++++++
 shell-completion/rename        |  27 +++++
 shell-completion/renice        |  38 ++++++
 shell-completion/resizepart    |  22 ++++
 shell-completion/rev           |  17 +++
 shell-completion/rtcwake       |  40 +++++++
 shell-completion/script        |  38 ++++++
 shell-completion/scriptreplay  |  28 +++++
 shell-completion/setarch       |  42 +++++++
 shell-completion/setpriv       |  82 +++++++++++++
 shell-completion/setsid        |  17 +++
 shell-completion/setterm       | 109 +++++++++++++++++
 shell-completion/sfdisk        |  72 ++++++++++++
 shell-completion/su            |  45 +++++++
 shell-completion/sulogin       |  24 ++++
 shell-completion/swaplabel     |  28 +++++
 shell-completion/swapon        |  48 ++++++++
 shell-completion/tailf         |  24 ++++
 shell-completion/taskset       |  38 ++++++
 shell-completion/tunelp        |  48 ++++++++
 shell-completion/ul            |  25 ++++
 shell-completion/unshare       |  24 ++++
 shell-completion/utmpdump      |  17 +++
 shell-completion/uuidd         |  33 ++++++
 shell-completion/uuidgen       |  15 +++
 shell-completion/wall          |  24 ++++
 shell-completion/wdctl         |  48 ++++++++
 shell-completion/whereis       |  24 ++++
 shell-completion/wipefs        |  38 ++++++
 shell-completion/write         |  19 +++
 97 files changed, 3512 insertions(+), 6 deletions(-)
 create mode 100644 shell-completion/Makemodule.am
 create mode 100644 shell-completion/addpart
 create mode 100644 shell-completion/agetty
 create mode 100644 shell-completion/blkdiscard
 create mode 100644 shell-completion/blkid
 create mode 100644 shell-completion/blockdev
 create mode 100644 shell-completion/cal
 create mode 100644 shell-completion/cfdisk
 create mode 100644 shell-completion/chcpu
 create mode 100644 shell-completion/chfn
 create mode 100644 shell-completion/chrt
 create mode 100644 shell-completion/chsh
 create mode 100644 shell-completion/col
 create mode 100644 shell-completion/colcrt
 create mode 100644 shell-completion/colrm
 create mode 100644 shell-completion/column
 create mode 100644 shell-completion/ctrlaltdel
 create mode 100644 shell-completion/cytune
 create mode 100644 shell-completion/delpart
 create mode 100644 shell-completion/dmesg
 create mode 100644 shell-completion/eject
 create mode 100644 shell-completion/fallocate
 create mode 100644 shell-completion/fdformat
 create mode 100644 shell-completion/fdisk
 create mode 100644 shell-completion/findmnt
 create mode 100644 shell-completion/flock
 create mode 100644 shell-completion/fsck
 create mode 100644 shell-completion/fsck.cramfs
 create mode 100644 shell-completion/fsck.minix
 create mode 100644 shell-completion/fsfreeze
 create mode 100644 shell-completion/fstrim
 create mode 100644 shell-completion/getopt
 create mode 100644 shell-completion/hexdump
 create mode 100644 shell-completion/hwclock
 create mode 100644 shell-completion/ionice
 create mode 100644 shell-completion/ipcrm
 create mode 100644 shell-completion/ipcs
 create mode 100644 shell-completion/isosize
 create mode 100644 shell-completion/last
 create mode 100644 shell-completion/ldattach
 create mode 100644 shell-completion/logger
 create mode 100644 shell-completion/login
 create mode 100644 shell-completion/look
 create mode 100644 shell-completion/losetup
 create mode 100644 shell-completion/lsblk
 create mode 100644 shell-completion/lscpu
 create mode 100644 shell-completion/lslocks
 create mode 100644 shell-completion/mcookie
 create mode 100644 shell-completion/mesg
 create mode 100644 shell-completion/mkfs
 create mode 100644 shell-completion/mkfs.bfs
 create mode 100644 shell-completion/mkfs.cramfs
 create mode 100644 shell-completion/mkfs.minix
 create mode 100644 shell-completion/mkswap
 create mode 100644 shell-completion/more
 create mode 100644 shell-completion/mountpoint
 create mode 100644 shell-completion/namei
 create mode 100644 shell-completion/newgrp
 create mode 100644 shell-completion/nsenter
 create mode 100644 shell-completion/partx
 create mode 100644 shell-completion/pg
 create mode 100644 shell-completion/pivot_root
 create mode 100644 shell-completion/prlimit
 create mode 100644 shell-completion/raw
 create mode 100644 shell-completion/readprofile
 create mode 100644 shell-completion/rename
 create mode 100644 shell-completion/renice
 create mode 100644 shell-completion/resizepart
 create mode 100644 shell-completion/rev
 create mode 100644 shell-completion/rtcwake
 create mode 100644 shell-completion/script
 create mode 100644 shell-completion/scriptreplay
 create mode 100644 shell-completion/setarch
 create mode 100644 shell-completion/setpriv
 create mode 100644 shell-completion/setsid
 create mode 100644 shell-completion/setterm
 create mode 100644 shell-completion/sfdisk
 create mode 100644 shell-completion/su
 create mode 100644 shell-completion/sulogin
 create mode 100644 shell-completion/swaplabel
 create mode 100644 shell-completion/swapon
 create mode 100644 shell-completion/tailf
 create mode 100644 shell-completion/taskset
 create mode 100644 shell-completion/tunelp
 create mode 100644 shell-completion/ul
 create mode 100644 shell-completion/unshare
 create mode 100644 shell-completion/utmpdump
 create mode 100644 shell-completion/uuidd
 create mode 100644 shell-completion/uuidgen
 create mode 100644 shell-completion/wall
 create mode 100644 shell-completion/wdctl
 create mode 100644 shell-completion/whereis
 create mode 100644 shell-completion/wipefs
 create mode 100644 shell-completion/write
#1 lore raw

PATCH 1/10 bash-completion: add bash completetion configure option

---
 Makefile.am                    |  5 +++++
 configure.ac                   | 13 +++++++++++++
 shell-completion/Makemodule.am |  1 +
 3 files changed, 19 insertions(+)
 create mode 100644 shell-completion/Makemodule.am
Makefile.am +5 -0
index 3afcad1..b963af9 100644
@@ -27,6 +27,8 @@ ul_libfdisk_incdir  = $(top_srcdir)/libfdisk/src
 
 pkgconfigdir = $(usrlib_execdir)/pkgconfig
 
+bashcompletiondir = @bashcompletiondir@
+
 dist_noinst_HEADERS =
 noinst_PROGRAMS =
 noinst_LTLIBRARIES =
@@ -87,6 +89,8 @@ include misc-utils/Makemodule.am
 include disk-utils/Makemodule.am
 include fdisks/Makemodule.am
 
+include shell-completion/Makemodule.am
+
 include tests/Makemodule.am
 
 #
@@ -158,6 +162,7 @@ checkdecl:
 ENABLE_ALL = --enable-static-programs --enable-most-builds
 DISTCHECK_CONFIGURE_FLAGS = --disable-use-tty-group \
 			    --disable-silent-rules $(ENABLE_ALL) \
+			    --with-bashcompletiondir=$$dc_install_base/$(bashcompletiondir) \
 			    --with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir)
 
 
configure.ac +13 -0
index 92a5a3b..cd4e826 100644
@@ -1342,6 +1342,18 @@ fi
 AM_CONDITIONAL(HAVE_SYSTEMD, [test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != "xno" ])
 
 
+AC_ARG_WITH([bashcompletiondir],
+  AS_HELP_STRING([--with-bashcompletiondir=DIR], [Bash completions directory]),
+  [],
+  [AS_IF([$($PKG_CONFIG --exists bash-completion)], [
+    with_bashcompletiondir=$($PKG_CONFIG --variable=completionsdir bash-completion)
+  ], [
+    with_bashcompletiondir=${datadir}/bash-completion/completions
+  ])
+])
+AC_SUBST([bashcompletiondir], [$with_bashcompletiondir])
+
+
 AC_ARG_ENABLE([pg-bell],
   AS_HELP_STRING([--disable-pg-bell], [let pg not ring the bell on invalid keys]),
   [], enable_pg_bell=yes
@@ -1463,6 +1475,7 @@ AC_MSG_RESULT([
 	suid cflags:       ${SUID_CFLAGS}
 	ldflags:           ${LDFLAGS}
 	suid ldflags:      ${SUID_LDFLAGS}
+	Bash completions dir: ${with_bashcompletiondir}
 
 	warnings:
 
shell-completion/Makemodule.am new file +1 -0
new file mode 100644
index 0000000..b784ec7
@@ -0,0 +1 @@
+dist_bashcompletion_DATA =
Signature · 1 line
1.8.2
#2 lore raw

Re: [PATCH 01/10] bash-completion: add bash completetion configure option

Quoted 7 lines · Sami Kerola
---
 Makefile.am                    |  5 +++++
 configure.ac                   | 13 +++++++++++++
 shell-completion/Makemodule.am |  1 +
 3 files changed, 19 insertions(+)
 create mode 100644 shell-completion/Makemodule.am

Do we need './configure --disable-overwriting-bash-compilation-package-files'? I realized some of the files I wrote will conflicting with the

http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=tree;f=completions

Signature · 2 lines
   Sami Kerola
   http://www.iki.fi/kerolasa/
maintainer
#3 lore raw

Re: [PATCH 01/10] bash-completion: add bash completetion configure option

Quoted 11 lines · Sami Kerola
Quoted 7 lines · Sami Kerola
---
 Makefile.am                    |  5 +++++
 configure.ac                   | 13 +++++++++++++
 shell-completion/Makemodule.am |  1 +
 3 files changed, 19 insertions(+)
 create mode 100644 shell-completion/Makemodule.am

Do we need './configure --disable-overwriting-bash-compilation-package-files'?

Hmm... not sure, it's distro specific decision/policy.

Maybe we need --disable-bash-completion, it should enough.

Quoted 1 line

I realized some of the files I wrote will conflicting with the

Which files? We can add some info to ReleaseNotes to make it easy for distros.

Quoted 1 line

http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=tree;f=completions

What about to use .ul (or .util-linux) suffix for the conflicting files and in the bash-completion package check for these files and use it if exists? See for example:

http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=blob;f=completions/umount

CC: to [email protected], maybe they already have any idea how to resolve the conflicts between packages.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#4 lore raw

PATCH 2/10 bash-completion: disk-utils

In reply to Sami Kerola
---
 shell-completion/addpart     | 25 +++++++++++++++++++++++++
 shell-completion/blockdev    | 44 ++++++++++++++++++++++++++++++++++++++++++++
 shell-completion/delpart     | 19 +++++++++++++++++++
 shell-completion/fdformat    | 11 +++++++++++
 shell-completion/fsck        | 36 ++++++++++++++++++++++++++++++++++++
 shell-completion/fsck.cramfs | 18 ++++++++++++++++++
 shell-completion/fsck.minix  | 11 +++++++++++
 shell-completion/isosize     | 17 +++++++++++++++++
 shell-completion/mkfs        | 25 +++++++++++++++++++++++++
 shell-completion/mkfs.bfs    | 28 ++++++++++++++++++++++++++++
 shell-completion/mkfs.cramfs | 40 ++++++++++++++++++++++++++++++++++++++++
 shell-completion/mkfs.minix  | 33 +++++++++++++++++++++++++++++++++
 shell-completion/mkswap      | 36 ++++++++++++++++++++++++++++++++++++
 shell-completion/partx       | 37 +++++++++++++++++++++++++++++++++++++
 shell-completion/raw         | 17 +++++++++++++++++
 shell-completion/resizepart  | 22 ++++++++++++++++++++++
 shell-completion/swaplabel   | 28 ++++++++++++++++++++++++++++
 17 files changed, 447 insertions(+)
 create mode 100644 shell-completion/addpart
 create mode 100644 shell-completion/blockdev
 create mode 100644 shell-completion/delpart
 create mode 100644 shell-completion/fdformat
 create mode 100644 shell-completion/fsck
 create mode 100644 shell-completion/fsck.cramfs
 create mode 100644 shell-completion/fsck.minix
 create mode 100644 shell-completion/isosize
 create mode 100644 shell-completion/mkfs
 create mode 100644 shell-completion/mkfs.bfs
 create mode 100644 shell-completion/mkfs.cramfs
 create mode 100644 shell-completion/mkfs.minix
 create mode 100644 shell-completion/mkswap
 create mode 100644 shell-completion/partx
 create mode 100644 shell-completion/raw
 create mode 100644 shell-completion/resizepart
 create mode 100644 shell-completion/swaplabel
shell-completion/addpart new file +25 -0
new file mode 100644
index 0000000..07ebf5e
@@ -0,0 +1,25 @@
+_addpart_module()
+{
+	local cur
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $COMP_CWORD in
+		1)
+			local DEVS
+			DEVS="$(lsblk -o NAME -n -r)"
+			OPTS="-h --help -V --version $DEVS"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			;;
+		2)
+			COMPREPLY=( $(compgen -W "$((1 + $(ls $prev?* 2>/dev/null | wc -l)))" -- $cur) )
+			;;
+		3)
+			COMPREPLY=( $(compgen -W "start" -- $cur) )
+			;;
+		4)
+			COMPREPLY=( $(compgen -W "length" -- $cur) )
+			;;
+	esac
+	return 0
+}
+complete -F _addpart_module addpart
shell-completion/blockdev new file +44 -0

44 lines not on this page · raw message

shell-completion/delpart new file +19 -0
new file mode 100644
index 0000000..849c018
@@ -0,0 +1,19 @@
+_delpart_module()
+{
+	local cur OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $COMP_CWORD in
+		1)
+			local DEVS
+			DEVS="$(lsblk -o NAME,TYPE -n -r | awk '$2 ~ /disk/ {print "/dev/" $1}')"
+			OPTS="-h --help -V --version $DEVS"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			;;
+		2)
+			COMPREPLY=( $(compgen -W "$(cat /sys/block/${prev##*/}/*/partition 2>/dev/null)" -- $cur) )
+			;;
+	esac
+	return 0
+}
+complete -F _delpart_module delpart
shell-completion/fdformat new file +11 -0
new file mode 100644
index 0000000..f7d6a8e
@@ -0,0 +1,11 @@
+_fdformat_module()
+{
+	local cur OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	DEVS=$(ls /dev/fd[0-9]* 2>/dev/null)
+	OPTS="-n --no-verify -h --help -V --version $DEVS"
+	COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+	return 0
+}
+complete -F _fdformat_module fdformat
shell-completion/fsck new file +36 -0
new file mode 100644
index 0000000..c3da5f5
@@ -0,0 +1,36 @@
+_fsck_module()
+{
+	local cur prev OPTS DEVS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-b')
+			COMPREPLY=( $(compgen -W "superblock" -- $cur) )
+			return 0
+			;;
+		'-B')
+			COMPREPLY=( $(compgen -W "blocksize" -- $cur) )
+			return 0
+			;;
+		'-j')
+			COMPREPLY=( $(compgen -W "external_journal" -- $cur) )
+			return 0
+			;;
+		'-l'|'-L')
+			COMPREPLY=( $(compgen -W "bad_blocks_file" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-p -n -y -c -f -v -b -B -j -l -L"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	DEVS="$(lsblk -o NAME -n -r | awk '{print "/dev/" $1}')"
+	COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
+	return 0
+}
+complete -F _fsck_module fsck
shell-completion/fsck.cramfs new file +18 -0
new file mode 100644
index 0000000..410b084
@@ -0,0 +1,18 @@
+_fsck.cramfs_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	OPTS='-v --verbose -x --destination -h --help -V --version file'
+	case $prev in
+		'-x'|'--destination')
+			compopt -o filenames
+			COMPREPLY=( $(compgen -o dirnames -- ${cur:-"/"}) )
+			return 0
+			;;
+	esac
+	COMPREPLY=( $(compgen -W "${OPTS[*]}" -S ' ' -- $cur) )
+	return 0
+}
+complete -F _fsck.cramfs_module fsck.cramfs
shell-completion/fsck.minix new file +11 -0
new file mode 100644
index 0000000..f01626a
@@ -0,0 +1,11 @@
+_fsck.minix_module()
+{
+	local cur OPTS DEVS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	DEVS="$(lsblk -o NAME -n -r | awk '{print "/dev/" $1}')"
+	OPTS="-l -a -r -v -s -m -f -V --version"
+	COMPREPLY=( $(compgen -W "${OPTS[*]} $DEVS" -- $cur) )
+	return 0
+}
+complete -F _fsck.minix_module fsck.minix
shell-completion/isosize new file +17 -0
new file mode 100644
index 0000000..2b4a499
@@ -0,0 +1,17 @@
+_isosize_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	OPTS='-d --divisor -x --sectors -h --help -V --version'
+	case $prev in
+		'-d'|'--divisor')
+			COMPREPLY=( $(compgen -W "number" -- $cur) )
+			return 0
+			;;
+	esac
+	COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+	return 0
+}
+complete -F _isosize_module isosize
shell-completion/mkfs new file +25 -0
new file mode 100644
index 0000000..ee6a26b
@@ -0,0 +1,25 @@
+_mkfs_module()
+{
+	local cur prev OPTS DEVS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-t'|'--type')
+			FSTYPES=$(for I in $(\ls /sbin/mkfs.* /usr/sbin/mkfs.* 2>/dev/null); do echo ${I##*mkfs.}; done)
+			COMPREPLY=( $(compgen -W "$FSTYPES" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS='-t --type --verbose -h --help -V --version'
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	DEVS="$(lsblk -o NAME -n -r | awk '{print "/dev/" $1}')"
+	COMPREPLY=( $(compgen -W "$DEVS /path/to/file" -- $cur) )
+	return 0
+}
+complete -F _mkfs_module mkfs
shell-completion/mkfs.bfs new file +28 -0
new file mode 100644
index 0000000..b1a226a
@@ -0,0 +1,28 @@
+_bfs_module()
+{
+	local cur prev OPTS DEVS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-N'|'--inodes')
+			COMPREPLY=( $(compgen -W "number" -- $cur) )
+			return 0
+			;;
+		'-V'|'--vname'|'-F'|'--fname')
+			COMPREPLY=( $(compgen -W "name" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS='-N --inodes --vname --fname -v --verbose -h --help -V --version'
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	DEVS="$(lsblk -o NAME -n -r | awk '{print "/dev/" $1}')"
+	COMPREPLY=( $(compgen -W "$DEVS /path/to/file" -- $cur) )
+	return 0
+}
+complete -F _bfs_module bfs
shell-completion/mkfs.cramfs new file +40 -0
new file mode 100644
index 0000000..65ee988
@@ -0,0 +1,40 @@
+_mkfs.cramfs_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-b')
+			COMPREPLY=( $(compgen -W "blksize" -- $cur) )
+			return 0
+			;;
+		'-e')
+			COMPREPLY=( $(compgen -W "edition" -- $cur) )
+			return 0
+			;;
+		'-N')
+			COMPREPLY=( $(compgen -W "big little host" -- $cur) )
+			return 0
+			;;
+		'-i')
+			COMPREPLY=( $(compgen -f -- $cur) )
+			return 0
+			;;
+		'-n')
+			COMPREPLY=( $(compgen -W "name" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-h -v -E -b -e -N -i -n -p -s -z"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _mkfs.cramfs_module mkfs.cramfs
shell-completion/mkfs.minix new file +33 -0
new file mode 100644
index 0000000..c717b3c
@@ -0,0 +1,33 @@
+_mkfs.minix_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-i')
+			COMPREPLY=( $(compgen -W "inodes" -- $cur) )
+			return 0
+			;;
+		'-l')
+			COMPREPLY=( $(compgen -W "badblocks-file" -- $cur) )
+			return 0
+			;;
+		'-n')
+			COMPREPLY=( $(compgen -W "14 30" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-c -i -l -n -1 -2 -3"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	local DEVS
+	DEVS="$(lsblk -o NAME -n -r | awk '{print "/dev/" $1}')"
+	COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
+	return 0
+}
+complete -F _mkfs.minix_module mkfs.minix
shell-completion/mkswap new file +36 -0
new file mode 100644
index 0000000..c847aa9
@@ -0,0 +1,36 @@
+_mkswap_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-p'|'--pagesize')
+			COMPREPLY=( $(compgen -W "bytes" -- $cur) )
+			return 0
+			;;
+		'-L'|'--label')
+			COMPREPLY=( $(compgen -W "label" -- $cur) )
+			return 0
+			;;
+		'-v'|'--swapversion')
+			COMPREPLY=( $(compgen -W "1" -- $cur) )
+			return 0
+			;;
+		'-U'|--uuid)
+			COMPREPLY=( $(compgen -W "$(lsblk -n --output uuid)" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-c --check -f --force -p --pagesize -L  --label -v --swapversion -U --uuid -V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _mkswap_module mkswap
shell-completion/partx new file +37 -0
new file mode 100644
index 0000000..c558d36
@@ -0,0 +1,37 @@
+_partx_module()
+{
+	local cur prev OPTS OUTPUT
+	COMPREPLY=()
+	OUTPUT="NR START END SECTORS SIZE NAME UUID TYPE FLAGS SCHEME"
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-n'|'--nr')
+			COMPREPLY=( $(compgen -W "$(lsblk -o NAME,TYPE -n -r | awk '$2 ~ /part/ {print "/dev/" $1}')" -- $cur) )
+			return 0
+			;;
+		'-o'|'--output')
+			# FIXME: how to append to a string with compgen?
+			compopt -o nospace
+			COMPREPLY=( $(compgen -W "$OUTPUT" -S ',' -- $cur) )
+			return 0
+			;;
+		'-t'|'--type')
+			# FIXME: some command should list type libblkid knows.
+			COMPREPLY=( $(compgen -W "aix bsd dos gpt mac minix sgi solaris_x86 sun ultrix unixware" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-a --add -d --delete -s --show -u --update -b --bytes -g --noheadings -n --nr -o --output -P --pairs -r --raw -t --type -v --verbose -h --help -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	local DEVS
+	DEVS="$(sblk -o NAME,TYPE -n -r | awk '$2 ~ /disk/ {print "/dev/" $1}')"
+	COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
+	return 0
+}
+complete -F _partx_module partx
shell-completion/raw new file +17 -0
new file mode 100644
index 0000000..41e03f2
@@ -0,0 +1,17 @@
+_raw_module()
+{
+	local cur
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $cur in
+		-*)
+			local OPTS
+			OPTS="-q --query -a --all -h --help -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	COMPREPLY=( $(compgen -W "$(ls 2>/dev/null /dev/raw/*)" -- $cur) )
+	return 0
+}
+complete -F _raw_module raw
shell-completion/resizepart new file +22 -0
new file mode 100644
index 0000000..827638a
@@ -0,0 +1,22 @@
+_resizepart_module()
+{
+	local cur OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $COMP_CWORD in
+		1)
+			local DEVS
+			DEVS="$(lsblk -o NAME,TYPE -n -r | awk '$2 ~ /disk/ {print "/dev/" $1}')"
+			OPTS="-h --help -V --version $DEVS"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			;;
+		2)
+			COMPREPLY=( $(compgen -W "$(cat /sys/block/${prev##*/}/*/partition 2>/dev/null)" -- $cur) )
+			;;
+		3)
+			COMPREPLY="length"
+			;;
+	esac
+	return 0
+}
+complete -F _resizepart_module resizepart
shell-completion/swaplabel new file +28 -0
new file mode 100644
index 0000000..c857d15
@@ -0,0 +1,28 @@
+_swaplabel_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-L'|'--label')
+			COMPREPLY=( $(compgen -W "label" -- $cur) )
+			return 0
+			;;
+		'-U'|'--uuid')
+			COMPREPLY=( $(compgen -W '$(uuidgen)' -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-L --label -U --uuid -h --help -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _swaplabel_module swaplabel
Signature · 1 line
1.8.2
#5 lore raw

Re: [PATCH 02/10] bash-completion: disk-utils

Quoted 45 lines · Sami Kerola
---
 shell-completion/addpart     | 25 +++++++++++++++++++++++++
 shell-completion/blockdev    | 44 ++++++++++++++++++++++++++++++++++++++++++++
 shell-completion/delpart     | 19 +++++++++++++++++++
 shell-completion/fdformat    | 11 +++++++++++
 shell-completion/fsck        | 36 ++++++++++++++++++++++++++++++++++++
 shell-completion/fsck.cramfs | 18 ++++++++++++++++++
 shell-completion/fsck.minix  | 11 +++++++++++
 shell-completion/isosize     | 17 +++++++++++++++++
 shell-completion/mkfs        | 25 +++++++++++++++++++++++++
 shell-completion/mkfs.bfs    | 28 ++++++++++++++++++++++++++++
 shell-completion/mkfs.cramfs | 40 ++++++++++++++++++++++++++++++++++++++++
 shell-completion/mkfs.minix  | 33 +++++++++++++++++++++++++++++++++
 shell-completion/mkswap      | 36 ++++++++++++++++++++++++++++++++++++
 shell-completion/partx       | 37 +++++++++++++++++++++++++++++++++++++
 shell-completion/raw         | 17 +++++++++++++++++
 shell-completion/resizepart  | 22 ++++++++++++++++++++++
 shell-completion/swaplabel   | 28 ++++++++++++++++++++++++++++
 17 files changed, 447 insertions(+)
 create mode 100644 shell-completion/addpart
 create mode 100644 shell-completion/blockdev
 create mode 100644 shell-completion/delpart
 create mode 100644 shell-completion/fdformat
 create mode 100644 shell-completion/fsck
 create mode 100644 shell-completion/fsck.cramfs
 create mode 100644 shell-completion/fsck.minix
 create mode 100644 shell-completion/isosize
 create mode 100644 shell-completion/mkfs
 create mode 100644 shell-completion/mkfs.bfs
 create mode 100644 shell-completion/mkfs.cramfs
 create mode 100644 shell-completion/mkfs.minix
 create mode 100644 shell-completion/mkswap
 create mode 100644 shell-completion/partx
 create mode 100644 shell-completion/raw
 create mode 100644 shell-completion/resizepart
 create mode 100644 shell-completion/swaplabel
shell-completion/addpart new file +1 -0
new file mode 100644
index 0000000..07ebf5e
@@ -0,0 +1,25 @@
+_addpart_module()

shell-completion/addpart line 11

Quoted 10 lines
shell-completion/addpart new file +10 -0
+{
+	local cur
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $COMP_CWORD in
+		1)
+			local DEVS
+			DEVS="$(lsblk -o NAME -n -r)"
+			OPTS="-h --help -V --version $DEVS"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )

You've defined OPTS as a simple string variable and then you're expanding it as an array. Make sure to localize any variables you might define in the completion function as well, or else they leak to the user's environment (DEVS, OPTS). In general, I'd recommend *against* using all capitalized variable names, particularly for local variables.

shell-completion/addpart line 14

Quoted 3 lines
shell-completion/addpart new file +3 -0
+			;;
+		2)
+			COMPREPLY=( $(compgen -W "$((1 + $(ls $prev?* 2>/dev/null | wc -l)))" -- $cur) )

Please don't use ls to count items in a directory. It's slightly longer winded, but bash does this just fine without forking:

filecount=0
files=("$prev"?*)
[[ -e ${files[0]} ]] && filecount=${#files[*]}

This advice and the above apply to a bunch of your patches.

Quoted 67 lines
shell-completion/addpart new file +11 -0
+			;;
+		3)
+			COMPREPLY=( $(compgen -W "start" -- $cur) )
+			;;
+		4)
+			COMPREPLY=( $(compgen -W "length" -- $cur) )
+			;;
+	esac
+	return 0
+}
+complete -F _addpart_module addpart
shell-completion/blockdev new file +44 -0
new file mode 100644
index 0000000..82ac6c1
@@ -0,0 +1,44 @@
+_blockdev_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	DEVS="$(lsblk -o NAME -n -r)"
+	OPTS="-h -V -q
+		--report
+		--getsz
+		--setro
+		--setrw
+		--getro
+		--getdiscardzeroes
+		--getss
+		--getpbsz
+		--getiomin
+		--getioopt
+		--getalignoff
+		--getmaxsect
+		--getbsz
+		--setbsz
+		--getsize64
+		--setra
+		--getra
+		--setfra
+		--getfra
+		--flushbufs
+		--rereadpt
+		$DEVS"
+	case $prev in
+		'--setbsz')
+			COMPREPLY=( $(compgen -W "bytes" -- $cur) )
+			return 0
+			;;
+		'--setbsz'|'--setfra')
+			COMPREPLY=( $(compgen -W "sectors" -- $cur) )
+			return 0
+			;;
+	esac
+	COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+	return 0
+}
+complete -F _blockdev_module blockdev
shell-completion/delpart new file +0 -0
new file mode 100644
index 0000000..849c018

shell-completion/delpart line 9

Quoted 9 lines
shell-completion/delpart new file +9 -0
@@ -0,0 +1,19 @@
+_delpart_module()
+{
+	local cur OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $COMP_CWORD in
+		1)
+			local DEVS
+			DEVS="$(lsblk -o NAME,TYPE -n -r | awk '$2 ~ /disk/ {print "/dev/" $1}')"

local dev typ
while read dev typ; do

    [[ $dev = 'disk' ]] && devices+=("/dev/$dev")

done < <(lsblk -nro name,type)

shell-completion/delpart line 14

Quoted 5 lines
shell-completion/delpart new file +5 -0
+			OPTS="-h --help -V --version $DEVS"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			;;
+		2)
+			COMPREPLY=( $(compgen -W "$(cat /sys/block/${prev##*/}/*/partition 2>/dev/null)" -- $cur) )

Bash has a builtin "cat" which uses mmap instead of direct reads, and is far more efficient:

  COMPREPLY=( $(compgen -W "$(</sys/block/"${prev##*/}"/*/partition 2>/dev/null)" -- $cur) )
Quoted 455 lines
shell-completion/delpart new file +5 -0
+			;;
+	esac
+	return 0
+}
+complete -F _delpart_module delpart
shell-completion/fdformat new file +11 -0
new file mode 100644
index 0000000..f7d6a8e
@@ -0,0 +1,11 @@
+_fdformat_module()
+{
+	local cur OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	DEVS=$(ls /dev/fd[0-9]* 2>/dev/null)
+	OPTS="-n --no-verify -h --help -V --version $DEVS"
+	COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+	return 0
+}
+complete -F _fdformat_module fdformat
shell-completion/fsck new file +36 -0
new file mode 100644
index 0000000..c3da5f5
@@ -0,0 +1,36 @@
+_fsck_module()
+{
+	local cur prev OPTS DEVS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-b')
+			COMPREPLY=( $(compgen -W "superblock" -- $cur) )
+			return 0
+			;;
+		'-B')
+			COMPREPLY=( $(compgen -W "blocksize" -- $cur) )
+			return 0
+			;;
+		'-j')
+			COMPREPLY=( $(compgen -W "external_journal" -- $cur) )
+			return 0
+			;;
+		'-l'|'-L')
+			COMPREPLY=( $(compgen -W "bad_blocks_file" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-p -n -y -c -f -v -b -B -j -l -L"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	DEVS="$(lsblk -o NAME -n -r | awk '{print "/dev/" $1}')"
+	COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
+	return 0
+}
+complete -F _fsck_module fsck
shell-completion/fsck.cramfs new file +18 -0
new file mode 100644
index 0000000..410b084
@@ -0,0 +1,18 @@
+_fsck.cramfs_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	OPTS='-v --verbose -x --destination -h --help -V --version file'
+	case $prev in
+		'-x'|'--destination')
+			compopt -o filenames
+			COMPREPLY=( $(compgen -o dirnames -- ${cur:-"/"}) )
+			return 0
+			;;
+	esac
+	COMPREPLY=( $(compgen -W "${OPTS[*]}" -S ' ' -- $cur) )
+	return 0
+}
+complete -F _fsck.cramfs_module fsck.cramfs
shell-completion/fsck.minix new file +11 -0
new file mode 100644
index 0000000..f01626a
@@ -0,0 +1,11 @@
+_fsck.minix_module()
+{
+	local cur OPTS DEVS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	DEVS="$(lsblk -o NAME -n -r | awk '{print "/dev/" $1}')"
+	OPTS="-l -a -r -v -s -m -f -V --version"
+	COMPREPLY=( $(compgen -W "${OPTS[*]} $DEVS" -- $cur) )
+	return 0
+}
+complete -F _fsck.minix_module fsck.minix
shell-completion/isosize new file +17 -0
new file mode 100644
index 0000000..2b4a499
@@ -0,0 +1,17 @@
+_isosize_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	OPTS='-d --divisor -x --sectors -h --help -V --version'
+	case $prev in
+		'-d'|'--divisor')
+			COMPREPLY=( $(compgen -W "number" -- $cur) )
+			return 0
+			;;
+	esac
+	COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+	return 0
+}
+complete -F _isosize_module isosize
shell-completion/mkfs new file +25 -0
new file mode 100644
index 0000000..ee6a26b
@@ -0,0 +1,25 @@
+_mkfs_module()
+{
+	local cur prev OPTS DEVS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-t'|'--type')
+			FSTYPES=$(for I in $(\ls /sbin/mkfs.* /usr/sbin/mkfs.* 2>/dev/null); do echo ${I##*mkfs.}; done)
+			COMPREPLY=( $(compgen -W "$FSTYPES" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS='-t --type --verbose -h --help -V --version'
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	DEVS="$(lsblk -o NAME -n -r | awk '{print "/dev/" $1}')"
+	COMPREPLY=( $(compgen -W "$DEVS /path/to/file" -- $cur) )
+	return 0
+}
+complete -F _mkfs_module mkfs
shell-completion/mkfs.bfs new file +28 -0
new file mode 100644
index 0000000..b1a226a
@@ -0,0 +1,28 @@
+_bfs_module()
+{
+	local cur prev OPTS DEVS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-N'|'--inodes')
+			COMPREPLY=( $(compgen -W "number" -- $cur) )
+			return 0
+			;;
+		'-V'|'--vname'|'-F'|'--fname')
+			COMPREPLY=( $(compgen -W "name" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS='-N --inodes --vname --fname -v --verbose -h --help -V --version'
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	DEVS="$(lsblk -o NAME -n -r | awk '{print "/dev/" $1}')"
+	COMPREPLY=( $(compgen -W "$DEVS /path/to/file" -- $cur) )
+	return 0
+}
+complete -F _bfs_module bfs
shell-completion/mkfs.cramfs new file +40 -0
new file mode 100644
index 0000000..65ee988
@@ -0,0 +1,40 @@
+_mkfs.cramfs_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-b')
+			COMPREPLY=( $(compgen -W "blksize" -- $cur) )
+			return 0
+			;;
+		'-e')
+			COMPREPLY=( $(compgen -W "edition" -- $cur) )
+			return 0
+			;;
+		'-N')
+			COMPREPLY=( $(compgen -W "big little host" -- $cur) )
+			return 0
+			;;
+		'-i')
+			COMPREPLY=( $(compgen -f -- $cur) )
+			return 0
+			;;
+		'-n')
+			COMPREPLY=( $(compgen -W "name" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-h -v -E -b -e -N -i -n -p -s -z"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _mkfs.cramfs_module mkfs.cramfs
shell-completion/mkfs.minix new file +33 -0
new file mode 100644
index 0000000..c717b3c
@@ -0,0 +1,33 @@
+_mkfs.minix_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-i')
+			COMPREPLY=( $(compgen -W "inodes" -- $cur) )
+			return 0
+			;;
+		'-l')
+			COMPREPLY=( $(compgen -W "badblocks-file" -- $cur) )
+			return 0
+			;;
+		'-n')
+			COMPREPLY=( $(compgen -W "14 30" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-c -i -l -n -1 -2 -3"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	local DEVS
+	DEVS="$(lsblk -o NAME -n -r | awk '{print "/dev/" $1}')"
+	COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
+	return 0
+}
+complete -F _mkfs.minix_module mkfs.minix
shell-completion/mkswap new file +36 -0
new file mode 100644
index 0000000..c847aa9
@@ -0,0 +1,36 @@
+_mkswap_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-p'|'--pagesize')
+			COMPREPLY=( $(compgen -W "bytes" -- $cur) )
+			return 0
+			;;
+		'-L'|'--label')
+			COMPREPLY=( $(compgen -W "label" -- $cur) )
+			return 0
+			;;
+		'-v'|'--swapversion')
+			COMPREPLY=( $(compgen -W "1" -- $cur) )
+			return 0
+			;;
+		'-U'|--uuid)
+			COMPREPLY=( $(compgen -W "$(lsblk -n --output uuid)" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-c --check -f --force -p --pagesize -L  --label -v --swapversion -U --uuid -V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _mkswap_module mkswap
shell-completion/partx new file +37 -0
new file mode 100644
index 0000000..c558d36
@@ -0,0 +1,37 @@
+_partx_module()
+{
+	local cur prev OPTS OUTPUT
+	COMPREPLY=()
+	OUTPUT="NR START END SECTORS SIZE NAME UUID TYPE FLAGS SCHEME"
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-n'|'--nr')
+			COMPREPLY=( $(compgen -W "$(lsblk -o NAME,TYPE -n -r | awk '$2 ~ /part/ {print "/dev/" $1}')" -- $cur) )
+			return 0
+			;;
+		'-o'|'--output')
+			# FIXME: how to append to a string with compgen?
+			compopt -o nospace
+			COMPREPLY=( $(compgen -W "$OUTPUT" -S ',' -- $cur) )
+			return 0
+			;;
+		'-t'|'--type')
+			# FIXME: some command should list type libblkid knows.
+			COMPREPLY=( $(compgen -W "aix bsd dos gpt mac minix sgi solaris_x86 sun ultrix unixware" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-a --add -d --delete -s --show -u --update -b --bytes -g --noheadings -n --nr -o --output -P --pairs -r --raw -t --type -v --verbose -h --help -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	local DEVS
+	DEVS="$(sblk -o NAME,TYPE -n -r | awk '$2 ~ /disk/ {print "/dev/" $1}')"
+	COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
+	return 0
+}
+complete -F _partx_module partx
shell-completion/raw new file +17 -0
new file mode 100644
index 0000000..41e03f2
@@ -0,0 +1,17 @@
+_raw_module()
+{
+	local cur
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $cur in
+		-*)
+			local OPTS
+			OPTS="-q --query -a --all -h --help -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	COMPREPLY=( $(compgen -W "$(ls 2>/dev/null /dev/raw/*)" -- $cur) )
+	return 0
+}
+complete -F _raw_module raw
shell-completion/resizepart new file +22 -0
new file mode 100644
index 0000000..827638a
@@ -0,0 +1,22 @@
+_resizepart_module()
+{
+	local cur OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $COMP_CWORD in
+		1)
+			local DEVS
+			DEVS="$(lsblk -o NAME,TYPE -n -r | awk '$2 ~ /disk/ {print "/dev/" $1}')"
+			OPTS="-h --help -V --version $DEVS"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			;;
+		2)
+			COMPREPLY=( $(compgen -W "$(cat /sys/block/${prev##*/}/*/partition 2>/dev/null)" -- $cur) )
+			;;
+		3)
+			COMPREPLY="length"
+			;;
+	esac
+	return 0
+}
+complete -F _resizepart_module resizepart
shell-completion/swaplabel new file +28 -0
new file mode 100644
index 0000000..c857d15
@@ -0,0 +1,28 @@
+_swaplabel_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-L'|'--label')
+			COMPREPLY=( $(compgen -W "label" -- $cur) )
+			return 0
+			;;
+		'-U'|'--uuid')
+			COMPREPLY=( $(compgen -W '$(uuidgen)' -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-L --label -U --uuid -h --help -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _swaplabel_module swaplabel
Signature · 6 lines
1.8.2

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#6 lore raw

Re: [PATCH 02/10] bash-completion: disk-utils

Quoted 11 lines · Dave Reisner

shell-completion/addpart line 11

Quoted 4 lines · Sami Kerola
shell-completion/addpart new file +4 -0
+			local DEVS
+			DEVS="$(lsblk -o NAME -n -r)"
+			OPTS="-h --help -V --version $DEVS"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )

You've defined OPTS as a simple string variable and then you're expanding it as an array. Make sure to localize any variables you might define in the completion function as well, or else they leak to the user's environment (DEVS, OPTS). In general, I'd recommend *against* using all capitalized variable names, particularly for local variables.

I made attempt to find non-localized variables, and correct them. It could be that there are still some left.

Quoted 7 lines

shell-completion/addpart line 14

Quoted 3 lines
shell-completion/addpart new file +3 -0
+			;;
+		2)
+			COMPREPLY=( $(compgen -W "$((1 + $(ls $prev?* 2>/dev/null | wc -l)))" -- $cur) )

Please don't use ls to count items in a directory. It's slightly longer winded, but bash does this just fine without forking:

Quoted 5 lines

filecount=0
files=("$prev"?*)
[[ -e ${files[0]} ]] && filecount=${#files[*]}

This advice and the above apply to a bunch of your patches.

All instances of 'ls' execution are gone.

Quoted 12 lines

shell-completion/delpart line 9

Quoted 9 lines
shell-completion/delpart new file +9 -0
+_delpart_module()
+{
+	local cur OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $COMP_CWORD in
+		1)
+			local DEVS
+			DEVS="$(lsblk -o NAME,TYPE -n -r | awk '$2 ~ /disk/ {print "/dev/" $1}')"

local dev typ
while read dev typ; do

Quoted 2 lines
    [[ $dev = 'disk' ]] && devices+=("/dev/$dev")

done < <(lsblk -nro name,type)

Changed to version you proposed.

Quoted 10 lines

shell-completion/delpart line 14

Quoted 5 lines
shell-completion/delpart new file +5 -0
+			OPTS="-h --help -V --version $DEVS"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			;;
+		2)
+			COMPREPLY=( $(compgen -W "$(cat /sys/block/${prev##*/}/*/partition 2>/dev/null)" -- $cur) )

Bash has a builtin "cat" which uses mmap instead of direct reads, and is far more efficient:

  COMPREPLY=( $(compgen -W "$(</sys/block/"${prev##*/}"/*/partition 2>/dev/null)" -- $cur) )

I left that as-is. Reading from a bunch of files would require a loop, which and I don't think avoiding cat is worth of the mess.

Thank you for advice Dave.

Signature · 2 lines
   Sami Kerola
   http://www.iki.fi/kerolasa/
maintainer
#7 lore raw

Re: [PATCH 02/10] bash-completion: disk-utils

In reply to Sami Kerola
Quoted 6 lines · Sami Kerola
shell-completion/mkfs new file +0 -0
new file mode 100644
index 0000000..ee6a26b

shell-completion/mkfs line 9

Quoted 9 lines
shell-completion/mkfs new file +9 -0
@@ -0,0 +1,25 @@
+_mkfs_module()
+{
+	local cur prev OPTS DEVS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-t'|'--type')
+			FSTYPES=$(for I in $(\ls /sbin/mkfs.* /usr/sbin/mkfs.* 2>/dev/null); do echo ${I##*mkfs.}; done)

The /sbin and /usr/sbin are the same directories on many systems, so you need to de-duplicate the list or use only one directory (I suggest /sbin).

Quoted 17 lines
shell-completion/mkswap new file +11 -0
new file mode 100644
index 0000000..c847aa9
@@ -0,0 +1,36 @@
+_mkswap_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-p'|'--pagesize')
+			COMPREPLY=( $(compgen -W "bytes" -- $cur) )
+			return 0
+			;;

shell-completion/mkswap line 21

Quoted 10 lines
shell-completion/mkswap new file +10 -0
+		'-L'|'--label')
+			COMPREPLY=( $(compgen -W "label" -- $cur) )
+			return 0
+			;;
+		'-v'|'--swapversion')
+			COMPREPLY=( $(compgen -W "1" -- $cur) )
+			return 0
+			;;
+		'-U'|--uuid)
+			COMPREPLY=( $(compgen -W "$(lsblk -n --output uuid)" -- $cur) )

The -U|--uuid is not a device identifier here, it's UUID you want to use for the new swap superblock. So ask lsblk does not make sense. (It will generate duplicate UUIDS.)

If you do not specify -U then mkswap will generate a new.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#8 lore raw

Re: [PATCH 02/10] bash-completion: disk-utils

Quoted 11 lines · Karel Zak
Quoted 10 lines · Sami Kerola
shell-completion/mkfs new file +4 -0
new file mode 100644
index 0000000..ee6a26b
@@ -0,0 +1,25 @@
+_mkfs_module()
+{
+	local cur prev OPTS DEVS
+	COMPREPLY=()
Quoted 8 lines

shell-completion/mkfs line 9

Quoted 5 lines
shell-completion/mkfs new file +5 -0
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-t'|'--type')
+			FSTYPES=$(for I in $(\ls /sbin/mkfs.* /usr/sbin/mkfs.* 2>/dev/null); do echo ${I##*mkfs.}; done)

The /sbin and /usr/sbin are the same directories on many systems, so you need to de-duplicate the list or use only one directory (I suggest /sbin).

The compgen will remove duplicates. Perhaps most systems now a days has /sbin -> /usr/sbin symlink, but because that cannot be guaranteed I would rather let the later command to sort out duplicates than being over clever about what is necessary.

Quoted 32 lines
Quoted 17 lines
shell-completion/mkswap new file +11 -0
new file mode 100644
index 0000000..c847aa9
@@ -0,0 +1,36 @@
+_mkswap_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-p'|'--pagesize')
+			COMPREPLY=( $(compgen -W "bytes" -- $cur) )
+			return 0
+			;;

shell-completion/mkswap line 21

Quoted 10 lines
shell-completion/mkswap new file +10 -0
+		'-L'|'--label')
+			COMPREPLY=( $(compgen -W "label" -- $cur) )
+			return 0
+			;;
+		'-v'|'--swapversion')
+			COMPREPLY=( $(compgen -W "1" -- $cur) )
+			return 0
+			;;
+		'-U'|--uuid)
+			COMPREPLY=( $(compgen -W "$(lsblk -n --output uuid)" -- $cur) )

The -U|--uuid is not a device identifier here, it's UUID you want to use for the new swap superblock. So ask lsblk does not make sense. (It will generate duplicate UUIDS.)

Quoted 1 line

If you do not specify -U then mkswap will generate a new.

Fixed.

Signature · 2 lines
   Sami Kerola
   http://www.iki.fi/kerolasa/
#9 lore raw

PATCH 3/10 bash-completion: fdisks

In reply to Sami Kerola
---
 shell-completion/cfdisk | 31 +++++++++++++++++++++
 shell-completion/fdisk  | 41 ++++++++++++++++++++++++++++
 shell-completion/sfdisk | 72 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 144 insertions(+)
 create mode 100644 shell-completion/cfdisk
 create mode 100644 shell-completion/fdisk
 create mode 100644 shell-completion/sfdisk
shell-completion/cfdisk new file +31 -0
new file mode 100644
index 0000000..8da32fd
@@ -0,0 +1,31 @@
+_cfdisk_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-c')
+			COMPREPLY=( $(compgen -W "cylinders" -- $cur) )
+			return 0
+			;;
+		'-h')
+			COMPREPLY=( $(compgen -W "heads" -- $cur) )
+			return 0
+			;;
+		'-s')
+			COMPREPLY=( $(compgen -W "sectors" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-a -z -c -h -s"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	COMPREPLY=( $(compgen -W "$(lsblk -o NAME,TYPE -n -r | awk '$2 ~ /disk/ {print "/dev/" $1}')" -- $cur) )
+	return 0
+}
+complete -F _cfdisk_module cfdisk
shell-completion/fdisk new file +41 -0

41 lines not on this page · raw message

shell-completion/sfdisk new file +72 -0

72 lines not on this page · raw message

Signature · 1 line
1.8.2
maintainer
#10 lore raw

Re: [PATCH 03/10] bash-completion: fdisks

Quoted 11 lines · Sami Kerola

+++ b/shell-completion/fdisk

shell-completion/fdisk new file +9 -0
@@ -0,0 +1,41 @@
+_fdisk_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-s')
+			local PARTITIONS

shell-completion/fdisk line 19

Quoted 10 lines
shell-completion/fdisk new file +10 -0
+			PARTITIONS="$(for I in /sys/block/*/*/partition; do IFS='/'; DIR_ARR=($I); echo "/dev/${DIR_ARR[4]}"; done)"
+			COMPREPLY=( $(compgen -W "$PARTITIONS" -- $cur) )
+			return 0
+			;;
+		'-b')
+			COMPREPLY=( $(compgen -W "512 1024 2048 4096" -- $cur) )
+			return 0
+			;;
+		'-c')
+			COMPREPLY=( $(compgen -W "dos nondos" -- $cur) )

optional arguments, it means the result has to be "-c=dos" or "-c=nondos" and no blank spaces.

I guess you need to use -o nospace for compgen or so.

shell-completion/fdisk line 24

Quoted 5 lines
shell-completion/fdisk new file +5 -0
+			return 0
+			;;
+		'-u')
+			COMPREPLY=( $(compgen -W "cylinders sectors" -- $cur) )
+			return 0

the same situation, -u=

Quoted 6 lines
shell-completion/fdisk new file +6 -0
+			;;
+		'-C'|'-H'|'-S')
+			COMPREPLY=( $(compgen -W "number" -- $cur) )
+			return 0
+			;;
+	esac

shell-completion/fdisk line 40

Quoted 10 lines
shell-completion/fdisk new file +10 -0
+	case $cur in
+		-*)
+			OPTS="-l -s -b -c -h -u -v -C -H -S"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	COMPREPLY=( $(compgen -W "$(lsblk -o NAME,TYPE -n -r | awk '$2 ~ /disk/ {print "/dev/" $1}')" -- $cur) )
+	return 0
+}

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#11 lore raw

PATCH 4/10 bash-completion: login-utils

In reply to Sami Kerola
---
 shell-completion/chfn     | 31 +++++++++++++++++++++++++++++++
 shell-completion/chsh     | 23 +++++++++++++++++++++++
 shell-completion/last     | 38 ++++++++++++++++++++++++++++++++++++++
 shell-completion/login    | 27 +++++++++++++++++++++++++++
 shell-completion/newgrp   | 16 ++++++++++++++++
 shell-completion/su       | 45 +++++++++++++++++++++++++++++++++++++++++++++
 shell-completion/sulogin  | 24 ++++++++++++++++++++++++
 shell-completion/utmpdump | 17 +++++++++++++++++
 8 files changed, 221 insertions(+)
 create mode 100644 shell-completion/chfn
 create mode 100644 shell-completion/chsh
 create mode 100644 shell-completion/last
 create mode 100644 shell-completion/login
 create mode 100644 shell-completion/newgrp
 create mode 100644 shell-completion/su
 create mode 100644 shell-completion/sulogin
 create mode 100644 shell-completion/utmpdump
shell-completion/chfn new file +31 -0
new file mode 100644
index 0000000..1c5167a
@@ -0,0 +1,31 @@
+_chfn_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-f'|'--full-name')
+			COMPREPLY=( $(compgen -W "name" -- $cur) )
+			return 0
+			;;
+		'-o'|'--office')
+			COMPREPLY=( $(compgen -W "office" -- $cur) )
+			return 0
+			;;
+		'-p'|'--office-phone'|'-h'|'--home-phone')
+			COMPREPLY=( $(compgen -W "phone-nr" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-f --full-name -o --office -p --office-phone -h --home-phone -u --help -v --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	COMPREPLY=( $(compgen -u -- $cur) )
+	return 0
+}
+complete -F _chfn_module chfn
shell-completion/chsh new file +23 -0
new file mode 100644
index 0000000..c0a194c
@@ -0,0 +1,23 @@
+_chsh_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-s'|'--shell')
+			COMPREPLY=( $(compgen -W "$(chsh -l)" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-s --shell -l --list-shells -V --version -u --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	COMPREPLY=( $(compgen -u -- $cur) )
+	return 0
+}
+complete -F _chsh_module chsh
shell-completion/last new file +38 -0
new file mode 100644
index 0000000..493051e
@@ -0,0 +1,38 @@
+_last_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-f')
+			compopt -o filenames
+			COMPREPLY=( $(compgen -f -- $cur) )
+			return 0
+			;;
+		'-h')
+			COMPREPLY=( $(compgen -A hostname -- $cur) )
+			return 0
+			;;
+		'-i')
+			COMPREPLY=( $(compgen -W "ipaddr" -- $cur) )
+			return 0
+			;;
+		'-t')
+			local TTYS
+			TTYS=$(cd /sys/devices/virtual/tty && echo *)
+			COMPREPLY=( $(compgen -W "$TTYS" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-f -h -i -l -t -y"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	COMPREPLY=( $(compgen -u -- $cur) )
+	return 0
+}
+complete -F _last_module last
shell-completion/login new file +27 -0
new file mode 100644
index 0000000..c075f64
@@ -0,0 +1,27 @@
+_login_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-f')
+			COMPREPLY=( $(compgen -u -- $cur) )
+			return 0
+			;;
+		'-h')
+			COMPREPLY=( $(compgen -A hostname -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-p -f -h -H -V"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	COMPREPLY=( $(compgen -u -- $cur) )
+	return 0
+}
+complete -F _login_module login
shell-completion/newgrp new file +16 -0
new file mode 100644
index 0000000..567c08c
@@ -0,0 +1,16 @@
+_newgrp_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $cur in
+		-*)
+			OPTS="-V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	COMPREPLY=( $(compgen -g -- $cur) )
+	return 0
+}
+complete -F _newgrp_module newgrp
shell-completion/su new file +45 -0

45 lines not on this page · raw message

shell-completion/sulogin new file +24 -0
new file mode 100644
index 0000000..9fdc20e
@@ -0,0 +1,24 @@
+_sulogin_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-t'|'--timeout')
+			COMPREPLY=( $(compgen -W "seconds" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-p --login-shell -t --timeout -V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- ${cur:-"/dev/tty"}) )
+	return 0
+}
+complete -F _sulogin_module sulogin
shell-completion/utmpdump new file +17 -0
new file mode 100644
index 0000000..e306ef8
@@ -0,0 +1,17 @@
+_utmpdump_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $cur in
+		-*)
+			OPTS="-f --follow -r --reverse -V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _utmpdump_module utmpdump
Signature · 1 line
1.8.2
#12 lore raw

Re: [PATCH 04/10] bash-completion: login-utils

Quoted 35 lines · Sami Kerola
---
 shell-completion/chfn     | 31 +++++++++++++++++++++++++++++++
 shell-completion/chsh     | 23 +++++++++++++++++++++++
 shell-completion/last     | 38 ++++++++++++++++++++++++++++++++++++++
 shell-completion/login    | 27 +++++++++++++++++++++++++++
 shell-completion/newgrp   | 16 ++++++++++++++++
 shell-completion/su       | 45 +++++++++++++++++++++++++++++++++++++++++++++
 shell-completion/sulogin  | 24 ++++++++++++++++++++++++
 shell-completion/utmpdump | 17 +++++++++++++++++
 8 files changed, 221 insertions(+)
 create mode 100644 shell-completion/chfn
 create mode 100644 shell-completion/chsh
 create mode 100644 shell-completion/last
 create mode 100644 shell-completion/login
 create mode 100644 shell-completion/newgrp
 create mode 100644 shell-completion/su
 create mode 100644 shell-completion/sulogin
 create mode 100644 shell-completion/utmpdump
shell-completion/chfn new file +9 -0
new file mode 100644
index 0000000..1c5167a
@@ -0,0 +1,31 @@
+_chfn_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-f'|'--full-name')
+			COMPREPLY=( $(compgen -W "name" -- $cur) )

shell-completion/chfn line 19

Quoted 10 lines
shell-completion/chfn new file +10 -0
+			return 0
+			;;
+		'-o'|'--office')
+			COMPREPLY=( $(compgen -W "office" -- $cur) )
+			return 0
+			;;
+		'-p'|'--office-phone'|'-h'|'--home-phone')
+			COMPREPLY=( $(compgen -W "phone-nr" -- $cur) )
+			return 0
+			;;

I don't understand these. Given the previous argument being one of the found flags, you're completing staticly defined strings. Why complete anything at all?

Quoted 167 lines
shell-completion/chfn new file +12 -0
+	esac
+	case $cur in
+		-*)
+			OPTS="-f --full-name -o --office -p --office-phone -h --home-phone -u --help -v --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	COMPREPLY=( $(compgen -u -- $cur) )
+	return 0
+}
+complete -F _chfn_module chfn
shell-completion/chsh new file +23 -0
new file mode 100644
index 0000000..c0a194c
@@ -0,0 +1,23 @@
+_chsh_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-s'|'--shell')
+			COMPREPLY=( $(compgen -W "$(chsh -l)" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-s --shell -l --list-shells -V --version -u --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	COMPREPLY=( $(compgen -u -- $cur) )
+	return 0
+}
+complete -F _chsh_module chsh
shell-completion/last new file +38 -0
new file mode 100644
index 0000000..493051e
@@ -0,0 +1,38 @@
+_last_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-f')
+			compopt -o filenames
+			COMPREPLY=( $(compgen -f -- $cur) )
+			return 0
+			;;
+		'-h')
+			COMPREPLY=( $(compgen -A hostname -- $cur) )
+			return 0
+			;;
+		'-i')
+			COMPREPLY=( $(compgen -W "ipaddr" -- $cur) )
+			return 0
+			;;
+		'-t')
+			local TTYS
+			TTYS=$(cd /sys/devices/virtual/tty && echo *)
+			COMPREPLY=( $(compgen -W "$TTYS" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-f -h -i -l -t -y"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	COMPREPLY=( $(compgen -u -- $cur) )
+	return 0
+}
+complete -F _last_module last
shell-completion/login new file +27 -0
new file mode 100644
index 0000000..c075f64
@@ -0,0 +1,27 @@
+_login_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-f')
+			COMPREPLY=( $(compgen -u -- $cur) )
+			return 0
+			;;
+		'-h')
+			COMPREPLY=( $(compgen -A hostname -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-p -f -h -H -V"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	COMPREPLY=( $(compgen -u -- $cur) )
+	return 0
+}
+complete -F _login_module login
shell-completion/newgrp new file +16 -0
new file mode 100644
index 0000000..567c08c
@@ -0,0 +1,16 @@
+_newgrp_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $cur in
+		-*)
+			OPTS="-V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	COMPREPLY=( $(compgen -g -- $cur) )
+	return 0
+}
+complete -F _newgrp_module newgrp
shell-completion/su new file +21 -0
new file mode 100644
index 0000000..ded4b7b
@@ -0,0 +1,45 @@
+_su_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-'|'-u'|'--user')
+			COMPREPLY=( $(compgen -u -- $cur) )
+			return 0
+			;;
+		'-g'|'--group'|'-G'|'--supp-group')
+			COMPREPLY=( $(compgen -g -- $cur) )
+			return 0
+			;;
+		'-s'|'--shell')
+			COMPREPLY=( $(compgen -W "$(chsh -l)" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in

shell-completion/su line 31

Quoted 10 lines
shell-completion/su new file +10 -0
+		-*)
+			OPTS="	-u --user
+				-m -p --preserve-environment
+				-g --group
+				-G --supp-group
+				- -l --login
+				-c --command
+				- -c
+				--session-command
+				-- -c

Please don't include the end of options marker in here. You appear to have duplicated -c as well.

Quoted 74 lines
shell-completion/su new file +14 -0
+				-f --fast
+				-s --shell
+				-h --help
+				-V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _su_module su
+complete -F _su_module runuser
shell-completion/sulogin new file +24 -0
new file mode 100644
index 0000000..9fdc20e
@@ -0,0 +1,24 @@
+_sulogin_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-t'|'--timeout')
+			COMPREPLY=( $(compgen -W "seconds" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-p --login-shell -t --timeout -V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- ${cur:-"/dev/tty"}) )
+	return 0
+}
+complete -F _sulogin_module sulogin
shell-completion/utmpdump new file +17 -0
new file mode 100644
index 0000000..e306ef8
@@ -0,0 +1,17 @@
+_utmpdump_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $cur in
+		-*)
+			OPTS="-f --follow -r --reverse -V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _utmpdump_module utmpdump
Signature · 6 lines
1.8.2

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#13 lore raw

Re: [PATCH 04/10] bash-completion: login-utils

Quoted 18 lines · Dave Reisner
Quoted 17 lines · Sami Kerola

+++ b/shell-completion/chfn

shell-completion/chfn new file +15 -0
@@ -0,0 +1,31 @@
+_chfn_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-f'|'--full-name')
+			COMPREPLY=( $(compgen -W "name" -- $cur) )
+			return 0
+			;;
+		'-o'|'--office')
+			COMPREPLY=( $(compgen -W "office" -- $cur) )
+			return 0
+			;;
Quoted 8 lines

shell-completion/chfn line 19

Quoted 4 lines
shell-completion/chfn new file +4 -0
+		'-p'|'--office-phone'|'-h'|'--home-phone')
+			COMPREPLY=( $(compgen -W "phone-nr" -- $cur) )
+			return 0
+			;;

I don't understand these. Given the previous argument being one of the found flags, you're completing staticly defined strings. Why complete anything at all?

I thought giving a textual hint to user is good idea. The hint is now gone. Some of the commands are giving similar hints, other are not. Let see what is found to be more preferred by users and adjust accordingly.

Quoted 4 lines
Quoted 4 lines
shell-completion/su new file +4 -0
+			OPTS="	-u --user
+				-m -p --preserve-environment
+				-g --group
+				-G --supp-group
Quoted 8 lines

shell-completion/su line 31

Quoted 5 lines
shell-completion/su new file +5 -0
+				- -l --login
+				-c --command
+				- -c
+				--session-command
+				-- -c

Please don't include the end of options marker in here. You appear to have duplicated -c as well.

Good catch, end of options marker is removed. While writing this reply I realized that the duplicates are still in my git. Hold on I'll do rebase fix to that.

Signature · 2 lines
   Sami Kerola
   http://www.iki.fi/kerolasa/
maintainer
#14 lore raw

Re: [PATCH 04/10] bash-completion: login-utils

In reply to Sami Kerola

shell-completion/login line 1

Quoted 3 lines · Sami Kerola

+++ b/shell-completion/login

shell-completion/login new file +1 -0
@@ -0,0 +1,27 @@
+_login_module()

Unnecessary module, nobody calls login(1) from command line, it does not work, it's not supported :-)

shell-completion/sulogin line 1

Quoted 3 lines
shell-completion/sulogin new file +2 -0
+++ b/shell-completion/sulogin
@@ -0,0 +1,24 @@
+_sulogin_module()

the same thing, unnecessary

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#15 lore raw

Re: [PATCH 04/10] bash-completion: login-utils

Quoted 8 lines · Karel Zak

shell-completion/login line 1

Quoted 3 lines · Sami Kerola

+++ b/shell-completion/login

shell-completion/login new file +1 -0
@@ -0,0 +1,27 @@
+_login_module()

Unnecessary module, nobody calls login(1) from command line, it does not work, it's not supported :-)

Quoted 5 lines

shell-completion/sulogin line 1

Quoted 3 lines
shell-completion/sulogin new file +2 -0
+++ b/shell-completion/sulogin
@@ -0,0 +1,24 @@
+_sulogin_module()

the same thing, unnecessary

Both are removed, and the agetty as well which is mentioned in later message.

Signature · 2 lines
   Sami Kerola
   http://www.iki.fi/kerolasa/
#16 lore raw

PATCH 5/10 bash-completion: misc-utils

In reply to Sami Kerola
---
 shell-completion/blkid   |  62 ++++++++++++++++++++++++++
 shell-completion/cal     |  15 +++++++
 shell-completion/findmnt | 114 +++++++++++++++++++++++++++++++++++++++++++++++
 shell-completion/getopt  |  34 ++++++++++++++
 shell-completion/logger  |  43 ++++++++++++++++++
 shell-completion/look    |  24 ++++++++++
 shell-completion/lsblk   |  60 +++++++++++++++++++++++++
 shell-completion/lslocks |  43 ++++++++++++++++++
 shell-completion/mcookie |  23 ++++++++++
 shell-completion/namei   |  17 +++++++
 shell-completion/rename  |  27 +++++++++++
 shell-completion/uuidd   |  33 ++++++++++++++
 shell-completion/uuidgen |  15 +++++++
 shell-completion/whereis |  24 ++++++++++
 shell-completion/wipefs  |  38 ++++++++++++++++
 15 files changed, 572 insertions(+)
 create mode 100644 shell-completion/blkid
 create mode 100644 shell-completion/cal
 create mode 100644 shell-completion/findmnt
 create mode 100644 shell-completion/getopt
 create mode 100644 shell-completion/logger
 create mode 100644 shell-completion/look
 create mode 100644 shell-completion/lsblk
 create mode 100644 shell-completion/lslocks
 create mode 100644 shell-completion/mcookie
 create mode 100644 shell-completion/namei
 create mode 100644 shell-completion/rename
 create mode 100644 shell-completion/uuidd
 create mode 100644 shell-completion/uuidgen
 create mode 100644 shell-completion/whereis
 create mode 100644 shell-completion/wipefs
shell-completion/blkid new file +62 -0
new file mode 100644
index 0000000..dce41e0
@@ -0,0 +1,62 @@
+_blkid_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-c')
+			compopt -o filenames
+			COMPREPLY=( $(compgen -f -- $cur) )
+			return 0
+			;;
+		'-o')
+			COMPREPLY=( $(compgen -W "value device export full" -- $cur) )
+			return 0
+			;;
+		'-s')
+			COMPREPLY=( $(compgen -W "tag" -- $cur) )
+			return 0
+			;;
+		'-t')
+			COMPREPLY=( $(compgen -W "token" -- $cur) )
+			return 0
+			;;
+		'-L')
+			COMPREPLY=( $(compgen -W "$(\ls /dev/disk/by-label/ 2>/dev/null)" -- $cur) )
+			return 0
+			;;
+		'-U')
+			COMPREPLY=( $(compgen -W "$(\ls /dev/disk/by-uuid/ 2>/dev/null)" -- $cur) )
+			return 0
+			;;
+		'-s')
+			COMPREPLY=( $(compgen -W "size" -- $cur) )
+			return 0
+			;;
+		'-O')
+			COMPREPLY=( $(compgen -W "offset" -- $cur) )
+			return 0
+			;;
+		'-u')
+			COMPREPLY=( $(compgen -W "filesystem raid crypto other nofilesystem noraid nocrypto noother" -- $cur) )
+			return 0
+			;;
+		'-n')
+			COMPREPLY=( $(compgen -W "$(awk '{print $NF}' /proc/filesystems)" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-c -d -h -g -o -k -s -t -l -L -U -V -p -i -S -O -u -n"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	local PARTITIONS
+	PARTITIONS="$(for I in /sys/block/*/*/partition; do IFS='/'; DIR_ARR=($I); echo "/dev/${DIR_ARR[4]}"; done)"
+	COMPREPLY=( $(compgen -W "$PARTITIONS" -- $cur) )
+	return 0
+}
+complete -F _blkid_module blkid
shell-completion/cal new file +15 -0
new file mode 100644
index 0000000..d50c8bb
@@ -0,0 +1,15 @@
+_cal_module()
+{
+	local cur OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $cur in
+		-*)
+			OPTS="-1 --one -3 --three -s --sunday -m --monday -j --julian -y --year -V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	return 0
+}
+complete -F _cal_module cal
shell-completion/findmnt new file +114 -0

114 lines not on this page · raw message

shell-completion/getopt new file +34 -0
new file mode 100644
index 0000000..ea8c8e2
@@ -0,0 +1,34 @@
+_getopt_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-l'|'--longoptions')
+			COMPREPLY=( $(compgen -W "longopts" -- $cur) )
+			return 0
+			;;
+		'-n'|'--name')
+			COMPREPLY=( $(compgen -W "name" -- $cur) )
+			return 0
+			;;
+		'-o'|'--options')
+			COMPREPLY=( $(compgen -W "optstring" -- $cur) )
+			return 0
+			;;
+		'-s'|'--shell')
+			COMPREPLY=( $(compgen -W "sh bash csh tcsh" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-a --alternative -h --help -l --longoptions -n --name -o --options -q --quiet -Q --quiet-output -s --shell -T --test -u --unquote -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	return 0
+}
+complete -F _getopt_module getopt
shell-completion/logger new file +43 -0

43 lines not on this page · raw message

shell-completion/look new file +24 -0
new file mode 100644
index 0000000..68cea56
@@ -0,0 +1,24 @@
+_look_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-t'|'--terminate')
+			COMPREPLY=( $(compgen -W "char" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-a --alternative -d --alphanum -f --ignore-case -t --terminate -V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _look_module look
shell-completion/lsblk new file +60 -0

60 lines not on this page · raw message

shell-completion/lslocks new file +43 -0

43 lines not on this page · raw message

shell-completion/mcookie new file +23 -0
new file mode 100644
index 0000000..1c01a55
@@ -0,0 +1,23 @@
+_mcookie_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-f'|'--file')
+			compopt -o filenames
+			COMPREPLY=( $(compgen -f -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-f --file -v --verbose -V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	return 0
+}
+complete -F _mcookie_module mcookie
shell-completion/namei new file +17 -0
new file mode 100644
index 0000000..c44821c
@@ -0,0 +1,17 @@
+_namei_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $cur in
+		-*)
+			OPTS="-h --help -V --version -x --mountpoints -m --modes -o --owners -l --long -n --nosymlinks -v --vertical"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _namei_module namei
shell-completion/rename new file +27 -0
new file mode 100644
index 0000000..0fe4cc6
@@ -0,0 +1,27 @@
+_rename_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $cur in
+		-*)
+			OPTS="-v --verbose -s --symlink  -h --help -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	case $COMP_CWORD in
+		1)
+			COMPREPLY=( $(compgen -W "expression" -- $cur) )
+			;;
+		2)
+			COMPREPLY=( $(compgen -W "replacement" -- $cur) )
+			;;
+		*)
+			compopt -o filenames
+			COMPREPLY=( $(compgen -f -- $cur) )
+			;;
+	esac
+	return 0
+}
+complete -F _rename_module rename
shell-completion/uuidd new file +33 -0
new file mode 100644
index 0000000..23c1a49
@@ -0,0 +1,33 @@
+_uuidd_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-p'|'--pid'|'-s'|'--socket')
+			compopt -o filenames
+			COMPREPLY=( $(compgen -f -- $cur) )
+			return 0
+			;;
+		'-T'|'--timeout')
+			compopt -o filenames
+			COMPREPLY=( $(compgen -W "timeout" -- $cur) )
+			return 0
+			;;
+		'-n'|'--uuids')
+			compopt -o filenames
+			COMPREPLY=( $(compgen -W "number" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-p --pid -s --socket -T --timeout -k --kill -r --random -t --time -n --uuids -P --no-pid -F --no-fork -S --socket-activation -d --debug -q --quiet -V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	return 0
+}
+complete -F _uuidd_module uuidd
shell-completion/uuidgen new file +15 -0
new file mode 100644
index 0000000..d9edde9
@@ -0,0 +1,15 @@
+_uuidgen_module()
+{
+	local cur OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $cur in
+		-*)
+			OPTS="-r --random -t --time -V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	return 0
+}
+complete -F _uuidgen_module uuidgen
shell-completion/whereis new file +24 -0
new file mode 100644
index 0000000..96e4117
@@ -0,0 +1,24 @@
+_whereis_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-B'|'-M'|'-S')
+			compopt -o filenames
+			COMPREPLY=( $(compgen -o dirnames -- ${cur:-"/"}) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-b -B -m -M -s -S -f -u -l"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	COMPREPLY=( $(compgen -W "file" -- $cur) )
+	return 0
+}
+complete -F _whereis_module whereis
shell-completion/wipefs new file +38 -0
new file mode 100644
index 0000000..427f47b
@@ -0,0 +1,38 @@
+_wipefs_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-o'|'--offset')
+			COMPREPLY=( $(compgen -W "offset" -- $cur) )
+			return 0
+			;;
+		'-t'|'--types')
+			local TYPES
+			TYPES="adfs affs autofs cifs coda coherent cramfs
+				debugfs devpts efs ext ext2 ext3 ext4 hfs
+				hfsplus hpfs iso9660 jfs minix msdos
+				ncpfs nfs nfs4 ntfs proc qnx4 ramfs
+				reiserfs romfs squashfs smbfs sysv tmpfs
+				ubifs udf ufs umsdos usbfs vfat xenix xfs
+				xiafs"
+			COMPREPLY=( $(compgen -W "$TYPES" -- $cur) )
+			return 0
+			;;
+
+	esac
+	case $cur in
+		-*)
+			OPTS="-a --all -f --force -h --help -n --no-actn -o --offset -p --parsable -q --quiet -t --types -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	local DEVS
+	DEVS="$(\ls -d /sys/class/block/* | sed 's|/sys/class/block/|/dev/|g')"
+	COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
+	return 0
+}
+complete -F _wipefs_module wipefs
Signature · 1 line
1.8.2
#17 lore raw

Re: [PATCH 05/10] bash-completion: misc-utils

Quoted 88 lines · Sami Kerola
---
 shell-completion/blkid   |  62 ++++++++++++++++++++++++++
 shell-completion/cal     |  15 +++++++
 shell-completion/findmnt | 114 +++++++++++++++++++++++++++++++++++++++++++++++
 shell-completion/getopt  |  34 ++++++++++++++
 shell-completion/logger  |  43 ++++++++++++++++++
 shell-completion/look    |  24 ++++++++++
 shell-completion/lsblk   |  60 +++++++++++++++++++++++++
 shell-completion/lslocks |  43 ++++++++++++++++++
 shell-completion/mcookie |  23 ++++++++++
 shell-completion/namei   |  17 +++++++
 shell-completion/rename  |  27 +++++++++++
 shell-completion/uuidd   |  33 ++++++++++++++
 shell-completion/uuidgen |  15 +++++++
 shell-completion/whereis |  24 ++++++++++
 shell-completion/wipefs  |  38 ++++++++++++++++
 15 files changed, 572 insertions(+)
 create mode 100644 shell-completion/blkid
 create mode 100644 shell-completion/cal
 create mode 100644 shell-completion/findmnt
 create mode 100644 shell-completion/getopt
 create mode 100644 shell-completion/logger
 create mode 100644 shell-completion/look
 create mode 100644 shell-completion/lsblk
 create mode 100644 shell-completion/lslocks
 create mode 100644 shell-completion/mcookie
 create mode 100644 shell-completion/namei
 create mode 100644 shell-completion/rename
 create mode 100644 shell-completion/uuidd
 create mode 100644 shell-completion/uuidgen
 create mode 100644 shell-completion/whereis
 create mode 100644 shell-completion/wipefs
shell-completion/blkid new file +48 -0
new file mode 100644
index 0000000..dce41e0
@@ -0,0 +1,62 @@
+_blkid_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-c')
+			compopt -o filenames
+			COMPREPLY=( $(compgen -f -- $cur) )
+			return 0
+			;;
+		'-o')
+			COMPREPLY=( $(compgen -W "value device export full" -- $cur) )
+			return 0
+			;;
+		'-s')
+			COMPREPLY=( $(compgen -W "tag" -- $cur) )
+			return 0
+			;;
+		'-t')
+			COMPREPLY=( $(compgen -W "token" -- $cur) )
+			return 0
+			;;
+		'-L')
+			COMPREPLY=( $(compgen -W "$(\ls /dev/disk/by-label/ 2>/dev/null)" -- $cur) )
+			return 0
+			;;
+		'-U')
+			COMPREPLY=( $(compgen -W "$(\ls /dev/disk/by-uuid/ 2>/dev/null)" -- $cur) )
+			return 0
+			;;
+		'-s')
+			COMPREPLY=( $(compgen -W "size" -- $cur) )
+			return 0
+			;;
+		'-O')
+			COMPREPLY=( $(compgen -W "offset" -- $cur) )
+			return 0
+			;;
+		'-u')
+			COMPREPLY=( $(compgen -W "filesystem raid crypto other nofilesystem noraid nocrypto noother" -- $cur) )
+			return 0
+			;;
+		'-n')
+			COMPREPLY=( $(compgen -W "$(awk '{print $NF}' /proc/filesystems)" -- $cur) )
+			return 0
+			;;

shell-completion/blkid line 58

Quoted 10 lines
shell-completion/blkid new file +10 -0
+	esac
+	case $cur in
+		-*)
+			OPTS="-c -d -h -g -o -k -s -t -l -L -U -V -p -i -S -O -u -n"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	local PARTITIONS
+	PARTITIONS="$(for I in /sys/block/*/*/partition; do IFS='/'; DIR_ARR=($I); echo "/dev/${DIR_ARR[4]}"; done)"

You want the loop *outside* the assignment, rather than exploding the contents into the array via echo:

  for part in /sys/block/*/*/partition; do
    IFS=/ read -ra a <<< "$part"
    partitions+=("${a[4]}")
  done
Quoted 48 lines
shell-completion/blkid new file +4 -0
+	COMPREPLY=( $(compgen -W "$PARTITIONS" -- $cur) )
+	return 0
+}
+complete -F _blkid_module blkid
shell-completion/cal new file +15 -0
new file mode 100644
index 0000000..d50c8bb
@@ -0,0 +1,15 @@
+_cal_module()
+{
+	local cur OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $cur in
+		-*)
+			OPTS="-1 --one -3 --three -s --sunday -m --monday -j --julian -y --year -V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	return 0
+}
+complete -F _cal_module cal
shell-completion/findmnt new file +17 -0
new file mode 100644
index 0000000..5207b97
@@ -0,0 +1,114 @@
+_findmnt_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-p'|'--poll')
+			COMPREPLY=( $(compgen -W "=list" -- $cur) )
+			return 0
+			;;
+		'-w'|'--timeout')
+			COMPREPLY=( $(compgen -W "timeout" -- $cur) )
+			return 0
+			;;
+		'-d'|'--direction')
+			COMPREPLY=( $(compgen -W "forward backward" -- $cur) )

shell-completion/findmnt line 27

Quoted 10 lines
shell-completion/findmnt new file +10 -0
+			return 0
+			;;
+		'-F'|'--tab-file')
+			compopt -o filenames
+			COMPREPLY=( $(compgen -f -- $cur) )
+			return 0
+			;;
+		'-N'|'--task')
+			local TID I
+			TID="$(for I in /proc/*/mountinfo; do IFS='/'; TID=($I); echo "${TID[2]}"; done)"

Ditto here

shell-completion/findmnt line 33

Quoted 6 lines
shell-completion/findmnt new file +6 -0
+			COMPREPLY=( $(compgen -W "$TID" -- $cur) )
+			return 0
+			;;
+		'-O'|'--options')
+			local MNT_OPTS
+			MNT_OPTS=$(awk '{ n = split($4, a, ","); for (i = 0; i <= n; i++) { mnt_opts[a[i]]=1 } } END { for (i in mnt_opts) { print i } }' /etc/mtab 2>/dev/null )

I'm not sure you want to get into this game. You're including values from key=val pairs (e.g. the 300 in timeout=300). Regardless, no awk required here

declare -A mnt_opts

  while read _ _ _ optstring _; do
    IFS=, read -ra opts <<< "$optstring"
    for opt in "${opts[@]}"; do
      mnt_opts["${opt%%=*}"]=1
    done
  done </etc/mtab

  opts=("${!mnt_opts[@]}")

shell-completion/findmnt line 38

Quoted 5 lines
shell-completion/findmnt new file +5 -0
+			COMPREPLY=( $(compgen -W "$MNT_OPTS" -- $cur) )
+			return 0
+			;;
+		'-o'|'--output')
+			# FIXME: how to append to a string with compgen?

I've been down this road when I wrote some of the systemd completion. I don't think you want to go there.

Quoted 536 lines
shell-completion/findmnt new file +76 -0
+			local OUTPUT
+			OUTPUT="SOURCE TARGET FSTYPE OPTIONS VFS-OPTIONS
+				FS-OPTIONS LABEL UUID PARTLABEL PARTUUID
+				MAJ\:MIN ACTION OLD-TARGET OLD-OPTIONS
+				SIZE AVAIL USED USE% FSROOT TID ID
+				OPT-FIELDS PROPAGATION FREQ PASSNO"
+			compopt -o nospace
+			COMPREPLY=( $(compgen -W "$OUTPUT" -S ',' -- $cur) )
+			return 0
+			;;
+		'-t'|'--types')
+			local TYPES
+			TYPES="adfs affs autofs cifs coda coherent cramfs
+				debugfs devpts efs ext ext2 ext3 ext4 hfs
+				hfsplus hpfs iso9660 jfs minix msdos
+				ncpfs nfs nfs4 ntfs proc qnx4 ramfs
+				reiserfs romfs squashfs smbfs sysv tmpfs
+				ubifs udf ufs umsdos usbfs vfat xenix xfs
+				xiafs"
+			COMPREPLY=( $(compgen -W "$TYPES" -- $cur) )
+			return 0
+			;;
+		'-S'|'--source')
+			local DEV_MPOINT
+			DEV_MPOINT=$(awk '{ print $1 }' /etc/mtab 2>/dev/null)
+			COMPREPLY=( $(compgen -W "$DEV_MPOINT" -- $cur) )
+			return 0
+			;;
+		'-T'|'--target')
+			local DEV_MPOINT
+			DEV_MPOINT=$(awk '{ print $2 }' /etc/mtab 2>/dev/null)
+			COMPREPLY=( $(compgen -W "$DEV_MPOINT" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-s --fstab
+				-m --mtab
+				-k --kernel
+				-p --poll
+				-w --timeout
+				-A --all
+				-a --ascii
+				-c --canonicalize
+				-D --df
+				-d --direction
+				-e --evaluate
+				-F --tab-file
+				-f --first-only
+				-i --invert
+				-l --list
+				-N --task
+				-n --noheadings
+				-u --notruncate
+				-O --options
+				-o --output
+				-P --pairs
+				-r --raw
+				-t --types
+				-v --nofsroot
+				-R --submounts
+				-S --source
+				-T --target
+				-h --help
+				-V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	local DEV_MPOINT
+	DEV_MPOINT=$(awk '{ print $1, $2 }' /etc/mtab 2>/dev/null)
+	COMPREPLY=( $(compgen -W "$DEV_MPOINT" -- $cur) )
+	return 0
+}
+complete -F _findmnt_module findmnt
shell-completion/getopt new file +34 -0
new file mode 100644
index 0000000..ea8c8e2
@@ -0,0 +1,34 @@
+_getopt_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-l'|'--longoptions')
+			COMPREPLY=( $(compgen -W "longopts" -- $cur) )
+			return 0
+			;;
+		'-n'|'--name')
+			COMPREPLY=( $(compgen -W "name" -- $cur) )
+			return 0
+			;;
+		'-o'|'--options')
+			COMPREPLY=( $(compgen -W "optstring" -- $cur) )
+			return 0
+			;;
+		'-s'|'--shell')
+			COMPREPLY=( $(compgen -W "sh bash csh tcsh" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-a --alternative -h --help -l --longoptions -n --name -o --options -q --quiet -Q --quiet-output -s --shell -T --test -u --unquote -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	return 0
+}
+complete -F _getopt_module getopt
shell-completion/logger new file +43 -0
new file mode 100644
index 0000000..f572302
@@ -0,0 +1,43 @@
+_logger_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-f'|'--file')
+			compopt -o filenames
+			COMPREPLY=( $(compgen -f -- $cur) )
+			return 0
+			;;
+		'-n'|'--server')
+			COMPREPLY=( $(compgen -A hostname -- $cur) )
+			return 0
+			;;
+		'-P'|'--port')
+			COMPREPLY=( $(compgen -W "$(awk '$1 ~ /^syslog$/  {split($2, a, "/"); print a[1]}' /etc/services)" -- $cur) )
+			return 0
+			;;
+		'-p'|'--priority')
+			COMPREPLY=( $(compgen -W "$(echo {auth,authpriv,cron,daemon,ftp,lpr,mail,news,security}.{alert,crit,debug,emerg,err,error})" -- $cur) )
+			return 0
+			;;
+		'-t'|'--tag')
+			COMPREPLY=( $(compgen -W "tag" -- $cur) )
+			return 0
+			;;
+		'-u'|'--socket')
+			COMPREPLY=( $(compgen -W "$(awk '$NF ~ /^\// {print $NF}' /proc/net/unix)" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-d --udp -i --id -f --file -h --help -n --server -P --port -p --priority -s --stderr -t --tag -u --socket -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	return 0
+}
+complete -F _logger_module logger
shell-completion/look new file +24 -0
new file mode 100644
index 0000000..68cea56
@@ -0,0 +1,24 @@
+_look_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-t'|'--terminate')
+			COMPREPLY=( $(compgen -W "char" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-a --alternative -d --alphanum -f --ignore-case -t --terminate -V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _look_module look
shell-completion/lsblk new file +60 -0
new file mode 100644
index 0000000..521cead
@@ -0,0 +1,60 @@
+_lsblk_module()
+{
+	local cur prev OPTS MAJOR
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-e'|'--exclude'|'-I'|'--include')
+			MAJOR=$(\ls /sys/dev/block/ | sed 's/:.*//')
+			# FIXME: how to append to a string with compgen?
+			compopt -o nospace
+			COMPREPLY=( $(compgen -W "$MAJOR" -S ',' -- $cur) )
+			return 0
+			;;
+		'-o'|'--output')
+			# FIXME: how to append to a string with compgen?
+			OUTPUT="NAME KNAME MAJ:MIN FSTYPE MOUNTPOINT
+				LABEL UUID PARTLABEL PARTUUID RA RO RM
+				MODEL SIZE STATE OWNER GROUP MODE
+				ALIGNMENT MIN-IO OPT-IO PHY-SEC LOG-SEC
+				ROTA SCHED RQ-SIZE TYPE DISC-ALN
+				DISC-GRAN DISC-MAX DISC-ZERO WSAME WWN
+				RAND PKNAME HCTL TRAN REV VENDOR"
+			compopt -o nospace
+			COMPREPLY=( $(compgen -W "$OUTPUT" -S ',' -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-a --all
+				-b --bytes
+				-d --nodeps
+				-D --discard
+				-e --exclude
+				-I --include
+				-f --fs
+				-h --help
+				-i --ascii
+				-m --perms
+				-l --list
+				-n --noheadings
+				-o --output
+				-P --pairs
+				-r --raw
+				-s --inverse
+				-t --topology
+				-S --scsi
+				-h --help
+				-V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	local DEVS
+	DEVS="$(\ls -d /sys/class/block/* | sed 's|/sys/class/block/|/dev/|g')"
+	COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
+	return 0
+}
+complete -F _lsblk_module lsblk
shell-completion/lslocks new file +43 -0
new file mode 100644
index 0000000..f55c17e
@@ -0,0 +1,43 @@
+_lslocks_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-p'|'--pid')
+			local PIDS
+			# /proc/locks can have 8 to 9 fields, see commit
+			# 55c0d16bab8cc84b72bf11cb2fdd8aa6205ac608
+			PIDS="$(awk '{print $(NF-3)}' /proc/locks)"
+			COMPREPLY=( $(compgen -W "$PIDS" -- $cur) )
+			return 0
+			;;
+		'-o'|'--output')
+			# FIXME: how to append to a string with compgen?
+			local OUTPUT
+			OUTPUT="COMMAND PID TYPE SIZE MODE M START END PATH BLOCKER"
+			compopt -o nospace
+			COMPREPLY=( $(compgen -W "$OUTPUT" -S ',' -- $cur) )
+			return 0
+			;;
+
+	esac
+	case $cur in
+		-*)
+			OPTS="-p --pid
+				-o --output
+				-n --noheadings
+				-r --raw
+				-u --notruncate
+				-h --help
+				-V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _lslocks_module lslocks
shell-completion/mcookie new file +23 -0
new file mode 100644
index 0000000..1c01a55
@@ -0,0 +1,23 @@
+_mcookie_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-f'|'--file')
+			compopt -o filenames
+			COMPREPLY=( $(compgen -f -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-f --file -v --verbose -V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	return 0
+}
+complete -F _mcookie_module mcookie
shell-completion/namei new file +17 -0
new file mode 100644
index 0000000..c44821c
@@ -0,0 +1,17 @@
+_namei_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $cur in
+		-*)
+			OPTS="-h --help -V --version -x --mountpoints -m --modes -o --owners -l --long -n --nosymlinks -v --vertical"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _namei_module namei
shell-completion/rename new file +27 -0
new file mode 100644
index 0000000..0fe4cc6
@@ -0,0 +1,27 @@
+_rename_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $cur in
+		-*)
+			OPTS="-v --verbose -s --symlink  -h --help -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	case $COMP_CWORD in
+		1)
+			COMPREPLY=( $(compgen -W "expression" -- $cur) )
+			;;
+		2)
+			COMPREPLY=( $(compgen -W "replacement" -- $cur) )
+			;;
+		*)
+			compopt -o filenames
+			COMPREPLY=( $(compgen -f -- $cur) )
+			;;
+	esac
+	return 0
+}
+complete -F _rename_module rename
shell-completion/uuidd new file +33 -0
new file mode 100644
index 0000000..23c1a49
@@ -0,0 +1,33 @@
+_uuidd_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-p'|'--pid'|'-s'|'--socket')
+			compopt -o filenames
+			COMPREPLY=( $(compgen -f -- $cur) )
+			return 0
+			;;
+		'-T'|'--timeout')
+			compopt -o filenames
+			COMPREPLY=( $(compgen -W "timeout" -- $cur) )
+			return 0
+			;;
+		'-n'|'--uuids')
+			compopt -o filenames
+			COMPREPLY=( $(compgen -W "number" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-p --pid -s --socket -T --timeout -k --kill -r --random -t --time -n --uuids -P --no-pid -F --no-fork -S --socket-activation -d --debug -q --quiet -V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	return 0
+}
+complete -F _uuidd_module uuidd
shell-completion/uuidgen new file +15 -0
new file mode 100644
index 0000000..d9edde9
@@ -0,0 +1,15 @@
+_uuidgen_module()
+{
+	local cur OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $cur in
+		-*)
+			OPTS="-r --random -t --time -V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	return 0
+}
+complete -F _uuidgen_module uuidgen
shell-completion/whereis new file +24 -0
new file mode 100644
index 0000000..96e4117
@@ -0,0 +1,24 @@
+_whereis_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-B'|'-M'|'-S')
+			compopt -o filenames
+			COMPREPLY=( $(compgen -o dirnames -- ${cur:-"/"}) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-b -B -m -M -s -S -f -u -l"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	COMPREPLY=( $(compgen -W "file" -- $cur) )
+	return 0
+}
+complete -F _whereis_module whereis
shell-completion/wipefs new file +38 -0
new file mode 100644
index 0000000..427f47b
@@ -0,0 +1,38 @@
+_wipefs_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-o'|'--offset')
+			COMPREPLY=( $(compgen -W "offset" -- $cur) )
+			return 0
+			;;
+		'-t'|'--types')
+			local TYPES
+			TYPES="adfs affs autofs cifs coda coherent cramfs
+				debugfs devpts efs ext ext2 ext3 ext4 hfs
+				hfsplus hpfs iso9660 jfs minix msdos
+				ncpfs nfs nfs4 ntfs proc qnx4 ramfs
+				reiserfs romfs squashfs smbfs sysv tmpfs
+				ubifs udf ufs umsdos usbfs vfat xenix xfs
+				xiafs"
+			COMPREPLY=( $(compgen -W "$TYPES" -- $cur) )
+			return 0
+			;;
+
+	esac
+	case $cur in
+		-*)
+			OPTS="-a --all -f --force -h --help -n --no-actn -o --offset -p --parsable -q --quiet -t --types -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	local DEVS
+	DEVS="$(\ls -d /sys/class/block/* | sed 's|/sys/class/block/|/dev/|g')"
+	COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
+	return 0
+}
+complete -F _wipefs_module wipefs
Signature · 6 lines
1.8.2

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#18 lore raw

Re: [PATCH 05/10] bash-completion: misc-utils

Quoted 11 lines · Dave Reisner

shell-completion/blkid line 58

Quoted 2 lines · Sami Kerola
shell-completion/blkid new file +2 -0
+	local PARTITIONS
+	PARTITIONS="$(for I in /sys/block/*/*/partition; do IFS='/'; DIR_ARR=($I); echo "/dev/${DIR_ARR[4]}"; done)"

You want the loop *outside* the assignment, rather than exploding the contents into the array via echo:

  for part in /sys/block/*/*/partition; do
    IFS=/ read -ra a <<< "$part"
    partitions+=("${a[4]}")
  done

That was changed to use 'lsblk' rather than /sys files.

Quoted 5 lines

shell-completion/findmnt line 27

Quoted 3 lines
shell-completion/findmnt new file +3 -0
+		'-N'|'--task')
+			local TID I
+			TID="$(for I in /proc/*/mountinfo; do IFS='/'; TID=($I); echo "${TID[2]}"; done)"

Ditto here

Corrected.

Quoted 13 lines

shell-completion/findmnt line 33

Quoted 6 lines
shell-completion/findmnt new file +6 -0
+			COMPREPLY=( $(compgen -W "$TID" -- $cur) )
+			return 0
+			;;
+		'-O'|'--options')
+			local MNT_OPTS
+			MNT_OPTS=$(awk '{ n = split($4, a, ","); for (i = 0; i <= n; i++) { mnt_opts[a[i]]=1 } } END { for (i in mnt_opts) { print i } }' /etc/mtab 2>/dev/null )

I'm not sure you want to get into this game. You're including values from key=val pairs (e.g. the 300 in timeout=300). Regardless, no awk required here

declare -A mnt_opts

Quoted 8 lines
  while read _ _ _ optstring _; do
    IFS=, read -ra opts <<< "$optstring"
    for opt in "${opts[@]}"; do
      mnt_opts["${opt%%=*}"]=1
    done
  done </etc/mtab

  opts=("${!mnt_opts[@]}")

Something similar to that was done with a small difference to avoid reading /etc/mtab. Notice that findmnt is using key=val pair when matching with mount options, not key only.

Quoted 8 lines

shell-completion/findmnt line 38

Quoted 5 lines
shell-completion/findmnt new file +5 -0
+			COMPREPLY=( $(compgen -W "$MNT_OPTS" -- $cur) )
+			return 0
+			;;
+		'-o'|'--output')
+			# FIXME: how to append to a string with compgen?

I've been down this road when I wrote some of the systemd completion. I don't think you want to go there.

I am not sure if CSV filling with compgen is currently possible. I have a feeling the whole issue would be easier if after a completetion which resulted to nospace a word break would be inserted. Is that missing bash feature, bug, or my misunderstanding how this case would be nicest to solve. While I do not know belive leaving the FIXME items in place is correct thing to do.

Thanks for reviews Dave.

Signature · 2 lines
   Sami Kerola
   http://www.iki.fi/kerolasa/
#19 lore raw

PATCH 6/10 bash-completion: schedutils

In reply to Sami Kerola
---
 shell-completion/chrt    | 32 ++++++++++++++++++++++++++++++++
 shell-completion/ionice  | 34 ++++++++++++++++++++++++++++++++++
 shell-completion/taskset | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 104 insertions(+)
 create mode 100644 shell-completion/chrt
 create mode 100644 shell-completion/ionice
 create mode 100644 shell-completion/taskset
shell-completion/chrt new file +32 -0
new file mode 100644
index 0000000..08912c9
@@ -0,0 +1,32 @@
+_chrt_module()
+{
+	local cur OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	# FIXME: -p is ambiguous, it takes either pid or priority as an
+	# argument depending on whether user wanted to get or set the
+	# values.  Perhaps the command interface should be reconsidered.
+	case $cur in
+		-*)
+			OPTS="-b --batch
+				-f --fifo
+				-i --idle
+				-o --other
+				-r --rr
+				-R --reset-on-fork
+				-a --all-tasks
+				-h --help
+				-m --max
+				-p --pid
+				-v --verbose
+				-V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	local PIDS
+	PIDS=$(\ls -d /proc/[0-9]* | sed 's|/proc/||')
+	COMPREPLY=( $(compgen -W "$PIDS" -- $cur) )
+	return 0
+}
+complete -F _chrt_module chrt
shell-completion/ionice new file +34 -0
new file mode 100644
index 0000000..3087c4a
@@ -0,0 +1,34 @@
+_ionice_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-c'|'--class')
+			COMPREPLY=( $(compgen -W "$(echo {0..3}) none realtime best-effort idle" -- $cur) )
+			return 0
+			;;
+		'-n'|'--classdata')
+			COMPREPLY=( $(compgen -W "$(echo {0..7})" -- $cur) )
+			return 0
+			;;
+		'-p'|'--pid')
+			local PIDS
+			PIDS=$(\ls -d /proc/[0-9]* | sed 's|/proc/||')
+			COMPREPLY=( $(compgen -W "$PIDS" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-c --class -n --classdata -p --pid -t --ignore -V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _ionice_module ionice
shell-completion/taskset new file +38 -0
new file mode 100644
index 0000000..81247cd
@@ -0,0 +1,38 @@
+_taskset_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-c'|'--cpu-list')
+			local CPULIST
+			# FIXME: will propose only binding to a cpu.
+			# Maybe this should add comma, and continue?
+			CPULIST=$(sed 's/^/{/; s/-/../g; s/,/} {/g; s/$/}/' /sys/devices/system/cpu/online)
+			COMPREPLY=( $(compgen -W "$(eval echo $CPULIST)" -- $cur) )
+			return 0
+			;;
+		'-p'|'--pid')
+			local PIDS
+			# FIXME: the pid argument is ambiguous.  When
+			# setting an affinity the optarg has to be cpu
+			# mask.  The following is good only for getting
+			# affinity.
+			PIDS=$(\ls -d /proc/[0-9]* | sed 's|/proc/||')
+			COMPREPLY=( $(compgen -W "$PIDS" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-a --all-tasks -p --pid -c --cpu-list -h --help -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o bashdefault
+	COMPREPLY=( $(compgen -c -- $cur) )
+	return 0
+}
+complete -F _taskset_module taskset
Signature · 1 line
1.8.2
#20 lore raw

PATCH 7/10 bash-completion: sys-utils

In reply to Sami Kerola
---
 shell-completion/blkdiscard  | 25 ++++++++++++++
 shell-completion/chcpu       | 44 ++++++++++++++++++++++++
 shell-completion/ctrlaltdel  | 11 ++++++
 shell-completion/cytune      | 37 ++++++++++++++++++++
 shell-completion/dmesg       | 53 ++++++++++++++++++++++++++++
 shell-completion/eject       | 61 ++++++++++++++++++++++++++++++++
 shell-completion/fallocate   | 24 +++++++++++++
 shell-completion/flock       | 42 +++++++++++++++++++++++
 shell-completion/fsfreeze    | 18 ++++++++++
 shell-completion/fstrim      | 25 ++++++++++++++
 shell-completion/hwclock     | 53 ++++++++++++++++++++++++++++
 shell-completion/ipcrm       | 52 ++++++++++++++++++++++++++++
 shell-completion/ipcs        | 30 ++++++++++++++++
 shell-completion/ldattach    | 54 +++++++++++++++++++++++++++++
 shell-completion/losetup     | 64 ++++++++++++++++++++++++++++++++++
 shell-completion/lscpu       | 39 +++++++++++++++++++++
 shell-completion/mountpoint  | 24 +++++++++++++
 shell-completion/nsenter     | 47 +++++++++++++++++++++++++
 shell-completion/pivot_root  | 14 ++++++++
 shell-completion/prlimit     | 55 +++++++++++++++++++++++++++++
 shell-completion/readprofile | 33 ++++++++++++++++++
 shell-completion/renice      | 38 ++++++++++++++++++++
 shell-completion/rtcwake     | 40 +++++++++++++++++++++
 shell-completion/setarch     | 42 +++++++++++++++++++++++
 shell-completion/setpriv     | 82 ++++++++++++++++++++++++++++++++++++++++++++
 shell-completion/setsid      | 17 +++++++++
 shell-completion/swapon      | 48 ++++++++++++++++++++++++++
 shell-completion/tunelp      | 48 ++++++++++++++++++++++++++
 shell-completion/unshare     | 24 +++++++++++++
 shell-completion/wdctl       | 48 ++++++++++++++++++++++++++
 30 files changed, 1192 insertions(+)
 create mode 100644 shell-completion/blkdiscard
 create mode 100644 shell-completion/chcpu
 create mode 100644 shell-completion/ctrlaltdel
 create mode 100644 shell-completion/cytune
 create mode 100644 shell-completion/dmesg
 create mode 100644 shell-completion/eject
 create mode 100644 shell-completion/fallocate
 create mode 100644 shell-completion/flock
 create mode 100644 shell-completion/fsfreeze
 create mode 100644 shell-completion/fstrim
 create mode 100644 shell-completion/hwclock
 create mode 100644 shell-completion/ipcrm
 create mode 100644 shell-completion/ipcs
 create mode 100644 shell-completion/ldattach
 create mode 100644 shell-completion/losetup
 create mode 100644 shell-completion/lscpu
 create mode 100644 shell-completion/mountpoint
 create mode 100644 shell-completion/nsenter
 create mode 100644 shell-completion/pivot_root
 create mode 100644 shell-completion/prlimit
 create mode 100644 shell-completion/readprofile
 create mode 100644 shell-completion/renice
 create mode 100644 shell-completion/rtcwake
 create mode 100644 shell-completion/setarch
 create mode 100644 shell-completion/setpriv
 create mode 100644 shell-completion/setsid
 create mode 100644 shell-completion/swapon
 create mode 100644 shell-completion/tunelp
 create mode 100644 shell-completion/unshare
 create mode 100644 shell-completion/wdctl
shell-completion/blkdiscard new file +25 -0
new file mode 100644
index 0000000..e907a1b
@@ -0,0 +1,25 @@
+_blkdiscard_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-o'|'--offset'|'-l'|'--length')
+			COMPREPLY=( $(compgen -W "num" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-o --offset -l --length -s --secure -v --verbose -h --help -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	local DEVS
+	DEVS="$(\ls -d /sys/class/block/* | sed 's|/sys/class/block/|/dev/|g')"
+	COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
+	return 0
+}
+complete -F _blkdiscard_module blkdiscard
shell-completion/chcpu new file +44 -0

44 lines not on this page · raw message

shell-completion/ctrlaltdel new file +11 -0
new file mode 100644
index 0000000..e725752
@@ -0,0 +1,11 @@
+_ctrlaltdel_module()
+{
+	local cur
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	COMPREPLY=()
+	if [ $COMP_CWORD -eq 1 ]; then
+		COMPREPLY=( $(compgen -W "hard soft" -- $cur) )
+	fi
+	return 0
+}
+complete -F _ctrlaltdel_module ctrlaltdel
shell-completion/cytune new file +37 -0
new file mode 100644
index 0000000..9a90d34
@@ -0,0 +1,37 @@
+_cytune_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-s'|'--set-threshold'|'-S'|'--set-default-threshold'|'-t'|'--set-flush'|'-T'|'--set-default-flush')
+			COMPREPLY=( $(compgen -W "num" -- $cur) )
+			return 0
+			;;
+		'-i'|'--interval')
+			COMPREPLY=( $(compgen -W "seconds" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-s --set-threshold
+				-g --get-threshold
+				-S --set-default-threshold
+				-t --set-flush
+				-G --get-glush
+				-T --set-default-flush
+				-q --stats
+				-i --interval
+				-h --help
+				-V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- ${cur:-"/dev/tty"}) )
+	return 0
+}
+complete -F _cytune_module cytune
shell-completion/dmesg new file +53 -0

53 lines not on this page · raw message

shell-completion/eject new file +61 -0

61 lines not on this page · raw message

shell-completion/fallocate new file +24 -0
new file mode 100644
index 0000000..132858c
@@ -0,0 +1,24 @@
+_fallocate_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-o'|'--offset'|'-l'|'--length')
+			COMPREPLY=( $(compgen -W "bytes" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-n --keep-size -p --punch-hole -o --offset -l --length -h --help -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _fallocate_module fallocate
shell-completion/flock new file +42 -0

42 lines not on this page · raw message

shell-completion/fsfreeze new file +18 -0
new file mode 100644
index 0000000..7933c15
@@ -0,0 +1,18 @@
+_fsfreeze_module()
+{
+	local cur OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $cur in
+		-*)
+			OPTS="-f --freeze -u --unfreeze -h --help -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	local MPOINT
+	MPOINT="$(findmnt -t ext2,ext3,ext4,reiserfs,jfs,xfs -o TARGET -n -r)"
+	COMPREPLY=( $(compgen -W "$MPOINT" -- $cur) )
+	return 0
+}
+complete -F _fsfreeze_module fsfreeze
shell-completion/fstrim new file +25 -0
new file mode 100644
index 0000000..87cb050
@@ -0,0 +1,25 @@
+_fstrim_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-o'|'--offset'|'-l'|'--length'|'-m'|'--minimum')
+			COMPREPLY=( $(compgen -W "num" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-o --offset -l --length -m --minimum -v --verbose -h --help -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	local MPOINTS
+	MPOINTS=$(awk '{if ($1 ~ /^\//){print $2}}' /etc/mtab 2>/dev/null)
+	COMPREPLY=( $(compgen -W "$MPOINTS" -- $cur) )
+	return 0
+}
+complete -F _fstrim_module fstrim
shell-completion/hwclock new file +53 -0

53 lines not on this page · raw message

shell-completion/ipcrm new file +52 -0

52 lines not on this page · raw message

shell-completion/ipcs new file +30 -0
new file mode 100644
index 0000000..51502bb
@@ -0,0 +1,30 @@
+_ipcs_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-i'|'--id')
+			COMPREPLY=( $(compgen -W "id" -- $cur) )
+			return 0
+			;;
+	esac
+	OPTS="-i --id
+		-h --help
+		-V --version
+		-m --shmems
+		-q --queues
+		-s --semaphores
+		-a --all
+		-t --time
+		-p --pid
+		-c --creator
+		-l --limits
+		-u --summary
+		   --human
+		-b --bytes"
+	COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+	return 0
+}
+complete -F _ipcs_module ipcs
shell-completion/ldattach new file +54 -0

54 lines not on this page · raw message

shell-completion/losetup new file +64 -0

64 lines not on this page · raw message

shell-completion/lscpu new file +39 -0
new file mode 100644
index 0000000..bb76d4c
@@ -0,0 +1,39 @@
+_lscpu_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-e'|'--extended'|'-p'|'--parse')
+			# FIXME: how to append to a string with compgen?
+			# FIXME: space in between option and argument is
+			# 	 a problem.
+			local OUTPUT
+			OUTPUT="CPU CORE SOCKET NODE BOOK CACHE
+				POLARIZATION ADDRESS CONFIGURED ONLINE"
+			compopt -o nospace
+			COMPREPLY=( $(compgen -W "$OUTPUT" -S ',' -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-a --all
+				-b --online
+				-c --offline
+				-e --extended
+				-p --parse
+				-s --sysroot
+				-x --hex
+				-h --help
+				-V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _lscpu_module lscpu
shell-completion/mountpoint new file +24 -0
new file mode 100644
index 0000000..e2f1d56
@@ -0,0 +1,24 @@
+_mountpoint_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-f'|'--fixme')
+			COMPREPLY=( $(compgen -W "fixme" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-q --quiet -d --fs-devno -x --devno -h --help -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- ${cur:-"/"}) )
+	return 0
+}
+complete -F _mountpoint_module mountpoint
shell-completion/nsenter new file +47 -0

47 lines not on this page · raw message

shell-completion/pivot_root new file +14 -0
new file mode 100644
index 0000000..54f1734
@@ -0,0 +1,14 @@
+_pivot_root_module()
+{
+	local cur
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $COMP_CWORD in
+		1|2)
+			compopt -o filenames
+			COMPREPLY=( $(compgen -o dirnames -- ${cur:-"/"}) )
+			;;
+	esac
+	return 0
+}
+complete -F _pivot_root_module pivot_root
shell-completion/prlimit new file +55 -0

55 lines not on this page · raw message

shell-completion/readprofile new file +33 -0
new file mode 100644
index 0000000..c1eb514
@@ -0,0 +1,33 @@
+_readprofile_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-m'|'--mapfile'|'-p'|'--profile')
+			compopt -o filenames
+			COMPREPLY=( $(compgen -f -- $cur) )
+			return 0
+			;;
+		'-M'|'--multiplier')
+			COMPREPLY=( $(compgen -W "multiplier" -- $cur) )
+			return 0
+			;;
+	esac
+	OPTS="-m --mapfile
+		-p --profile
+		-M --multiplier
+		-i --info
+		-v --verbose
+		-a --all
+		-b --histbin
+		-s --counters
+		-r --reset
+		-n --no-auto
+		-h --help
+		-V --version"
+	COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+	return 0
+}
+complete -F _readprofile_module readprofile
shell-completion/renice new file +38 -0
new file mode 100644
index 0000000..bc80dac
@@ -0,0 +1,38 @@
+_renice_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-g'|'--pgrp')
+			local PGRP
+			PGRP=$(ps -ax -opgrp | sed '1d')
+			COMPREPLY=( $(compgen -W "$PGRP" -- $cur) )
+			return 0
+			;;
+		'-n'|'--priority')
+			COMPREPLY=( $(compgen -W "$(echo {-20..20})" -- $cur) )
+			return 0
+			;;
+		'-p'|'--pid')
+			local PIDS
+			PIDS=$(\ls -d /proc/[0-9]* | sed 's|/proc/||')
+			COMPREPLY=( $(compgen -W "$PIDS" -- $cur) )
+			return 0
+			;;
+		'-u'|'--user')
+			COMPREPLY=( $(compgen -u -- $cur) )
+			return 0
+			;;
+	esac
+	OPTS="-g --pgrp
+		-n --priority
+		-p --pid
+		-u --user
+		-h --help
+		-V --version"
+	COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+	return 0
+}
+complete -F _renice_module renice
shell-completion/rtcwake new file +40 -0
new file mode 100644
index 0000000..2010a52
@@ -0,0 +1,40 @@
+_rtcwake_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-d'|'--device')
+			local RTC_DEVS
+			RTC_DEVS=$(\ls /sys/class/rtc/ 2>/dev/null)
+			COMPREPLY=( $(compgen -W "$RTC_DEVS" -- $cur) )
+			return 0
+			;;
+		'-m'|'--mode')
+			COMPREPLY=( $(compgen -W "standby mem disk off no on disable show" -- $cur) )
+			return 0
+			;;
+		'-s'|'--seconds')
+			COMPREPLY=( $(compgen -W "seconds" -- $cur) )
+			return 0
+			;;
+		'-t'|'--time')
+			COMPREPLY=( $(compgen -W "time_t" -- $cur) )
+			return 0
+			;;
+	esac
+	OPTS="-d --device
+		-n --dry-run
+		-l --local
+		-m --mode
+		-s --seconds
+		-t --time
+		-u --utc
+		-v --verbose
+		-h --help
+		-V --version"
+	COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+	return 0
+}
+complete -F _rtcwake_module rtcwake
shell-completion/setarch new file +42 -0

42 lines not on this page · raw message

shell-completion/setpriv new file +82 -0

82 lines not on this page · raw message

shell-completion/setsid new file +17 -0
new file mode 100644
index 0000000..dcefc2f
@@ -0,0 +1,17 @@
+_setsid_module()
+{
+	local cur OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $cur in
+		-*)
+			OPTS="-c --ctty -h --help -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o bashdefault
+	COMPREPLY=( $(compgen -c -- $cur) )
+	return 0
+}
+complete -F _setsid_module setsid
shell-completion/swapon new file +48 -0

48 lines not on this page · raw message

shell-completion/tunelp new file +48 -0

48 lines not on this page · raw message

shell-completion/unshare new file +24 -0
new file mode 100644
index 0000000..295d02f
@@ -0,0 +1,24 @@
+_unshare_module()
+{
+	local cur OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $cur in
+		-*)
+			OPTS="-m --mount
+				-u --uts
+				-i --ipc
+				-n --net
+				-p --pid
+				-U --user
+				-h --help
+				-V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o bashdefault
+	COMPREPLY=( $(compgen -c -- $cur) )
+	return 0
+}
+complete -F _unshare_module unshare
shell-completion/wdctl new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
1.8.2
maintainer
#21 lore raw

Re: [PATCH 07/10] bash-completion: sys-utils

Quoted 12 lines · Sami Kerola
shell-completion/blkdiscard new file +11 -0
@@ -0,0 +1,25 @@
+_blkdiscard_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-o'|'--offset'|'-l'|'--length')
+			COMPREPLY=( $(compgen -W "num" -- $cur) )
+			return 0
+			;;

shell-completion/blkdiscard line 21

Quoted 10 lines
shell-completion/blkdiscard new file +10 -0
+	esac
+	case $cur in
+		-*)
+			OPTS="-o --offset -l --length -s --secure -v --verbose -h --help -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	local DEVS
+	DEVS="$(\ls -d /sys/class/block/* | sed 's|/sys/class/block/|/dev/|g')"

It does not look like the right way how to generate the paths, because /sys/class/block/ contains also paths to unassociated loop devices and all the paths are based on kernel device names (e.g. dm-X).

I have add --paths to lsblk(8), so now you can use:

lsblk -p -o NAME -n -l

to list the paths, for exmaple:

/dev/sda
/dev/sda1
/dev/sda2
/dev/sda3
/dev/sda4
/dev/sda5
/dev/sda6 /dev/mapper/luks-10d813de-fa82-4f67-a86c-23d5d0e7c30e /dev/sdb
/dev/sr0

it would be nice to use this solution everywhere.

Quoted 2 lines
shell-completion/eject new file +2 -0
+_eject_module()
+{

....

shell-completion/eject line 57

Quoted 9 lines
shell-completion/eject new file +9 -0
+	DEVS="$(for I in /sys/class/block/*/removable; do
+		if [ $(cat $I) -ne 0 ]; then
+			OLD_IFS=$IFS
+			IFS='/';
+			ARR=($I)
+			echo "/dev/${ARR[4]}"
+			IFS=$OLD_IFS
+		fi
+	done)"

lsblk -rpn -o RM,NAME | awk '/^1/ { print $2 }'

The common rule is to not read data from /sys if possible.

Quoted 17 lines
shell-completion/fstrim new file +11 -0
new file mode 100644
index 0000000..87cb050
@@ -0,0 +1,25 @@
+_fstrim_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-o'|'--offset'|'-l'|'--length'|'-m'|'--minimum')
+			COMPREPLY=( $(compgen -W "num" -- $cur) )
+			return 0
+			;;

shell-completion/fstrim line 21

Quoted 10 lines
shell-completion/fstrim new file +10 -0
+	esac
+	case $cur in
+		-*)
+			OPTS="-o --offset -l --length -m --minimum -v --verbose -h --help -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	local MPOINTS
+	MPOINTS=$(awk '{if ($1 ~ /^\//){print $2}}' /etc/mtab 2>/dev/null)

The same problem, don't read mtab directly (for example because some chars could be escaped...). Use:

findmnt -rno SOURCE | grep '/dev'

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#22 lore raw

Re: [PATCH 07/10] bash-completion: sys-utils

Quoted 45 lines · Karel Zak
Quoted 12 lines · Sami Kerola
shell-completion/blkdiscard new file +11 -0
@@ -0,0 +1,25 @@
+_blkdiscard_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-o'|'--offset'|'-l'|'--length')
+			COMPREPLY=( $(compgen -W "num" -- $cur) )
+			return 0
+			;;

shell-completion/blkdiscard line 21

Quoted 10 lines
shell-completion/blkdiscard new file +10 -0
+	esac
+	case $cur in
+		-*)
+			OPTS="-o --offset -l --length -s --secure -v --verbose -h --help -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	local DEVS
+	DEVS="$(\ls -d /sys/class/block/* | sed 's|/sys/class/block/|/dev/|g')"

It does not look like the right way how to generate the paths, because /sys/class/block/ contains also paths to unassociated loop devices and all the paths are based on kernel device names (e.g. dm-X).

I have add --paths to lsblk(8), so now you can use:

lsblk -p -o NAME -n -l

to list the paths, for exmaple:

/dev/sda
/dev/sda1
/dev/sda2
/dev/sda3
/dev/sda4
/dev/sda5
/dev/sda6 /dev/mapper/luks-10d813de-fa82-4f67-a86c-23d5d0e7c30e /dev/sdb
/dev/sr0

Quoted 1 line

it would be nice to use this solution everywhere.

I think I found all references to block devices, and replaced them with lsblk which is using Dave's while loop.

Quoted 48 lines
Quoted 2 lines
shell-completion/eject new file +2 -0
+_eject_module()
+{

....

shell-completion/eject line 57

Quoted 9 lines
shell-completion/eject new file +9 -0
+	DEVS="$(for I in /sys/class/block/*/removable; do
+		if [ $(cat $I) -ne 0 ]; then
+			OLD_IFS=$IFS
+			IFS='/';
+			ARR=($I)
+			echo "/dev/${ARR[4]}"
+			IFS=$OLD_IFS
+		fi
+	done)"

lsblk -rpn -o RM,NAME | awk '/^1/ { print $2 }'

The common rule is to not read data from /sys if possible.

Quoted 17 lines
shell-completion/fstrim new file +11 -0
new file mode 100644
index 0000000..87cb050
@@ -0,0 +1,25 @@
+_fstrim_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-o'|'--offset'|'-l'|'--length'|'-m'|'--minimum')
+			COMPREPLY=( $(compgen -W "num" -- $cur) )
+			return 0
+			;;

shell-completion/fstrim line 21

Quoted 10 lines
shell-completion/fstrim new file +10 -0
+	esac
+	case $cur in
+		-*)
+			OPTS="-o --offset -l --length -m --minimum -v --verbose -h --help -V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	local MPOINTS
+	MPOINTS=$(awk '{if ($1 ~ /^\//){print $2}}' /etc/mtab 2>/dev/null)

The same problem, don't read mtab directly (for example because some chars could be escaped...). Use:

Quoted 1 line

findmnt -rno SOURCE | grep '/dev'

With this I had a small whoops. The diff I sent moment ago did not have findmnt v.s. /etc/mtab fixes, which are now in my git.

What comes to principle of using helper commands rather than /sys or /proc files I fully agree this is better.

Signature · 2 lines
   Sami Kerola
   http://www.iki.fi/kerolasa/
maintainer
#23 lore raw

Re: [PATCH 07/10] bash-completion: sys-utils

In reply to Sami Kerola
Quoted 17 lines · Sami Kerola
shell-completion/swapon new file +11 -0
new file mode 100644
index 0000000..83e7e24
@@ -0,0 +1,48 @@
+_swapon_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-p'|'--priority')
+			# Priority range is -1 to 32767.  Perhaps these
+			# few are enough.
+			COMPREPLY=( $(compgen -W "$(echo {-1..9} 32767)" -- $cur) )

shell-completion/swapon line 21

Quoted 10 lines
shell-completion/swapon new file +10 -0
+			return 0
+			;;
+		'--show')
+			# FIXME: how to append to a string with compgen?
+			local OUTPUT
+			OUTPUT="NAME TYPE SIZE USED PRIO"
+			compopt -o nospace
+			COMPREPLY=( $(compgen -W "$OUTPUT" -S ',' -- $cur) )
+			return 0
+			;;

What about to -L <label> and -U <uuid>? For example:

lsblk -nrp -o FSTYPE,UUID | awk '$1 ~ /swap/ { print $2 }'

returns all swaps UUIDs

Quoted 16 lines
shell-completion/swapon new file +16 -0
+	esac
+	case $cur in
+		-*)
+			OPTS="-a --all
+				-d --discard
+				-e --ifexists
+				-f --fixpgsz
+				-p --priority
+				-s --summary
+				   --show
+				   --noheadings
+				   --raw
+				   --bytes
+				-v --verbose
+				-h --help
+				-V --version"

shell-completion/swapon line 47

Quoted 10 lines
shell-completion/swapon new file +10 -0
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	# FIXME: compgen will split SPEC= from '=' point.  The append
+	# comma separated value problem is very similar.
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}

Would be better to offer list of block devices where is swap header?

lsblk -nrp -o FSTYPE,NAME | awk '$1 ~ /swap/ { print $2 }'

rather than list of files? I think that swap to files is unusual.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#24 lore raw

PATCH 8/10 bash-completion: term-utils

In reply to Sami Kerola
---
 shell-completion/agetty       |  70 +++++++++++++++++++++++++++
 shell-completion/mesg         |  16 +++++++
 shell-completion/script       |  38 +++++++++++++++
 shell-completion/scriptreplay |  28 +++++++++++
 shell-completion/setterm      | 109 ++++++++++++++++++++++++++++++++++++++++++
 shell-completion/wall         |  24 ++++++++++
 shell-completion/write        |  19 ++++++++
 7 files changed, 304 insertions(+)
 create mode 100644 shell-completion/agetty
 create mode 100644 shell-completion/mesg
 create mode 100644 shell-completion/script
 create mode 100644 shell-completion/scriptreplay
 create mode 100644 shell-completion/setterm
 create mode 100644 shell-completion/wall
 create mode 100644 shell-completion/write
shell-completion/agetty new file +70 -0
new file mode 100644
index 0000000..dc37a68
@@ -0,0 +1,70 @@
+_agetty_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-a'|'--autologin')
+			COMPREPLY=( $(compgen -u -- $cur) )
+			return 0
+			;;
+		'-o'|'--issue-file'|'-I'|'--login-program')
+			compopt -o filenames
+			COMPREPLY=( $(compgen -f -- $cur) )
+			return 0
+			;;
+		'-I'|'--init-string'|'--erase-chars'|'--kill-chars')
+			compopt -o filenames
+			COMPREPLY=( $(compgen -W "string" -- $cur) )
+			return 0
+			;;
+		'-o'|'--login-options')
+			COMPREPLY=( $(compgen -W "login-options" -- $cur) )
+			return 0
+			;;
+		'-t'|'--timeout')
+			COMPREPLY=( $(compgen -W "seconds" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-8 --8bits
+				-a --autologin
+				-c --noreset
+				-f --issue-file
+				-h --flow-control
+				-H --host
+				-i --noissue
+				-I --init-string
+				-l --login-program
+				-L --local-line
+				-m --extract-baud
+				-n --skip-login
+				-o --login-options
+				-p --loginpause
+				-R --hangup
+				-s --keep-baud
+				-t --timeout
+				-U --detect-case
+				-w --wait-cr
+				   --nocleardo
+				   --nohintsdo
+				   --nonewlinedo
+				   --no-hostnameno
+				   --long-hostnameshow
+				   --erase-chars
+				   --kill-chars
+				-h --help
+				-V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	local BAUD_RATES
+	BAUD_RATES="75 110 300 1200 2400 4800 9600 19200 38400 57600 115200"
+	COMPREPLY=( $(compgen -W "$BAUD_RATES $(echo /dev/tty*)" -- $cur) )
+	return 0
+}
+complete -F _agetty_module agetty
shell-completion/mesg new file +16 -0
new file mode 100644
index 0000000..62c98ca
@@ -0,0 +1,16 @@
+_mesg_module()
+{
+	local cur OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $cur in
+		-*)
+			OPTS="-v --verbose -V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	COMPREPLY=( $(compgen -W "y n" -- $cur) )
+	return 0
+}
+complete -F _mesg_module mesg
shell-completion/script new file +38 -0
new file mode 100644
index 0000000..fb6c106
@@ -0,0 +1,38 @@
+_script_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-c'|'--command')
+			compopt -o bashdefault
+			COMPREPLY=( $(compgen -c -- $cur) )
+			return 0
+			;;
+		'-t'|'--timing')
+			compopt -o filenames
+			COMPREPLY=( $(compgen -f -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-a --append
+				-c --command
+				-e --return
+				-f --flush
+				   --force
+				-q --quiet
+				-t --timing
+				-V --version
+				-h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _script_module script
shell-completion/scriptreplay new file +28 -0
new file mode 100644
index 0000000..78e5b23
@@ -0,0 +1,28 @@
+_scriptreplay_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-d'|'--divisor')
+			COMPREPLY=( $(compgen -W "digit" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-t --timing
+				-s --typescript
+				-d --divisor
+				-V --version
+				-h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _scriptreplay_module scriptreplay
shell-completion/setterm new file +109 -0

109 lines not on this page · raw message

shell-completion/wall new file +24 -0
new file mode 100644
index 0000000..d3cbbd5
@@ -0,0 +1,24 @@
+_wall_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-t'|'--timeout')
+			COMPREPLY=( $(compgen -W "seconds" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-n --nobanner -t --timeout -V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _wall_module wall
shell-completion/write new file +19 -0
new file mode 100644
index 0000000..ba67569
@@ -0,0 +1,19 @@
+_write_module()
+{
+	local cur
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $COMP_CWORD in
+		1)
+			COMPREPLY=( $(compgen -u -- $cur) )
+			return 0
+			;;
+		2)
+			local TERMS=$(for I in $(\ls /sys/class/tty 2>/dev/null); do echo "/dev/$I"; done)
+			COMPREPLY=( $(compgen -W "$TERMS" -- $cur) )
+			return 0
+			;;
+	esac
+	return 0
+}
+complete -F _write_module write
Signature · 1 line
1.8.2
maintainer
#25 lore raw

Re: [PATCH 08/10] bash-completion: term-utils

shell-completion/agetty line 1

Quoted 3 lines · Sami Kerola

+++ b/shell-completion/agetty

shell-completion/agetty new file +1 -0
@@ -0,0 +1,70 @@
+_agetty_module()

You don't want to use agetty from command line :-)

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#26 lore raw

PATCH 9/10 bash-completion: text-utils

In reply to Sami Kerola
---
 shell-completion/col     | 24 ++++++++++++++++++++++++
 shell-completion/colcrt  | 20 ++++++++++++++++++++
 shell-completion/colrm   | 23 +++++++++++++++++++++++
 shell-completion/column  | 34 ++++++++++++++++++++++++++++++++++
 shell-completion/hexdump | 32 ++++++++++++++++++++++++++++++++
 shell-completion/more    | 22 ++++++++++++++++++++++
 shell-completion/pg      | 29 +++++++++++++++++++++++++++++
 shell-completion/rev     | 17 +++++++++++++++++
 shell-completion/tailf   | 24 ++++++++++++++++++++++++
 shell-completion/ul      | 25 +++++++++++++++++++++++++
 10 files changed, 250 insertions(+)
 create mode 100644 shell-completion/col
 create mode 100644 shell-completion/colcrt
 create mode 100644 shell-completion/colrm
 create mode 100644 shell-completion/column
 create mode 100644 shell-completion/hexdump
 create mode 100644 shell-completion/more
 create mode 100644 shell-completion/pg
 create mode 100644 shell-completion/rev
 create mode 100644 shell-completion/tailf
 create mode 100644 shell-completion/ul
shell-completion/col new file +24 -0
new file mode 100644
index 0000000..9ad3a67
@@ -0,0 +1,24 @@
+_col_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-l'|'--lines')
+			COMPREPLY=( $(compgen -W "number" -- $cur) )
+			return 0
+			;;
+	esac
+	OPTS="-b --no-backspaces
+		-f --fine
+		-p --pass
+		-h --tabs
+		-x --spaces
+		-l --lines
+		-V --version
+		-H --help"
+	COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+	return 0
+}
+complete -F _col_module col
shell-completion/colcrt new file +20 -0
new file mode 100644
index 0000000..628416e
@@ -0,0 +1,20 @@
+_colcrt_module()
+{
+	local cur OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $cur in
+		-*)
+			OPTS="	-  --no-underlining
+				-2 --half-lines
+				-V --version
+				-h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _colcrt_module colcrt
shell-completion/colrm new file +23 -0
new file mode 100644
index 0000000..aa57c02
@@ -0,0 +1,23 @@
+_colrm_module()
+{
+	local cur OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $cur in
+		-*)
+			OPTS="-V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	case $COMP_CWORD in
+		1)
+			COMPREPLY=( $(compgen -W "startcol" -- $cur) )
+			;;
+		2)
+			COMPREPLY=( $(compgen -W "endcol" -- $cur) )
+			;;
+	esac
+	return 0
+}
+complete -F _colrm_module colrm
shell-completion/column new file +34 -0
new file mode 100644
index 0000000..94e1a51
@@ -0,0 +1,34 @@
+_column_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-c'|'--columns')
+			COMPREPLY=( $(compgen -W "number" -- $cur) )
+			return 0
+			;;
+		'-s'|'--separator'|'-o'|'--output-separator')
+			COMPREPLY=( $(compgen -W "string" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-c --columns
+				-t --table
+				-s --separator
+				-o --output-separator
+				-x --fillrows
+				-h --help
+				-V --version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _column_module column
shell-completion/hexdump new file +32 -0
new file mode 100644
index 0000000..1a6786b
@@ -0,0 +1,32 @@
+_hexdump_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-e')
+			COMPREPLY=( $(compgen -W "format" -- $cur) )
+			return 0
+			;;
+		'-n')
+			COMPREPLY=( $(compgen -W "length" -- $cur) )
+			return 0
+			;;
+		'-s')
+			COMPREPLY=( $(compgen -W "offset" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-b -c -C -d -o -x -e -f -n -s -v -V"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _hexdump_module hexdump
shell-completion/more new file +22 -0
new file mode 100644
index 0000000..f32770d
@@ -0,0 +1,22 @@
+_more_module()
+{
+	local cur OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $cur in
+		-*)
+			OPTS="-d -f -l -p -c -u -s -number -V"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+		+*)
+			OPTS="+number +/string"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _more_module more
shell-completion/pg new file +29 -0
new file mode 100644
index 0000000..4ae8887
@@ -0,0 +1,29 @@
+_pg_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-p')
+			COMPREPLY=( $(compgen -W "prompt" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-number -c -e -f -n -p -r -s -h -V"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+		+*)
+			OPTS="+number +/pattern/"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _pg_module pg
shell-completion/rev new file +17 -0
new file mode 100644
index 0000000..f891f19
@@ -0,0 +1,17 @@
+_rev_module()
+{
+	local cur OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	case $cur in
+		-*)
+			OPTS="-V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _rev_module rev
shell-completion/tailf new file +24 -0
new file mode 100644
index 0000000..29c5bed
@@ -0,0 +1,24 @@
+_tailf_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-n'|'--lines')
+			COMPREPLY=( $(compgen -W "number" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-n --lines -number -V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _tailf_module tailf
shell-completion/ul new file +25 -0
new file mode 100644
index 0000000..89e2800
@@ -0,0 +1,25 @@
+_ul_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-t'|'--terminal')
+			# FIXME: terminal type list would be nice
+			COMPREPLY=( $(compgen -W "vt100 xterm linux screen etc" -- $cur) )
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-t --terminal -i --indicated -V --version -h --help"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	compopt -o filenames
+	COMPREPLY=( $(compgen -f -- $cur) )
+	return 0
+}
+complete -F _ul_module ul
Signature · 1 line
1.8.2
#27 lore raw

PATCH 10/10 bash-completion: add completion files to Makefile.am

In reply to Sami Kerola

And remove shell completion TODO item.

---
 Documentation/TODO             |   6 -
 shell-completion/Makemodule.am | 261 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 260 insertions(+), 7 deletions(-)
Documentation/TODO +0 -6
index b4139d3..4adf05d 100644
@@ -8,12 +8,6 @@ hwlock
  - the /var/lib/hwclock/drift should be implemented backwardly compatible,
    it means use the file only if exists, otherwise follow /etc/adjtime 
 
-bash completion
----------------
- - file per command in shel-completion/bash/
- - use $(pkg-config --variable=completionsdir bash-completion)/util-linux/
-   as a destination install directory
-
 wipefs
 ------
  - generate /root/wipefs-<devname>-<offset>.bak with wiped bytes, so after 
shell-completion/Makemodule.am +260 -1

261 lines not on this page · raw message

Signature · 1 line
1.8.2
#28 lore raw
In reply to Sami Kerola
Quoted 13 lines · Sami Kerola

Hello,

Here is a pull request, which does two things; an introduction of bash completetion to util-linux, and most FIXME items ever sent to review in single batch (26).

Most of the brokenness in this batch series has got to do with a comma separate value list, e.g., 'value1,another,foobar', which one would expect to continue filling with 'value1,<tab>' but that does not work. I am almost sure that one might achieve continue the list by setting comma to COMP_WORDBREAKS, and check if $prev is in known words list, but I simply did not get that to work (I suspect PEBKAC).

Quoted 8 lines

Some FIXME's are slightly more difficult to fix. For example I do not know how to get list of possible TERM values distribution agnostic way. And with 'wdctl' I have no how to determine flags. Same goes for SELinux labels & Apparmor provilles for setpriv. Anyhow, if someone wants to help, give hints, or even directly fix something feel free to reply the later patches what could be done to an instance of a problem.

Of course any other sort of feedback is also welcome.

Hi Sami,

I think this is a great start. I've commented on a few of your patches and pointed out where I think there's room for improvement. I haven't commented on everything, but I think you'll be able to apply some of the advice in a general sense (if you're so inclined).

Quoted 224 lines

The following changes since commit 4cd271adc1dd3231e705c9e074491a7f49a721b8:

libmount: make mnt_table_find_* more robust [coverity scan] (2013-03-27 16:47:46 +0100)

are available in the git repository at:

git://github.com/kerolasa/lelux-utiliteetit.git shell-completion

for you to fetch changes up to e8b90f9baffd36a95bab408a3859b04543577a1b:

bash-completion: add completion files to Makefile.am (2013-03-27 21:31:25 +0000)

----------------------------------------------------------------
Sami Kerola (10):
bash-completion: add bash completetion configure option
bash-completion: disk-utils
bash-completion: fdisks
bash-completion: login-utils
bash-completion: misc-utils
bash-completion: schedutils
bash-completion: sys-utils
bash-completion: term-utils
bash-completion: text-utils
bash-completion: add completion files to Makefile.am

 Documentation/TODO             |   6 -
 Makefile.am                    |   5 +
 configure.ac                   |  13 +++
 shell-completion/Makemodule.am | 260 +++++++++++++++++++++++++++++++++++++++++
 shell-completion/addpart       |  25 ++++
 shell-completion/agetty        |  70 +++++++++++
 shell-completion/blkdiscard    |  25 ++++
 shell-completion/blkid         |  62 ++++++++++
 shell-completion/blockdev      |  44 +++++++
 shell-completion/cal           |  15 +++
 shell-completion/cfdisk        |  31 +++++
 shell-completion/chcpu         |  44 +++++++
 shell-completion/chfn          |  31 +++++
 shell-completion/chrt          |  32 +++++
 shell-completion/chsh          |  23 ++++
 shell-completion/col           |  24 ++++
 shell-completion/colcrt        |  20 ++++
 shell-completion/colrm         |  23 ++++
 shell-completion/column        |  34 ++++++
 shell-completion/ctrlaltdel    |  11 ++
 shell-completion/cytune        |  37 ++++++
 shell-completion/delpart       |  19 +++
 shell-completion/dmesg         |  53 +++++++++
 shell-completion/eject         |  61 ++++++++++
 shell-completion/fallocate     |  24 ++++
 shell-completion/fdformat      |  11 ++
 shell-completion/fdisk         |  41 +++++++
 shell-completion/findmnt       | 114 ++++++++++++++++++
 shell-completion/flock         |  42 +++++++
 shell-completion/fsck          |  36 ++++++
 shell-completion/fsck.cramfs   |  18 +++
 shell-completion/fsck.minix    |  11 ++
 shell-completion/fsfreeze      |  18 +++
 shell-completion/fstrim        |  25 ++++
 shell-completion/getopt        |  34 ++++++
 shell-completion/hexdump       |  32 +++++
 shell-completion/hwclock       |  53 +++++++++
 shell-completion/ionice        |  34 ++++++
 shell-completion/ipcrm         |  52 +++++++++
 shell-completion/ipcs          |  30 +++++
 shell-completion/isosize       |  17 +++
 shell-completion/last          |  38 ++++++
 shell-completion/ldattach      |  54 +++++++++
 shell-completion/logger        |  43 +++++++
 shell-completion/login         |  27 +++++
 shell-completion/look          |  24 ++++
 shell-completion/losetup       |  64 ++++++++++
 shell-completion/lsblk         |  60 ++++++++++
 shell-completion/lscpu         |  39 +++++++
 shell-completion/lslocks       |  43 +++++++
 shell-completion/mcookie       |  23 ++++
 shell-completion/mesg          |  16 +++
 shell-completion/mkfs          |  25 ++++
 shell-completion/mkfs.bfs      |  28 +++++
 shell-completion/mkfs.cramfs   |  40 +++++++
 shell-completion/mkfs.minix    |  33 ++++++
 shell-completion/mkswap        |  36 ++++++
 shell-completion/more          |  22 ++++
 shell-completion/mountpoint    |  24 ++++
 shell-completion/namei         |  17 +++
 shell-completion/newgrp        |  16 +++
 shell-completion/nsenter       |  47 ++++++++
 shell-completion/partx         |  37 ++++++
 shell-completion/pg            |  29 +++++
 shell-completion/pivot_root    |  14 +++
 shell-completion/prlimit       |  55 +++++++++
 shell-completion/raw           |  17 +++
 shell-completion/readprofile   |  33 ++++++
 shell-completion/rename        |  27 +++++
 shell-completion/renice        |  38 ++++++
 shell-completion/resizepart    |  22 ++++
 shell-completion/rev           |  17 +++
 shell-completion/rtcwake       |  40 +++++++
 shell-completion/script        |  38 ++++++
 shell-completion/scriptreplay  |  28 +++++
 shell-completion/setarch       |  42 +++++++
 shell-completion/setpriv       |  82 +++++++++++++
 shell-completion/setsid        |  17 +++
 shell-completion/setterm       | 109 +++++++++++++++++
 shell-completion/sfdisk        |  72 ++++++++++++
 shell-completion/su            |  45 +++++++
 shell-completion/sulogin       |  24 ++++
 shell-completion/swaplabel     |  28 +++++
 shell-completion/swapon        |  48 ++++++++
 shell-completion/tailf         |  24 ++++
 shell-completion/taskset       |  38 ++++++
 shell-completion/tunelp        |  48 ++++++++
 shell-completion/ul            |  25 ++++
 shell-completion/unshare       |  24 ++++
 shell-completion/utmpdump      |  17 +++
 shell-completion/uuidd         |  33 ++++++
 shell-completion/uuidgen       |  15 +++
 shell-completion/wall          |  24 ++++
 shell-completion/wdctl         |  48 ++++++++
 shell-completion/whereis       |  24 ++++
 shell-completion/wipefs        |  38 ++++++
 shell-completion/write         |  19 +++
 97 files changed, 3512 insertions(+), 6 deletions(-)
 create mode 100644 shell-completion/Makemodule.am
 create mode 100644 shell-completion/addpart
 create mode 100644 shell-completion/agetty
 create mode 100644 shell-completion/blkdiscard
 create mode 100644 shell-completion/blkid
 create mode 100644 shell-completion/blockdev
 create mode 100644 shell-completion/cal
 create mode 100644 shell-completion/cfdisk
 create mode 100644 shell-completion/chcpu
 create mode 100644 shell-completion/chfn
 create mode 100644 shell-completion/chrt
 create mode 100644 shell-completion/chsh
 create mode 100644 shell-completion/col
 create mode 100644 shell-completion/colcrt
 create mode 100644 shell-completion/colrm
 create mode 100644 shell-completion/column
 create mode 100644 shell-completion/ctrlaltdel
 create mode 100644 shell-completion/cytune
 create mode 100644 shell-completion/delpart
 create mode 100644 shell-completion/dmesg
 create mode 100644 shell-completion/eject
 create mode 100644 shell-completion/fallocate
 create mode 100644 shell-completion/fdformat
 create mode 100644 shell-completion/fdisk
 create mode 100644 shell-completion/findmnt
 create mode 100644 shell-completion/flock
 create mode 100644 shell-completion/fsck
 create mode 100644 shell-completion/fsck.cramfs
 create mode 100644 shell-completion/fsck.minix
 create mode 100644 shell-completion/fsfreeze
 create mode 100644 shell-completion/fstrim
 create mode 100644 shell-completion/getopt
 create mode 100644 shell-completion/hexdump
 create mode 100644 shell-completion/hwclock
 create mode 100644 shell-completion/ionice
 create mode 100644 shell-completion/ipcrm
 create mode 100644 shell-completion/ipcs
 create mode 100644 shell-completion/isosize
 create mode 100644 shell-completion/last
 create mode 100644 shell-completion/ldattach
 create mode 100644 shell-completion/logger
 create mode 100644 shell-completion/login
 create mode 100644 shell-completion/look
 create mode 100644 shell-completion/losetup
 create mode 100644 shell-completion/lsblk
 create mode 100644 shell-completion/lscpu
 create mode 100644 shell-completion/lslocks
 create mode 100644 shell-completion/mcookie
 create mode 100644 shell-completion/mesg
 create mode 100644 shell-completion/mkfs
 create mode 100644 shell-completion/mkfs.bfs
 create mode 100644 shell-completion/mkfs.cramfs
 create mode 100644 shell-completion/mkfs.minix
 create mode 100644 shell-completion/mkswap
 create mode 100644 shell-completion/more
 create mode 100644 shell-completion/mountpoint
 create mode 100644 shell-completion/namei
 create mode 100644 shell-completion/newgrp
 create mode 100644 shell-completion/nsenter
 create mode 100644 shell-completion/partx
 create mode 100644 shell-completion/pg
 create mode 100644 shell-completion/pivot_root
 create mode 100644 shell-completion/prlimit
 create mode 100644 shell-completion/raw
 create mode 100644 shell-completion/readprofile
 create mode 100644 shell-completion/rename
 create mode 100644 shell-completion/renice
 create mode 100644 shell-completion/resizepart
 create mode 100644 shell-completion/rev
 create mode 100644 shell-completion/rtcwake
 create mode 100644 shell-completion/script
 create mode 100644 shell-completion/scriptreplay
 create mode 100644 shell-completion/setarch
 create mode 100644 shell-completion/setpriv
 create mode 100644 shell-completion/setsid
 create mode 100644 shell-completion/setterm
 create mode 100644 shell-completion/sfdisk
 create mode 100644 shell-completion/su
 create mode 100644 shell-completion/sulogin
 create mode 100644 shell-completion/swaplabel
 create mode 100644 shell-completion/swapon
 create mode 100644 shell-completion/tailf
 create mode 100644 shell-completion/taskset
 create mode 100644 shell-completion/tunelp
 create mode 100644 shell-completion/ul
 create mode 100644 shell-completion/unshare
 create mode 100644 shell-completion/utmpdump
 create mode 100644 shell-completion/uuidd
 create mode 100644 shell-completion/uuidgen
 create mode 100644 shell-completion/wall
 create mode 100644 shell-completion/wdctl
 create mode 100644 shell-completion/whereis
 create mode 100644 shell-completion/wipefs
 create mode 100644 shell-completion/write

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#29 lore raw
In reply to Sami Kerola
Quoted 2 lines · Sami Kerola
Quoted 2 lines

Some FIXME's are slightly more difficult to fix. For example I do not know how to get list of possible TERM values distribution agnostic way.

Well, I think we can start with some nice hardcoded list..

Quoted 1 line
Quoted 1 line

And with 'wdctl' I have no how to determine flags. Same goes for SELinux

    wdctl --flags-only -o FLAG 

returns currently supported flags (by the device), the complete list of the flags is:

CARDRESET
EXTERN1
EXTERN2
FANFAULT
KEEPALIVEPING
MAGICCLOSE
OVERHEAT
POWEROVER
POWERUNDER
PRETIMEOUT
SETTIMEOUT
ALARMONLY

I think it's fine to use this hardcoded list.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#30 lore raw
Quoted 27 lines · Karel Zak
Quoted 2 lines · Sami Kerola
Quoted 2 lines

Some FIXME's are slightly more difficult to fix. For example I do not know how to get list of possible TERM values distribution agnostic way.

Well, I think we can start with some nice hardcoded list..

Quoted 1 line
Quoted 1 line

And with 'wdctl' I have no how to determine flags. Same goes for

SELinux

    wdctl --flags-only -o FLAG

returns currently supported flags (by the device), the complete list of the flags is:

CARDRESET
EXTERN1
EXTERN2
FANFAULT
KEEPALIVEPING
MAGICCLOSE
OVERHEAT
POWEROVER
POWERUNDER
PRETIMEOUT
SETTIMEOUT
ALARMONLY

Quoted 2 lines

I think it's fine to use this hardcoded list.

Hello,

I did something to some of the stuff that was mentioned by Dave & Karel. The following changes can be found from git://
github.com/kerolasa/lelux-utiliteetit.git shell-completion.

shell-completion/Makemodule.am +0 -12
index 0bb8652..b657604 100644
@@ -90,10 +90,6 @@ if BUILD_LAST
 dist_bashcompletion_DATA += \
 	shell-completion/last
 endif
-if BUILD_LOGIN
-dist_bashcompletion_DATA += \
-	shell-completion/login
-endif
 if BUILD_NEWGRP
 dist_bashcompletion_DATA += \
 	shell-completion/newgrp
@@ -102,10 +98,6 @@ if BUILD_SU
 dist_bashcompletion_DATA += \
 	shell-completion/su
 endif
-if BUILD_SULOGIN
-dist_bashcompletion_DATA += \
-	shell-completion/sulogin
-endif
 if BUILD_UTMPDUMP
 dist_bashcompletion_DATA += \
 	shell-completion/utmpdump
@@ -222,10 +214,6 @@ endif
 # ...sys-utils
 
 # term-utils...
-if BUILD_AGETTY
-dist_bashcompletion_DATA += \
-	shell-completion/agetty
-endif
 if BUILD_MESG
 dist_bashcompletion_DATA += \
 	shell-completion/mesg
shell-completion/addpart +2 -3
index 07ebf5e..1fa34a7 100644
@@ -1,6 +1,6 @@
 _addpart_module()
 {
-	local cur
+	local cur prev
 	COMPREPLY=()
 	cur="${COMP_WORDS[COMP_CWORD]}"
 	case $COMP_CWORD in
@@ -11,7 +11,7 @@ _addpart_module()
 			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
 			;;
 		2)
-			COMPREPLY=( $(compgen -W "$((1 + $(ls $prev?* 2>/dev/null | wc
-l)))" -- $cur) )
+			# FIXME: how to determine next free partition number
 			;;
 		3)

COMPREPLY=( $(compgen -W "start" -- $cur) )

shell-completion/agetty deleted +0 -70

70 lines not on this page · raw message

shell-completion/blkdiscard +1 -1
index e907a1b..7d85bce 100644
@@ -18,7 +18,7 @@ _blkdiscard_module()
 			;;
 	esac
 	local DEVS
-	DEVS="$(\ls -d /sys/class/block/* | sed 's|/sys/class/block/|/dev/|g')"
+	DEVS="$(lsblk -o NAME -n -r -p)"
 	COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
 	return 0
 }
shell-completion/blkid +1 -1
index dce41e0..05e337b 100644
@@ -23,11 +23,11 @@ _blkid_module()
 			return 0
 			;;
 		'-L')
-			COMPREPLY=( $(compgen -W "$(\ls /dev/disk/by-label/ 2>/dev/null)" -- $cur) )
+			COMPREPLY=( $(compgen -W "$(cd /dev/disk/by-label/ 2>/dev/null &&

echo *)" -- $cur) )
return 0
;;
'-U')
- COMPREPLY=( $(compgen -W "$(\ls /dev/disk/by-uuid/ 2>/dev/null)" -- $cur) )
+ COMPREPLY=( $(compgen -W "$(cd /dev/disk/by-uuid/ 2>/dev/null &&
echo *)" -- $cur) )
return 0
;;
'-s')
@@ -55,7 +55,7 @@ _blkid_module()
;;
esac
local PARTITIONS
- PARTITIONS="$(for I in /sys/block/*/*/partition; do IFS='/';
DIR_ARR=($I); echo "/dev/${DIR_ARR[4]}"; done)"
+ PARTITIONS="$(lsblk -o NAME,TYPE -n -r -p | awk '$2 ~ /part/ {print $1}')"
COMPREPLY=( $(compgen -W "$PARTITIONS" -- $cur) ) return 0
}

shell-completion/cfdisk +0 -1
index 8da32fd..3725645 100644
@@ -25,7 +25,7 @@ _cfdisk_module()
 			return 0
 			;;
 	esac
-	COMPREPLY=( $(compgen -W "$(lsblk -o NAME,TYPE -n -r | awk '$2 ~

/disk/ {print "/dev/" $1}')" -- $cur) )
+ COMPREPLY=( $(compgen -W "$(lsblk -o NAME,TYPE -n -r -p | awk '$2 ~
/disk/ {print $1}')" -- $cur) )
return 0
}
complete -F _cfdisk_module cfdisk

shell-completion/chfn +1 -16
index 1c5167a..a8eaee5 100644
@@ -1,23 +1,8 @@
 _chfn_module()
 {
-	local cur prev OPTS
+	local cur OPTS
 	COMPREPLY=()
 	cur="${COMP_WORDS[COMP_CWORD]}"
-	prev="${COMP_WORDS[COMP_CWORD-1]}"
-	case $prev in
-		'-f'|'--full-name')
-			COMPREPLY=( $(compgen -W "name" -- $cur) )
-			return 0
-			;;
-		'-o'|'--office')
-			COMPREPLY=( $(compgen -W "office" -- $cur) )
-			return 0
-			;;
-		'-p'|'--office-phone'|'-h'|'--home-phone')
-			COMPREPLY=( $(compgen -W "phone-nr" -- $cur) )
-			return 0
-			;;
-	esac
 	case $cur in
 		-*)
 			OPTS="-f --full-name -o --office -p --office-phone -h --home-phone

-u --help -v --version"

shell-completion/chrt +1 -1
index 08912c9..b85775a 100644
@@ -25,7 +25,7 @@ _chrt_module()
 			;;
 	esac
 	local PIDS
-	PIDS=$(\ls -d /proc/[0-9]* | sed 's|/proc/||')
+	PIDS=$(for I in /proc/[0-9]*; do echo ${I##"/proc/"}; done)
 	COMPREPLY=( $(compgen -W "$PIDS" -- $cur) )
 	return 0
 }
shell-completion/delpart +3 -2
index 849c018..a9cd3b7 100644
@@ -1,16 +1,17 @@
 _delpart_module()
 {
-	local cur OPTS
+	local cur prev OPTS
 	COMPREPLY=()
 	cur="${COMP_WORDS[COMP_CWORD]}"
 	case $COMP_CWORD in
 		1)
 			local DEVS
-			DEVS="$(lsblk -o NAME,TYPE -n -r | awk '$2 ~ /disk/ {print "/dev/" $1}')"
+			DEVS="$(lsblk -o NAME,TYPE -n -p -r | awk '$2 ~ /disk/ {print $1}')"
 			OPTS="-h --help -V --version $DEVS"
 			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
 			;;
 		2)
+			prev="${COMP_WORDS[COMP_CWORD-1]}"
 			COMPREPLY=( $(compgen -W "$(cat /sys/block/${prev##*/}/*/partition

2>/dev/null)" -- $cur) )
;;
esac

shell-completion/fdformat +1 -1
index f7d6a8e..4ad1c3d 100644
@@ -3,7 +3,7 @@ _fdformat_module()
 	local cur OPTS
 	COMPREPLY=()
 	cur="${COMP_WORDS[COMP_CWORD]}"
-	DEVS=$(ls /dev/fd[0-9]* 2>/dev/null)
+	DEVS=$(for I in echo /dev/fd*; do if [ -e $I ]; then echo $I; fi; done)
 	OPTS="-n --no-verify -h --help -V --version $DEVS"
 	COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
 	return 0
shell-completion/fdisk +0 -1
index ccf2015..a8a2a37 100644
@@ -7,7 +7,7 @@ _fdisk_module()
 	case $prev in
 		'-s')
 			local PARTITIONS
-			PARTITIONS="$(for I in /sys/block/*/*/partition; do IFS='/';

DIR_ARR=($I); echo "/dev/${DIR_ARR[4]}"; done)"
+ PARTITIONS="$(lsblk -o NAME,TYPE -n -r -p | awk '$2 ~ /part/ {print $1}')"
COMPREPLY=( $(compgen -W "$PARTITIONS" -- $cur) ) return 0
;;
@@ -35,7 +35,7 @@ _fdisk_module()
return 0
;;
esac
- COMPREPLY=( $(compgen -W "$(lsblk -o NAME,TYPE -n -r | awk '$2 ~
/disk/ {print "/dev/" $1}')" -- $cur) )
+ COMPREPLY=( $(compgen -W "$(lsblk -o NAME,TYPE -n -r -p | awk '$2 ~
/disk/ {print $1}')" -- $cur) )
return 0
}
complete -F _fdisk_module fdisk

shell-completion/findmnt +0 -2
index 5207b97..413d36a 100644
@@ -29,9 +29,16 @@ _findmnt_module()
 			return 0
 			;;
 		'-O'|'--options')
-			local MNT_OPTS
-			MNT_OPTS=$(awk '{ n = split($4, a, ","); for (i = 0; i <= n; i++)

{ mnt_opts[a[i]]=1 } } END { for (i in mnt_opts) { print i } }' /etc/mtab 2>/dev/null )
- COMPREPLY=( $(compgen -W "$MNT_OPTS" -- $cur) )
+ local MTAB_3RD I
+ declare -a TMP_ARR
+ declare -A MNT_OPTS
+ while read _ _ _ MTAB_3RD _; do
+ IFS=',' read -ra TMP_ARR <<<"$MTAB_3RD"
+ for I in ${TMP_ARR[@]}; do
+ MNT_OPTS[$I]='1'
+ done
+ done </etc/mtab
+ COMPREPLY=( $(compgen -W "$(echo ${!MNT_OPTS[@]})" -- $cur) )
return 0
;;
'-o'|'--output')

shell-completion/fsck +1 -1
index c3da5f5..a8f054f 100644
@@ -29,7 +29,7 @@ _fsck_module()
 			return 0
 			;;
 	esac
-	DEVS="$(lsblk -o NAME -n -r | awk '{print "/dev/" $1}')"
+	DEVS="$(lsblk -o NAME -n -r -p)"
 	COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
 	return 0
 }
shell-completion/fsck.minix +1 -1
index f01626a..69ac714 100644
@@ -3,7 +3,7 @@ _fsck.minix_module()
 	local cur OPTS DEVS
 	COMPREPLY=()
 	cur="${COMP_WORDS[COMP_CWORD]}"
-	DEVS="$(lsblk -o NAME -n -r | awk '{print "/dev/" $1}')"
+	DEVS="$(lsblk -o NAME -n -r -p)"
 	OPTS="-l -a -r -v -s -m -f -V --version"
 	COMPREPLY=( $(compgen -W "${OPTS[*]} $DEVS" -- $cur) )
 	return 0
shell-completion/ionice +1 -1
index 3087c4a..2180718 100644
@@ -15,7 +15,7 @@ _ionice_module()
 			;;
 		'-p'|'--pid')
 			local PIDS
-			PIDS=$(\ls -d /proc/[0-9]* | sed 's|/proc/||')
+			PIDS=$(for I in /proc/[0-9]*; do echo ${I##"/proc/"}; done)
 			COMPREPLY=( $(compgen -W "$PIDS" -- $cur) )
 			return 0
 			;;
shell-completion/ipcrm +8 -1
index 4b1024f..da9f783 100644
@@ -36,13 +36,20 @@ _ipcrm_module()
 			return 0
 			;;
 	esac
+	case $cur in
+		'=')
+			cur=${cur#=}
+			COMPREPLY=( $(compgen -W "shm msg sem" -- $cur) )
+			return 0
+			;;
+	esac
 	OPTS="	-m --shmem-id
 		-M --shmem-key
 		-q --queue-id
 		-Q --queue-key
 		-s --semaphore-id
 		-S --semaphore-key
-		-a --all
+		-a --all=
 		-v --verbose
 		-h --help
 		-V --version"
shell-completion/login deleted +0 -27
deleted file mode 100644
index c075f64..0000000
@@ -1,27 +0,0 @@
-_login_module()
-{
-	local cur prev OPTS
-	COMPREPLY=()
-	cur="${COMP_WORDS[COMP_CWORD]}"
-	prev="${COMP_WORDS[COMP_CWORD-1]}"
-	case $prev in
-		'-f')
-			COMPREPLY=( $(compgen -u -- $cur) )
-			return 0
-			;;
-		'-h')
-			COMPREPLY=( $(compgen -A hostname -- $cur) )
-			return 0
-			;;
-	esac
-	case $cur in
-		-*)
-			OPTS="-p -f -h -H -V"
-			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
-			return 0
-			;;
-	esac
-	COMPREPLY=( $(compgen -u -- $cur) )
-	return 0
-}
-complete -F _login_module login
shell-completion/losetup +1 -1
index b21f05d..329bb05 100644
@@ -16,7 +16,7 @@ _losetup_module()
 			return 0
 			;;
 		'-c'|'--set-capacity')
-			ARG="$(\ls /dev/loop[0-9]* 2>/dev/null)"
+			ARG="$(for I in /dev/loop[0-9]*; do if [ -e $I ]; then echo $I; fi; done)"
 			COMPREPLY=( $(compgen -W "$ARG" -- $cur) )
 			return 0
 			;;
shell-completion/lsblk +8 -3
index 521cead..4b5973d 100644
@@ -1,12 +1,17 @@
 _lsblk_module()
 {
-	local cur prev OPTS MAJOR
+	local cur prev OPTS
 	COMPREPLY=()
 	cur="${COMP_WORDS[COMP_CWORD]}"
 	prev="${COMP_WORDS[COMP_CWORD-1]}"
 	case $prev in
 		'-e'|'--exclude'|'-I'|'--include')
-			MAJOR=$(\ls /sys/dev/block/ | sed 's/:.*//')
+			local MAJOR I J
+			MAJOR=''
+			for I in /sys/dev/block/*; do
+				J=${I##*/}
+				MAJOR="$MAJOR ${J%%:*}"
+			done
 			# FIXME: how to append to a string with compgen?
 			compopt -o nospace
 			COMPREPLY=( $(compgen -W "$MAJOR" -S ',' -- $cur) )
@@ -53,7 +58,7 @@ _lsblk_module()
 			;;
 	esac
 	local DEVS
-	DEVS="$(\ls -d /sys/class/block/* | sed 's|/sys/class/block/|/dev/|g')"
+	DEVS="$(lsblk -o NAME -n -r -p)"
 	COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
 	return 0
 }
shell-completion/lscpu +16 -10
index bb76d4c..38ef07b 100644
@@ -1,19 +1,25 @@
 _lscpu_module()
 {
-	local cur prev OPTS
+	local cur OPTS
 	COMPREPLY=()
 	cur="${COMP_WORDS[COMP_CWORD]}"
 	prev="${COMP_WORDS[COMP_CWORD-1]}"
 	case $prev in
-		'-e'|'--extended'|'-p'|'--parse')
+		'--extended'|'=')
+			cur=${cur#=}
 			# FIXME: how to append to a string with compgen?
-			# FIXME: space in between option and argument is
-			# 	 a problem.
-			local OUTPUT
-			OUTPUT="CPU CORE SOCKET NODE BOOK CACHE
-				POLARIZATION ADDRESS CONFIGURED ONLINE"
+			OPTS="CPU,
+				CORE,
+				SOCKET,
+				NODE,
+				BOOK,
+				CACHE,
+				POLARIZATION,
+				ADDRESS,
+				CONFIGURED,
+				ONLINE,"
 			compopt -o nospace
-			COMPREPLY=( $(compgen -W "$OUTPUT" -S ',' -- $cur) )
+			COMPREPLY=( $(compgen -W "$OPTS" -- $cur) )
 			return 0
 			;;
 	esac
@@ -22,8 +28,8 @@ _lscpu_module()
 			OPTS="-a --all
 				-b --online
 				-c --offline
-				-e --extended
-				-p --parse
+				-e --extended=
+				-p --parse=
 				-s --sysroot
 				-x --hex
 				-h --help
shell-completion/mkfs +0 -1
index ee6a26b..ac56841 100644
@@ -6,7 +6,7 @@ _mkfs_module()
 	prev="${COMP_WORDS[COMP_CWORD-1]}"
 	case $prev in
 		'-t'|'--type')
-			FSTYPES=$(for I in $(\ls /sbin/mkfs.* /usr/sbin/mkfs.*

2>/dev/null); do echo ${I##*mkfs.}; done)
+ FSTYPES=$(for I in /sbin/mkfs.* /usr/sbin/mkfs.*; do if [ -e $I ];
then echo ${I##*mkfs.}; fi; done)
COMPREPLY=( $(compgen -W "$FSTYPES" -- $cur) ) return 0
;;
@@ -18,7 +18,7 @@ _mkfs_module()
return 0
;;
esac
- DEVS="$(lsblk -o NAME -n -r | awk '{print "/dev/" $1}')"
+ DEVS="$(lsblk -o NAME -n -r -p)"
COMPREPLY=( $(compgen -W "$DEVS /path/to/file" -- $cur) ) return 0
}

shell-completion/mkfs.bfs +1 -1
index b1a226a..2d8e796 100644
@@ -21,7 +21,7 @@ _bfs_module()
 			return 0
 			;;
 	esac
-	DEVS="$(lsblk -o NAME -n -r | awk '{print "/dev/" $1}')"
+	DEVS="$(lsblk -o NAME -n -r -p)"
 	COMPREPLY=( $(compgen -W "$DEVS /path/to/file" -- $cur) )
 	return 0
 }
shell-completion/mkfs.minix +1 -1
index c717b3c..884a09b 100644
@@ -26,7 +26,7 @@ _mkfs.minix_module()
 			;;
 	esac
 	local DEVS
-	DEVS="$(lsblk -o NAME -n -r | awk '{print "/dev/" $1}')"
+	DEVS="$(lsblk -o NAME -n -r -p)"
 	COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
 	return 0
 }
shell-completion/nsenter +16 -19
index f15a7f1..168f740 100644
@@ -7,32 +7,29 @@ _nsenter_module()
 	case $prev in
 		'-t'|'--target')
 			local PIDS
-			PIDS=$(\ls -d /proc/[0-9]* | sed 's|/proc/||')
+			PIDS=$(for I in /proc/[0-9]*; do echo ${I##"/proc/"}; done)
 			COMPREPLY=( $(compgen -W "$PIDS" -- $cur) )
 			return 0
 			;;
-		'-m'|'--mount'|'-u'|'--uts'|'-i'|'--net'|'-n'|'--net'|'-p'|'--pid'|'-U'|'--user')
-			compopt -o filenames
-			COMPREPLY=( $(compgen -f -- $cur) )
-			return 0
-			;;
-		'-r'|'--root'|'-w'|'--wd')
-			compopt -o filenames
-			COMPREPLY=( $(compgen -o dirnames -- $cur) )
-			return 0
-			;;
 	esac
 	case $cur in
+		'=')
+			# FIXME: --root and --wd should use get only
+			# directories as compgen output.  If $cur is
+			# overwrote the same way as below in case segment
+			# for $prev the command-line will get mangled.
+			cur=${cur#=}
+			;;
 		-*)
 			OPTS="-t --target
-				-m --mount
-				-u --uts
-				-i --ipc
-				-n --net
-				-p --pid
-				-U --user
-				-r --root
-				-w --wd
+				-m --mount=
+				-u --uts=
+				-i --ipc=
+				-n --net=
+				-p --pid=
+				-U --user=
+				-r --root=
+				-w --wd=
 				-F --no-fork
 				-h --help
 				-V --version"
shell-completion/partx +0 -1
index c558d36..8187965 100644
@@ -7,7 +7,7 @@ _partx_module()
 	prev="${COMP_WORDS[COMP_CWORD-1]}"
 	case $prev in
 		'-n'|'--nr')
-			COMPREPLY=( $(compgen -W "$(lsblk -o NAME,TYPE -n -r | awk '$2 ~

/part/ {print "/dev/" $1}')" -- $cur) )
+ COMPREPLY=( $(compgen -W "$(lsblk -o NAME,TYPE -n -r -p | awk '$2
~ /part/ {print $1}')" -- $cur) )
return 0
;;
'-o'|'--output')

shell-completion/prlimit +21 -16
index ee49b79..55bd13f 100644
@@ -6,7 +6,7 @@ _prlimit_module()
 	prev="${COMP_WORDS[COMP_CWORD-1]}"
 	case $prev in
 		'-p'|'--pid')
-			PIDS=$(\ls -d /proc/[0-9]* | sed 's|/proc/||')
+			PIDS=$(for I in /proc/[0-9]*; do echo ${I##"/proc/"}; done)
 			COMPREPLY=( $(compgen -W "$PIDS" -- $cur) )
 			return 0
 			;;
@@ -20,6 +20,11 @@ _prlimit_module()
 			;;
 	esac
 	case $cur in
+		'=')
+			cur=${cur#=}
+			# FIXME: is there anything what could be printed
+			# as limit value(s)
+			;;
 		-*)
 			OPTS="-p --pid
 				-o --output
@@ -28,21 +33,21 @@ _prlimit_module()
 				   --verbose
 				-h --help
 				-V --version
-				-c --core
-				-d --data
-				-e --nice
-				-f --fsize
-				-i --sigpending
-				-l --memlock
-				-m --rss
-				-n --nofile
-				-q --msgqueue
-				-r --rtprio
-				-s --stack
-				-t --cpu
-				-u --nproc
-				-v --as
-				-x --locks
+				-c --core=
+				-d --data=
+				-e --nice=
+				-f --fsize=
+				-i --sigpending=
+				-l --memlock=
+				-m --rss=
+				-n --nofile=
+				-q --msgqueue=
+				-r --rtprio=
+				-s --stack=
+				-t --cpu=
+				-u --nproc=
+				-v --as=
+				-x --locks=
 				-y --rttime"
 			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
 			return 0
shell-completion/raw +1 -1
index 41e03f2..27f0354 100644
@@ -11,7 +11,7 @@ _raw_module()
 			return 0
 			;;
 	esac
-	COMPREPLY=( $(compgen -W "$(ls 2>/dev/null /dev/raw/*)" -- $cur) )
+	COMPREPLY=( $(compgen -W "$(for I in /dev/raw/*; do if [ -e $I ];

then echo $I; fi; done)" -- $cur) )
return 0
}
complete -F _raw_module raw

shell-completion/renice +1 -1
index bc80dac..aba00d7 100644
@@ -17,7 +17,7 @@ _renice_module()
 			;;
 		'-p'|'--pid')
 			local PIDS
-			PIDS=$(\ls -d /proc/[0-9]* | sed 's|/proc/||')
+			PIDS=$(for I in /proc/[0-9]*; do echo ${I##"/proc/"}; done)
 			COMPREPLY=( $(compgen -W "$PIDS" -- $cur) )
 			return 0
 			;;
shell-completion/resizepart +3 -2
index 827638a..cdd76d0 100644
@@ -1,16 +1,17 @@
 _resizepart_module()
 {
-	local cur OPTS
+	local cur prev OPTS
 	COMPREPLY=()
 	cur="${COMP_WORDS[COMP_CWORD]}"
 	case $COMP_CWORD in
 		1)
 			local DEVS
-			DEVS="$(lsblk -o NAME,TYPE -n -r | awk '$2 ~ /disk/ {print "/dev/" $1}')"
+			DEVS="$(lsblk -o NAME,TYPE -n -r -p | awk '$2 ~ /disk/ {print $1}')"
 			OPTS="-h --help -V --version $DEVS"
 			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
 			;;
 		2)
+			prev="${COMP_WORDS[COMP_CWORD-1]}"
 			COMPREPLY=( $(compgen -W "$(cat /sys/block/${prev##*/}/*/partition

2>/dev/null)" -- $cur) )
;;
3)

shell-completion/rtcwake +1 -1
index 2010a52..1f38df8 100644
@@ -7,7 +7,7 @@ _rtcwake_module()
 	case $prev in
 		'-d'|'--device')
 			local RTC_DEVS
-			RTC_DEVS=$(\ls /sys/class/rtc/ 2>/dev/null)
+			RTC_DEVS=$(cd /sys/class/rtc/ && echo *)
 			COMPREPLY=( $(compgen -W "$RTC_DEVS" -- $cur) )
 			return 0
 			;;
shell-completion/script +4 -6
index fb6c106..e58dbd8 100644
@@ -10,13 +10,11 @@ _script_module()
 			COMPREPLY=( $(compgen -c -- $cur) )
 			return 0
 			;;
-		'-t'|'--timing')
-			compopt -o filenames
-			COMPREPLY=( $(compgen -f -- $cur) )
-			return 0
-			;;
 	esac
 	case $cur in
+		'=')
+			cur=${cur#=}
+			;;
 		-*)
 			OPTS="-a --append
 				-c --command
@@ -24,7 +22,7 @@ _script_module()
 				-f --flush
 				   --force
 				-q --quiet
-				-t --timing
+				-t --timing=
 				-V --version
 				-h --help"
 			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
shell-completion/setterm +8 -4
index a0dff44..33d2e56 100644
@@ -6,8 +6,12 @@ _setterm_module()
 	prev="${COMP_WORDS[COMP_CWORD-1]}"
 	case $prev in
 		'-term')
-			# FIXME: terminal type list would be nice
-			COMPREPLY=( $(compgen -W "vt100 xterm linux screen etc" -- $cur) )
+			local TERM_LIST I
+			TERM_LIST=''
+			for I in /usr/share/terminfo/?/*; do
+				TERM_LIST+="${I##*/} "
+			done
+			COMPREPLY=( $(compgen -W "$TERM_LIST" -- $cur) )
 			return 0
 			;;
 		'-foreground'|'-background'|'-ulcolor'|'-hbcolor')
@@ -36,8 +40,8 @@ _setterm_module()
 			;;
 		'-dump'|'-append')
 			local NUM_CONS
-			NUM_CONS=$(ls /sys/class/tty | wc -l)
-			COMPREPLY=( $(compgen -W "$(echo {1..$NUM_CONS})" -- $cur) )
+			NUM_CONS=(/sys/class/tty/*)
+			COMPREPLY=( $(compgen -W "$(echo {1..${#NUM_CONS[*]}})" -- $cur) )
 			return 0
 			;;
 		'-file')
shell-completion/sfdisk +5 -3
index 041ce55..835ecd2 100644
@@ -20,6 +20,9 @@ _sfdisk_module()
 			;;
 	esac
 	case $cur in
+		'=')
+			cur=${cur#=}
+			;;
 		-*)
 			OPTS="-s --show-size
 				-c --id
@@ -47,8 +50,8 @@ _sfdisk_module()
 				-L --Linux
 				-g --show-geometry
 				-G --show-pt-geometry
-				-A --activate
-				-U --unhide
+				-A --activate=
+				-U --unhide=
 				-x --show-extended
 				--leave-last
 				--IBM
@@ -66,7 +69,7 @@ _sfdisk_module()
 			return 0
 			;;
 	esac
-	COMPREPLY=( $(compgen -W "$(lsblk -o NAME,TYPE -n -r | awk '$2 ~

/disk/ {print "/dev/" $1}')" -- $cur) )
+ COMPREPLY=( $(compgen -W "$(lsblk -o NAME,TYPE -n -r -p | awk '$2 ~
/disk/ {print $1}')" -- $cur) )
return 0
}
complete -F _sfdisk_module sfdisk

shell-completion/su +5 -4
index ded4b7b..c5aa81e 100644
@@ -20,15 +20,16 @@ _su_module()
 	esac
 	case $cur in
 		-*)
-			OPTS="	-u --user
+			OPTS="	-
+				-u --user
 				-m -p --preserve-environment
 				-g --group
 				-G --supp-group
-				- -l --login
+				-l --login
 				-c --command
-				- -c
+				-c
 				--session-command
-				-- -c
+				-c
 				-f --fast
 				-s --shell
 				-h --help
shell-completion/sulogin deleted +0 -24
deleted file mode 100644
index 9fdc20e..0000000
@@ -1,24 +0,0 @@
-_sulogin_module()
-{
-	local cur prev OPTS
-	COMPREPLY=()
-	cur="${COMP_WORDS[COMP_CWORD]}"
-	prev="${COMP_WORDS[COMP_CWORD-1]}"
-	case $prev in
-		'-t'|'--timeout')
-			COMPREPLY=( $(compgen -W "seconds" -- $cur) )
-			return 0
-			;;
-	esac
-	case $cur in
-		-*)
-			OPTS="-p --login-shell -t --timeout -V --version -h --help"
-			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
-			return 0
-			;;
-	esac
-	compopt -o filenames
-	COMPREPLY=( $(compgen -f -- ${cur:-"/dev/tty"}) )
-	return 0
-}
-complete -F _sulogin_module sulogin
shell-completion/taskset +1 -1
index 81247cd..5311316 100644
@@ -19,7 +19,7 @@ _taskset_module()
 			# setting an affinity the optarg has to be cpu
 			# mask.  The following is good only for getting
 			# affinity.
-			PIDS=$(\ls -d /proc/[0-9]* | sed 's|/proc/||')
+			PIDS=$(for I in /proc/[0-9]*; do echo ${I##"/proc/"}; done)
 			COMPREPLY=( $(compgen -W "$PIDS" -- $cur) )
 			return 0
 			;;
shell-completion/ul +6 -2
index 89e2800..07d0731 100644
@@ -6,8 +6,12 @@ _ul_module()
 	prev="${COMP_WORDS[COMP_CWORD-1]}"
 	case $prev in
 		'-t'|'--terminal')
-			# FIXME: terminal type list would be nice
-			COMPREPLY=( $(compgen -W "vt100 xterm linux screen etc" -- $cur) )
+			local TERM_LIST I
+			TERM_LIST=''
+			for I in /usr/share/terminfo/?/*; do
+				TERM_LIST+="${I##*/} "
+			done
+			COMPREPLY=( $(compgen -W "$TERM_LIST" -- $cur) )
 			return 0
 			;;
 	esac
shell-completion/wdctl +14 -2
index 6a85e0a..42889ac 100644
@@ -6,8 +6,20 @@ _wdctl_module()
 	prev="${COMP_WORDS[COMP_CWORD-1]}"
 	case $prev in
 		'-f'|'--flags')
-			# FIXME: how to get flag list?
-			COMPREPLY=( $(compgen -W "flags" -- $cur) )
+			local FLAGS
+			FLAGS="ALARMONLY
+				CARDRESET
+				EXTERN1
+				EXTERN2
+				FANFAULT
+				KEEPALIVEPING
+				MAGICCLOSE
+				OVERHEAT
+				POWEROVER
+				POWERUNDER
+				PRETIMEOUT
+				SETTIMEOUT"
+			COMPREPLY=( $(compgen -W "$FLAGS" -- $cur) )
 			return 0
 			;;
 		'-o'|'--output')
shell-completion/wipefs +2 -8
index 427f47b..52c25b4 100644
@@ -11,13 +11,7 @@ _wipefs_module()
 			;;
 		'-t'|'--types')
 			local TYPES
-			TYPES="adfs affs autofs cifs coda coherent cramfs
-				debugfs devpts efs ext ext2 ext3 ext4 hfs
-				hfsplus hpfs iso9660 jfs minix msdos
-				ncpfs nfs nfs4 ntfs proc qnx4 ramfs
-				reiserfs romfs squashfs smbfs sysv tmpfs
-				ubifs udf ufs umsdos usbfs vfat xenix xfs
-				xiafs"
+			TYPES="$(blkid -k)"
 			COMPREPLY=( $(compgen -W "$TYPES" -- $cur) )
 			return 0
 			;;
@@ -31,7 +25,7 @@ _wipefs_module()
 			;;
 	esac
 	local DEVS
-	DEVS="$(\ls -d /sys/class/block/* | sed 's|/sys/class/block/|/dev/|g')"
+	DEVS="$(lsblk-o NAME -n -r -p)"
 	COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
 	return 0
 }
shell-completion/write +0 -1
index ba67569..d41159b 100644
@@ -9,7 +9,10 @@ _write_module()
 			return 0
 			;;
 		2)
-			local TERMS=$(for I in $(\ls /sys/class/tty 2>/dev/null); do echo

"/dev/$I"; done)
+ local I TERMS=''
+ for I in /sys/class/tty/*; do
+ TERMS+="/dev${I##/sys/class/tty} "
+ done
COMPREPLY=( $(compgen -W "$TERMS" -- $cur) ) return 0
;;

Signature · 2 lines
   Sami Kerola
   http://www.iki.fi/kerolasa/
#31 lore raw
In reply to Karel Zak
Quoted 26 lines · Karel Zak
Quoted 2 lines · Sami Kerola
Quoted 2 lines

Some FIXME's are slightly more difficult to fix. For example I do not know how to get list of possible TERM values distribution agnostic way.

Well, I think we can start with some nice hardcoded list..

Quoted 1 line
Quoted 1 line

And with 'wdctl' I have no how to determine flags. Same goes for SELinux

    wdctl --flags-only -o FLAG 

returns currently supported flags (by the device), the complete list of the flags is:

CARDRESET
EXTERN1
EXTERN2
FANFAULT
KEEPALIVEPING
MAGICCLOSE
OVERHEAT
POWEROVER
POWERUNDER
PRETIMEOUT
SETTIMEOUT
ALARMONLY

Quoted 1 line

I think it's fine to use this hardcoded list.

Hard coded list is in use for wdctl, and I have done few other changes which are collectively in my remote repository.

git://github.com/kerolasa/lelux-utiliteetit.git shell-completion

To be a bit less vague here are the changes since the previous submission.

shell-completion/Makemodule.am +0 -12
index 0bb8652..b657604 100644
@@ -90,10 +90,6 @@ if BUILD_LAST
 dist_bashcompletion_DATA += \
 	shell-completion/last
 endif
-if BUILD_LOGIN
-dist_bashcompletion_DATA += \
-	shell-completion/login
-endif
 if BUILD_NEWGRP
 dist_bashcompletion_DATA += \
 	shell-completion/newgrp
@@ -102,10 +98,6 @@ if BUILD_SU
 dist_bashcompletion_DATA += \
 	shell-completion/su
 endif
-if BUILD_SULOGIN
-dist_bashcompletion_DATA += \
-	shell-completion/sulogin
-endif
 if BUILD_UTMPDUMP
 dist_bashcompletion_DATA += \
 	shell-completion/utmpdump
@@ -222,10 +214,6 @@ endif
 # ...sys-utils
 
 # term-utils...
-if BUILD_AGETTY
-dist_bashcompletion_DATA += \
-	shell-completion/agetty
-endif
 if BUILD_MESG
 dist_bashcompletion_DATA += \
 	shell-completion/mesg
shell-completion/addpart +4 -4
index 07ebf5e..b6f119a 100644
@@ -1,17 +1,17 @@
 _addpart_module()
 {
-	local cur
+	local cur prev
 	COMPREPLY=()
 	cur="${COMP_WORDS[COMP_CWORD]}"
 	case $COMP_CWORD in
 		1)
-			local DEVS
-			DEVS="$(lsblk -o NAME -n -r)"
+			local DEVS=''
+			while read dev; do DEVS+="$dev " ; done < <(lsblk -pnro name)
 			OPTS="-h --help -V --version $DEVS"
 			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
 			;;
 		2)
-			COMPREPLY=( $(compgen -W "$((1 + $(ls $prev?* 2>/dev/null | wc -l)))" -- $cur) )
+			# FIXME: how to determine next free partition number
 			;;
 		3)
 			COMPREPLY=( $(compgen -W "start" -- $cur) )
shell-completion/agetty deleted +0 -70

70 lines not on this page · raw message

shell-completion/blkdiscard +1 -1
index e907a1b..757480c 100644
@@ -18,7 +18,7 @@ _blkdiscard_module()
 			;;
 	esac
 	local DEVS
-	DEVS="$(\ls -d /sys/class/block/* | sed 's|/sys/class/block/|/dev/|g')"
+	DEVS=''; while read dev; do DEVS+="$dev " ; done < <(lsblk -pnro name)
 	COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
 	return 0
 }
shell-completion/blkid +7 -5
index dce41e0..14222a4 100644
@@ -23,11 +23,11 @@ _blkid_module()
 			return 0
 			;;
 		'-L')
-			COMPREPLY=( $(compgen -W "$(\ls /dev/disk/by-label/ 2>/dev/null)" -- $cur) )
+			COMPREPLY=( $(compgen -W "$(cd /dev/disk/by-label/ 2>/dev/null && echo *)" -- $cur) )
 			return 0
 			;;
 		'-U')
-			COMPREPLY=( $(compgen -W "$(\ls /dev/disk/by-uuid/ 2>/dev/null)" -- $cur) )
+			COMPREPLY=( $(compgen -W "$(cd /dev/disk/by-uuid/ 2>/dev/null && echo *)" -- $cur) )
 			return 0
 			;;
 		'-s')
@@ -54,9 +54,11 @@ _blkid_module()
 			return 0
 			;;
 	esac
-	local PARTITIONS
-	PARTITIONS="$(for I in /sys/block/*/*/partition; do IFS='/'; DIR_ARR=($I); echo "/dev/${DIR_ARR[4]}"; done)"
-	COMPREPLY=( $(compgen -W "$PARTITIONS" -- $cur) )
+	local DEV TYPE DEVICES=''
+	while read DEV TYPE; do
+		[ $TYPE = 'part' ] && DEVICES+="$DEV "
+	done < <(lsblk -pnro name,type)
+	COMPREPLY=( $(compgen -W "$DEVICES" -- $cur) )
 	return 0
 }
 complete -F _blkid_module blkid
shell-completion/blockdev +1 -1
index 82ac6c1..ce986cb 100644
@@ -4,7 +4,7 @@ _blockdev_module()
 	COMPREPLY=()
 	cur="${COMP_WORDS[COMP_CWORD]}"
 	prev="${COMP_WORDS[COMP_CWORD-1]}"
-	DEVS="$(lsblk -o NAME -n -r)"
+	while read dev; do DEVS+="$dev " ; done < <(lsblk -pnro name)
 	OPTS="-h -V -q
 		--report
 		--getsz
shell-completion/cfdisk +5 -1
index 8da32fd..4be5186 100644
@@ -25,7 +25,11 @@ _cfdisk_module()
 			return 0
 			;;
 	esac
-	COMPREPLY=( $(compgen -W "$(lsblk -o NAME,TYPE -n -r | awk '$2 ~ /disk/ {print "/dev/" $1}')" -- $cur) )
+	local DEV TYPE DEVICES=''
+	while read DEV TYPE; do
+		[ $TYPE = 'disk' ] && DEVICES+="$DEV "
+	done < <(lsblk -pnro name,type)
+	COMPREPLY=( $(compgen -W "$DEVICES" -- $cur) )
 	return 0
 }
 complete -F _cfdisk_module cfdisk
shell-completion/chfn +1 -16
index 1c5167a..a8eaee5 100644
@@ -1,23 +1,8 @@
 _chfn_module()
 {
-	local cur prev OPTS
+	local cur OPTS
 	COMPREPLY=()
 	cur="${COMP_WORDS[COMP_CWORD]}"
-	prev="${COMP_WORDS[COMP_CWORD-1]}"
-	case $prev in
-		'-f'|'--full-name')
-			COMPREPLY=( $(compgen -W "name" -- $cur) )
-			return 0
-			;;
-		'-o'|'--office')
-			COMPREPLY=( $(compgen -W "office" -- $cur) )
-			return 0
-			;;
-		'-p'|'--office-phone'|'-h'|'--home-phone')
-			COMPREPLY=( $(compgen -W "phone-nr" -- $cur) )
-			return 0
-			;;
-	esac
 	case $cur in
 		-*)
 			OPTS="-f --full-name -o --office -p --office-phone -h --home-phone -u --help -v --version"
shell-completion/chrt +1 -1
index 08912c9..b85775a 100644
@@ -25,7 +25,7 @@ _chrt_module()
 			;;
 	esac
 	local PIDS
-	PIDS=$(\ls -d /proc/[0-9]* | sed 's|/proc/||')
+	PIDS=$(for I in /proc/[0-9]*; do echo ${I##"/proc/"}; done)
 	COMPREPLY=( $(compgen -W "$PIDS" -- $cur) )
 	return 0
 }
shell-completion/delpart +8 -4
index 849c018..e3ee406 100644
@@ -1,16 +1,20 @@
 _delpart_module()
 {
-	local cur OPTS
+	local cur prev OPTS
 	COMPREPLY=()
 	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
 	case $COMP_CWORD in
 		1)
-			local DEVS
-			DEVS="$(lsblk -o NAME,TYPE -n -r | awk '$2 ~ /disk/ {print "/dev/" $1}')"
-			OPTS="-h --help -V --version $DEVS"
+			local DEV TYPE DEVICES=''
+			while read DEV TYPE; do
+				[ $TYPE = 'disk' ] && DEVICES+="$DEV "
+			done < <(lsblk -pnro name,type)
+			OPTS="-h --help -V --version $DEVICES"
 			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
 			;;
 		2)
+			prev="${COMP_WORDS[COMP_CWORD-1]}"
 			COMPREPLY=( $(compgen -W "$(cat /sys/block/${prev##*/}/*/partition 2>/dev/null)" -- $cur) )
 			;;
 	esac
shell-completion/fdformat +1 -1
index f7d6a8e..4ad1c3d 100644
@@ -3,7 +3,7 @@ _fdformat_module()
 	local cur OPTS
 	COMPREPLY=()
 	cur="${COMP_WORDS[COMP_CWORD]}"
-	DEVS=$(ls /dev/fd[0-9]* 2>/dev/null)
+	DEVS=$(for I in echo /dev/fd*; do if [ -e $I ]; then echo $I; fi; done)
 	OPTS="-n --no-verify -h --help -V --version $DEVS"
 	COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
 	return 0
shell-completion/fdisk +10 -4
index ccf2015..ae94f10 100644
@@ -6,9 +6,11 @@ _fdisk_module()
 	prev="${COMP_WORDS[COMP_CWORD-1]}"
 	case $prev in
 		'-s')
-			local PARTITIONS
-			PARTITIONS="$(for I in /sys/block/*/*/partition; do IFS='/'; DIR_ARR=($I); echo "/dev/${DIR_ARR[4]}"; done)"
-			COMPREPLY=( $(compgen -W "$PARTITIONS" -- $cur) )
+			local DEV TYPE DEVICES=''
+			while read DEV TYPE; do
+				[ $TYPE = 'part' ] && DEVICES+="$DEV "
+			done < <(lsblk -pnro name,type)
+			COMPREPLY=( $(compgen -W "$DEVICES" -- $cur) )
 			return 0
 			;;
 		'-b')
@@ -35,7 +37,11 @@ _fdisk_module()
 			return 0
 			;;
 	esac
-	COMPREPLY=( $(compgen -W "$(lsblk -o NAME,TYPE -n -r | awk '$2 ~ /disk/ {print "/dev/" $1}')" -- $cur) )
+	local DEV TYPE DEVICES=''
+	while read DEV TYPE; do
+		[ $TYPE = 'disk' ] && DEVICES+="$DEV "
+	done < <(lsblk -pnro name,type)
+	COMPREPLY=( $(compgen -W "$DEVICES" -- $cur) )
 	return 0
 }
 complete -F _fdisk_module fdisk
shell-completion/findmnt +10 -3
index 5207b97..413d36a 100644
@@ -29,9 +29,16 @@ _findmnt_module()
 			return 0
 			;;
 		'-O'|'--options')
-			local MNT_OPTS
-			MNT_OPTS=$(awk '{ n = split($4, a, ","); for (i = 0; i <= n; i++) { mnt_opts[a[i]]=1 } } END { for (i in mnt_opts) { print i } }' /etc/mtab 2>/dev/null )
-			COMPREPLY=( $(compgen -W "$MNT_OPTS" -- $cur) )
+			local MTAB_3RD I
+			declare -a TMP_ARR
+			declare -A MNT_OPTS
+			while read _ _ _ MTAB_3RD _; do
+				IFS=',' read -ra TMP_ARR <<<"$MTAB_3RD"
+				for I in ${TMP_ARR[@]}; do
+					MNT_OPTS[$I]='1'
+				done
+			done </etc/mtab
+			COMPREPLY=( $(compgen -W "$(echo ${!MNT_OPTS[@]})" -- $cur) )
 			return 0
 			;;
 		'-o'|'--output')
shell-completion/fsck +1 -1
index c3da5f5..40b9a13 100644
@@ -29,7 +29,7 @@ _fsck_module()
 			return 0
 			;;
 	esac
-	DEVS="$(lsblk -o NAME -n -r | awk '{print "/dev/" $1}')"
+	while read dev; do DEVS+="$dev " ; done < <(lsblk -pnro name)
 	COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
 	return 0
 }
shell-completion/fsck.minix +1 -1
index f01626a..6239ae4 100644
@@ -3,7 +3,7 @@ _fsck.minix_module()
 	local cur OPTS DEVS
 	COMPREPLY=()
 	cur="${COMP_WORDS[COMP_CWORD]}"
-	DEVS="$(lsblk -o NAME -n -r | awk '{print "/dev/" $1}')"
+	while read dev; do DEVS+="$dev " ; done < <(lsblk -pnro name)
 	OPTS="-l -a -r -v -s -m -f -V --version"
 	COMPREPLY=( $(compgen -W "${OPTS[*]} $DEVS" -- $cur) )
 	return 0
shell-completion/ionice +1 -1
index 3087c4a..2180718 100644
@@ -15,7 +15,7 @@ _ionice_module()
 			;;
 		'-p'|'--pid')
 			local PIDS
-			PIDS=$(\ls -d /proc/[0-9]* | sed 's|/proc/||')
+			PIDS=$(for I in /proc/[0-9]*; do echo ${I##"/proc/"}; done)
 			COMPREPLY=( $(compgen -W "$PIDS" -- $cur) )
 			return 0
 			;;
shell-completion/ipcrm +8 -1
index 4b1024f..fd85091 100644
@@ -36,13 +36,20 @@ _ipcrm_module()
 			return 0
 			;;
 	esac
+	case $cur in
+		'=')
+			cur=${cur#=}
+			COMPREPLY=( $(compgen -W "shm msg sem" -- $cur) )
+			return 0
+			;;
+	esac
 	OPTS="	-m --shmem-id
 		-M --shmem-key
 		-q --queue-id
 		-Q --queue-key
 		-s --semaphore-id
 		-S --semaphore-key
-		-a --all
+		-a= --all=
 		-v --verbose
 		-h --help
 		-V --version"
shell-completion/login deleted +0 -27
deleted file mode 100644
index c075f64..0000000
@@ -1,27 +0,0 @@
-_login_module()
-{
-	local cur prev OPTS
-	COMPREPLY=()
-	cur="${COMP_WORDS[COMP_CWORD]}"
-	prev="${COMP_WORDS[COMP_CWORD-1]}"
-	case $prev in
-		'-f')
-			COMPREPLY=( $(compgen -u -- $cur) )
-			return 0
-			;;
-		'-h')
-			COMPREPLY=( $(compgen -A hostname -- $cur) )
-			return 0
-			;;
-	esac
-	case $cur in
-		-*)
-			OPTS="-p -f -h -H -V"
-			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
-			return 0
-			;;
-	esac
-	COMPREPLY=( $(compgen -u -- $cur) )
-	return 0
-}
-complete -F _login_module login
shell-completion/losetup +1 -1
index b21f05d..329bb05 100644
@@ -16,7 +16,7 @@ _losetup_module()
 			return 0
 			;;
 		'-c'|'--set-capacity')
-			ARG="$(\ls /dev/loop[0-9]* 2>/dev/null)"
+			ARG="$(for I in /dev/loop[0-9]*; do if [ -e $I ]; then echo $I; fi; done)"
 			COMPREPLY=( $(compgen -W "$ARG" -- $cur) )
 			return 0
 			;;
shell-completion/lsblk +8 -3
index 521cead..5498199 100644
@@ -1,12 +1,17 @@
 _lsblk_module()
 {
-	local cur prev OPTS MAJOR
+	local cur prev OPTS
 	COMPREPLY=()
 	cur="${COMP_WORDS[COMP_CWORD]}"
 	prev="${COMP_WORDS[COMP_CWORD-1]}"
 	case $prev in
 		'-e'|'--exclude'|'-I'|'--include')
-			MAJOR=$(\ls /sys/dev/block/ | sed 's/:.*//')
+			local MAJOR I J
+			MAJOR=''
+			for I in /sys/dev/block/*; do
+				J=${I##*/}
+				MAJOR="$MAJOR ${J%%:*}"
+			done
 			# FIXME: how to append to a string with compgen?
 			compopt -o nospace
 			COMPREPLY=( $(compgen -W "$MAJOR" -S ',' -- $cur) )
@@ -53,7 +58,7 @@ _lsblk_module()
 			;;
 	esac
 	local DEVS
-	DEVS="$(\ls -d /sys/class/block/* | sed 's|/sys/class/block/|/dev/|g')"
+	DEVS=''; while read dev; do DEVS+="$dev " ; done < <(lsblk -pnro name)
 	COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
 	return 0
 }
shell-completion/lscpu +16 -10
index bb76d4c..14926ec 100644
@@ -1,19 +1,25 @@
 _lscpu_module()
 {
-	local cur prev OPTS
+	local cur OPTS
 	COMPREPLY=()
 	cur="${COMP_WORDS[COMP_CWORD]}"
 	prev="${COMP_WORDS[COMP_CWORD-1]}"
 	case $prev in
-		'-e'|'--extended'|'-p'|'--parse')
+		'--extended'|'=')
+			cur=${cur#=}
 			# FIXME: how to append to a string with compgen?
-			# FIXME: space in between option and argument is
-			# 	 a problem.
-			local OUTPUT
-			OUTPUT="CPU CORE SOCKET NODE BOOK CACHE
-				POLARIZATION ADDRESS CONFIGURED ONLINE"
+			OPTS="CPU,
+				CORE,
+				SOCKET,
+				NODE,
+				BOOK,
+				CACHE,
+				POLARIZATION,
+				ADDRESS,
+				CONFIGURED,
+				ONLINE,"
 			compopt -o nospace
-			COMPREPLY=( $(compgen -W "$OUTPUT" -S ',' -- $cur) )
+			COMPREPLY=( $(compgen -W "$OPTS" -- $cur) )
 			return 0
 			;;
 	esac
@@ -22,8 +28,8 @@ _lscpu_module()
 			OPTS="-a --all
 				-b --online
 				-c --offline
-				-e --extended
-				-p --parse
+				-e= --extended=
+				-p= --parse=
 				-s --sysroot
 				-x --hex
 				-h --help
shell-completion/mkfs +2 -2
index ee6a26b..1947119 100644
@@ -6,7 +6,7 @@ _mkfs_module()
 	prev="${COMP_WORDS[COMP_CWORD-1]}"
 	case $prev in
 		'-t'|'--type')
-			FSTYPES=$(for I in $(\ls /sbin/mkfs.* /usr/sbin/mkfs.* 2>/dev/null); do echo ${I##*mkfs.}; done)
+			FSTYPES=$(for I in /sbin/mkfs.* /usr/sbin/mkfs.*; do if [ -e $I ]; then echo ${I##*mkfs.}; fi; done)
 			COMPREPLY=( $(compgen -W "$FSTYPES" -- $cur) )
 			return 0
 			;;
@@ -18,7 +18,7 @@ _mkfs_module()
 			return 0
 			;;
 	esac
-	DEVS="$(lsblk -o NAME -n -r | awk '{print "/dev/" $1}')"
+	while read dev; do DEVS+="$dev " ; done < <(lsblk -pnro name)
 	COMPREPLY=( $(compgen -W "$DEVS /path/to/file" -- $cur) )
 	return 0
 }
shell-completion/mkfs.bfs +1 -1
index b1a226a..7a47a76 100644
@@ -21,7 +21,7 @@ _bfs_module()
 			return 0
 			;;
 	esac
-	DEVS="$(lsblk -o NAME -n -r | awk '{print "/dev/" $1}')"
+	while read dev; do DEVS+="$dev " ; done < <(lsblk -pnro name)
 	COMPREPLY=( $(compgen -W "$DEVS /path/to/file" -- $cur) )
 	return 0
 }
shell-completion/mkfs.minix +1 -1
index c717b3c..085a058 100644
@@ -26,7 +26,7 @@ _mkfs.minix_module()
 			;;
 	esac
 	local DEVS
-	DEVS="$(lsblk -o NAME -n -r | awk '{print "/dev/" $1}')"
+	while read dev; do DEVS+="$dev " ; done < <(lsblk -pnro name)
 	COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
 	return 0
 }
shell-completion/mkswap +0 -1
index c847aa9..30d517c 100644
@@ -18,7 +18,6 @@ _mkswap_module()
 			return 0
 			;;
 		'-U'|--uuid)
-			COMPREPLY=( $(compgen -W "$(lsblk -n --output uuid)" -- $cur) )
 			return 0
 			;;
 	esac
shell-completion/nsenter +16 -19
index f15a7f1..b8296b6 100644
@@ -7,32 +7,29 @@ _nsenter_module()
 	case $prev in
 		'-t'|'--target')
 			local PIDS
-			PIDS=$(\ls -d /proc/[0-9]* | sed 's|/proc/||')
+			PIDS=$(for I in /proc/[0-9]*; do echo ${I##"/proc/"}; done)
 			COMPREPLY=( $(compgen -W "$PIDS" -- $cur) )
 			return 0
 			;;
-		'-m'|'--mount'|'-u'|'--uts'|'-i'|'--net'|'-n'|'--net'|'-p'|'--pid'|'-U'|'--user')
-			compopt -o filenames
-			COMPREPLY=( $(compgen -f -- $cur) )
-			return 0
-			;;
-		'-r'|'--root'|'-w'|'--wd')
-			compopt -o filenames
-			COMPREPLY=( $(compgen -o dirnames -- $cur) )
-			return 0
-			;;
 	esac
 	case $cur in
+		'=')
+			# FIXME: --root and --wd should use get only
+			# directories as compgen output.  If $cur is
+			# overwrote the same way as below in case segment
+			# for $prev the command-line will get mangled.
+			cur=${cur#=}
+			;;
 		-*)
 			OPTS="-t --target
-				-m --mount
-				-u --uts
-				-i --ipc
-				-n --net
-				-p --pid
-				-U --user
-				-r --root
-				-w --wd
+				-m= --mount=
+				-u= --uts=
+				-i= --ipc=
+				-n= --net=
+				-p= --pid=
+				-U= --user=
+				-r= --root=
+				-w= --wd=
 				-F --no-fork
 				-h --help
 				-V --version"
shell-completion/partx +5 -4
index c558d36..db2eded 100644
@@ -7,7 +7,6 @@ _partx_module()
 	prev="${COMP_WORDS[COMP_CWORD-1]}"
 	case $prev in
 		'-n'|'--nr')
-			COMPREPLY=( $(compgen -W "$(lsblk -o NAME,TYPE -n -r | awk '$2 ~ /part/ {print "/dev/" $1}')" -- $cur) )
 			return 0
 			;;
 		'-o'|'--output')
@@ -29,9 +28,11 @@ _partx_module()
 			return 0
 			;;
 	esac
-	local DEVS
-	DEVS="$(sblk -o NAME,TYPE -n -r | awk '$2 ~ /disk/ {print "/dev/" $1}')"
-	COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
+	local DEV TYPE DEVICES=''
+	while read DEV TYPE; do
+		[ $TYPE = 'disk' ] && DEVICES+="$DEV "
+	done < <(lsblk -pnro name,type)
+	COMPREPLY=( $(compgen -W "$DEVICES" -- $cur) )
 	return 0
 }
 complete -F _partx_module partx
shell-completion/prlimit +21 -16
index ee49b79..bf5ff2f 100644
@@ -6,7 +6,7 @@ _prlimit_module()
 	prev="${COMP_WORDS[COMP_CWORD-1]}"
 	case $prev in
 		'-p'|'--pid')
-			PIDS=$(\ls -d /proc/[0-9]* | sed 's|/proc/||')
+			PIDS=$(for I in /proc/[0-9]*; do echo ${I##"/proc/"}; done)
 			COMPREPLY=( $(compgen -W "$PIDS" -- $cur) )
 			return 0
 			;;
@@ -20,6 +20,11 @@ _prlimit_module()
 			;;
 	esac
 	case $cur in
+		'=')
+			cur=${cur#=}
+			# FIXME: is there anything what could be printed
+			# as limit value(s)
+			;;
 		-*)
 			OPTS="-p --pid
 				-o --output
@@ -28,21 +33,21 @@ _prlimit_module()
 				   --verbose
 				-h --help
 				-V --version
-				-c --core
-				-d --data
-				-e --nice
-				-f --fsize
-				-i --sigpending
-				-l --memlock
-				-m --rss
-				-n --nofile
-				-q --msgqueue
-				-r --rtprio
-				-s --stack
-				-t --cpu
-				-u --nproc
-				-v --as
-				-x --locks
+				-c= --core=
+				-d= --data=
+				-e= --nice=
+				-f= --fsize=
+				-i= --sigpending=
+				-l= --memlock=
+				-m= --rss=
+				-n= --nofile=
+				-q= --msgqueue=
+				-r= --rtprio=
+				-s= --stack=
+				-t= --cpu=
+				-u= --nproc=
+				-v= --as=
+				-x= --locks=
 				-y --rttime"
 			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
 			return 0
shell-completion/raw +1 -1
index 41e03f2..27f0354 100644
@@ -11,7 +11,7 @@ _raw_module()
 			return 0
 			;;
 	esac
-	COMPREPLY=( $(compgen -W "$(ls 2>/dev/null /dev/raw/*)" -- $cur) )
+	COMPREPLY=( $(compgen -W "$(for I in /dev/raw/*; do if [ -e $I ]; then echo $I; fi; done)" -- $cur) )
 	return 0
 }
 complete -F _raw_module raw
shell-completion/renice +1 -1
index bc80dac..aba00d7 100644
@@ -17,7 +17,7 @@ _renice_module()
 			;;
 		'-p'|'--pid')
 			local PIDS
-			PIDS=$(\ls -d /proc/[0-9]* | sed 's|/proc/||')
+			PIDS=$(for I in /proc/[0-9]*; do echo ${I##"/proc/"}; done)
 			COMPREPLY=( $(compgen -W "$PIDS" -- $cur) )
 			return 0
 			;;
shell-completion/resizepart +7 -4
index 827638a..b178b52 100644
@@ -1,16 +1,19 @@
 _resizepart_module()
 {
-	local cur OPTS
+	local cur prev OPTS
 	COMPREPLY=()
 	cur="${COMP_WORDS[COMP_CWORD]}"
 	case $COMP_CWORD in
 		1)
-			local DEVS
-			DEVS="$(lsblk -o NAME,TYPE -n -r | awk '$2 ~ /disk/ {print "/dev/" $1}')"
-			OPTS="-h --help -V --version $DEVS"
+			local DEV TYPE DEVICES=''
+			while read DEV TYPE; do
+				[ $TYPE = 'disk' ] && DEVICES+="$DEV "
+			done < <(lsblk -pnro name,type)
+			OPTS="-h --help -V --version $DEVICES"
 			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
 			;;
 		2)
+			prev="${COMP_WORDS[COMP_CWORD-1]}"
 			COMPREPLY=( $(compgen -W "$(cat /sys/block/${prev##*/}/*/partition 2>/dev/null)" -- $cur) )
 			;;
 		3)
shell-completion/rtcwake +1 -1
index 2010a52..1f38df8 100644
@@ -7,7 +7,7 @@ _rtcwake_module()
 	case $prev in
 		'-d'|'--device')
 			local RTC_DEVS
-			RTC_DEVS=$(\ls /sys/class/rtc/ 2>/dev/null)
+			RTC_DEVS=$(cd /sys/class/rtc/ && echo *)
 			COMPREPLY=( $(compgen -W "$RTC_DEVS" -- $cur) )
 			return 0
 			;;
shell-completion/script +4 -6
index fb6c106..48f50c3 100644
@@ -10,13 +10,11 @@ _script_module()
 			COMPREPLY=( $(compgen -c -- $cur) )
 			return 0
 			;;
-		'-t'|'--timing')
-			compopt -o filenames
-			COMPREPLY=( $(compgen -f -- $cur) )
-			return 0
-			;;
 	esac
 	case $cur in
+		'=')
+			cur=${cur#=}
+			;;
 		-*)
 			OPTS="-a --append
 				-c --command
@@ -24,7 +22,7 @@ _script_module()
 				-f --flush
 				   --force
 				-q --quiet
-				-t --timing
+				-t= --timing=
 				-V --version
 				-h --help"
 			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
shell-completion/setterm +8 -4
index a0dff44..33d2e56 100644
@@ -6,8 +6,12 @@ _setterm_module()
 	prev="${COMP_WORDS[COMP_CWORD-1]}"
 	case $prev in
 		'-term')
-			# FIXME: terminal type list would be nice
-			COMPREPLY=( $(compgen -W "vt100 xterm linux screen etc" -- $cur) )
+			local TERM_LIST I
+			TERM_LIST=''
+			for I in /usr/share/terminfo/?/*; do
+				TERM_LIST+="${I##*/} "
+			done
+			COMPREPLY=( $(compgen -W "$TERM_LIST" -- $cur) )
 			return 0
 			;;
 		'-foreground'|'-background'|'-ulcolor'|'-hbcolor')
@@ -36,8 +40,8 @@ _setterm_module()
 			;;
 		'-dump'|'-append')
 			local NUM_CONS
-			NUM_CONS=$(ls /sys/class/tty | wc -l)
-			COMPREPLY=( $(compgen -W "$(echo {1..$NUM_CONS})" -- $cur) )
+			NUM_CONS=(/sys/class/tty/*)
+			COMPREPLY=( $(compgen -W "$(echo {1..${#NUM_CONS[*]}})" -- $cur) )
 			return 0
 			;;
 		'-file')
shell-completion/sfdisk +10 -3
index 041ce55..5498b0e 100644
@@ -20,6 +20,9 @@ _sfdisk_module()
 			;;
 	esac
 	case $cur in
+		'=')
+			cur=${cur#=}
+			;;
 		-*)
 			OPTS="-s --show-size
 				-c --id
@@ -47,8 +50,8 @@ _sfdisk_module()
 				-L --Linux
 				-g --show-geometry
 				-G --show-pt-geometry
-				-A --activate
-				-U --unhide
+				-A= --activate=
+				-U= --unhide=
 				-x --show-extended
 				--leave-last
 				--IBM
@@ -66,7 +69,11 @@ _sfdisk_module()
 			return 0
 			;;
 	esac
-	COMPREPLY=( $(compgen -W "$(lsblk -o NAME,TYPE -n -r | awk '$2 ~ /disk/ {print "/dev/" $1}')" -- $cur) )
+	local DEV TYPE DEVICES=''
+	while read DEV TYPE; do
+		[ $TYPE = 'disk' ] && DEVICES+="$DEV "
+	done < <(lsblk -pnro name,type)
+	COMPREPLY=( $(compgen -W "$DEVICES" -- $cur) )
 	return 0
 }
 complete -F _sfdisk_module sfdisk
shell-completion/su +5 -4
index ded4b7b..c5aa81e 100644
@@ -20,15 +20,16 @@ _su_module()
 	esac
 	case $cur in
 		-*)
-			OPTS="	-u --user
+			OPTS="	-
+				-u --user
 				-m -p --preserve-environment
 				-g --group
 				-G --supp-group
-				- -l --login
+				-l --login
 				-c --command
-				- -c
+				-c
 				--session-command
-				-- -c
+				-c
 				-f --fast
 				-s --shell
 				-h --help
shell-completion/sulogin deleted +0 -24
deleted file mode 100644
index 9fdc20e..0000000
@@ -1,24 +0,0 @@
-_sulogin_module()
-{
-	local cur prev OPTS
-	COMPREPLY=()
-	cur="${COMP_WORDS[COMP_CWORD]}"
-	prev="${COMP_WORDS[COMP_CWORD-1]}"
-	case $prev in
-		'-t'|'--timeout')
-			COMPREPLY=( $(compgen -W "seconds" -- $cur) )
-			return 0
-			;;
-	esac
-	case $cur in
-		-*)
-			OPTS="-p --login-shell -t --timeout -V --version -h --help"
-			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
-			return 0
-			;;
-	esac
-	compopt -o filenames
-	COMPREPLY=( $(compgen -f -- ${cur:-"/dev/tty"}) )
-	return 0
-}
-complete -F _sulogin_module sulogin
shell-completion/taskset +1 -1
index 81247cd..5311316 100644
@@ -19,7 +19,7 @@ _taskset_module()
 			# setting an affinity the optarg has to be cpu
 			# mask.  The following is good only for getting
 			# affinity.
-			PIDS=$(\ls -d /proc/[0-9]* | sed 's|/proc/||')
+			PIDS=$(for I in /proc/[0-9]*; do echo ${I##"/proc/"}; done)
 			COMPREPLY=( $(compgen -W "$PIDS" -- $cur) )
 			return 0
 			;;
shell-completion/ul +6 -2
index 89e2800..07d0731 100644
@@ -6,8 +6,12 @@ _ul_module()
 	prev="${COMP_WORDS[COMP_CWORD-1]}"
 	case $prev in
 		'-t'|'--terminal')
-			# FIXME: terminal type list would be nice
-			COMPREPLY=( $(compgen -W "vt100 xterm linux screen etc" -- $cur) )
+			local TERM_LIST I
+			TERM_LIST=''
+			for I in /usr/share/terminfo/?/*; do
+				TERM_LIST+="${I##*/} "
+			done
+			COMPREPLY=( $(compgen -W "$TERM_LIST" -- $cur) )
 			return 0
 			;;
 	esac
shell-completion/wdctl +14 -2
index 6a85e0a..42889ac 100644
@@ -6,8 +6,20 @@ _wdctl_module()
 	prev="${COMP_WORDS[COMP_CWORD-1]}"
 	case $prev in
 		'-f'|'--flags')
-			# FIXME: how to get flag list?
-			COMPREPLY=( $(compgen -W "flags" -- $cur) )
+			local FLAGS
+			FLAGS="ALARMONLY
+				CARDRESET
+				EXTERN1
+				EXTERN2
+				FANFAULT
+				KEEPALIVEPING
+				MAGICCLOSE
+				OVERHEAT
+				POWEROVER
+				POWERUNDER
+				PRETIMEOUT
+				SETTIMEOUT"
+			COMPREPLY=( $(compgen -W "$FLAGS" -- $cur) )
 			return 0
 			;;
 		'-o'|'--output')
shell-completion/wipefs +2 -8
index 427f47b..db9426e 100644
@@ -11,13 +11,7 @@ _wipefs_module()
 			;;
 		'-t'|'--types')
 			local TYPES
-			TYPES="adfs affs autofs cifs coda coherent cramfs
-				debugfs devpts efs ext ext2 ext3 ext4 hfs
-				hfsplus hpfs iso9660 jfs minix msdos
-				ncpfs nfs nfs4 ntfs proc qnx4 ramfs
-				reiserfs romfs squashfs smbfs sysv tmpfs
-				ubifs udf ufs umsdos usbfs vfat xenix xfs
-				xiafs"
+			TYPES="$(blkid -k)"
 			COMPREPLY=( $(compgen -W "$TYPES" -- $cur) )
 			return 0
 			;;
@@ -31,7 +25,7 @@ _wipefs_module()
 			;;
 	esac
 	local DEVS
-	DEVS="$(\ls -d /sys/class/block/* | sed 's|/sys/class/block/|/dev/|g')"
+	DEVS=''; while read dev; do DEVS+="$dev " ; done < <(lsblk -pnro name)
 	COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
 	return 0
 }
shell-completion/write +4 -1
index ba67569..d41159b 100644
@@ -9,7 +9,10 @@ _write_module()
 			return 0
 			;;
 		2)
-			local TERMS=$(for I in $(\ls /sys/class/tty 2>/dev/null); do echo "/dev/$I"; done)
+			local I TERMS=''
+			for I in /sys/class/tty/*; do
+				TERMS+="/dev${I##/sys/class/tty} "
+			done
 			COMPREPLY=( $(compgen -W "$TERMS" -- $cur) )
 			return 0
 			;;
Signature · 2 lines
   Sami Kerola
   http://www.iki.fi/kerolasa/