[PATCH] bash-completion: handle comma-separated options in findmnt

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

 



So, I discovered a way to complete comma-separated options. This
solution can become messy when you have too many values listed.

Similar fixes for other utils follow if this one will be merged.

Signed-off-by: Boris Egorov <egorov@xxxxxxxxx>
---
 bash-completion/findmnt | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/bash-completion/findmnt b/bash-completion/findmnt
index cf66565..3ad9147 100644
--- a/bash-completion/findmnt
+++ b/bash-completion/findmnt
@@ -43,15 +43,23 @@ _findmnt_module()
 			return 0
 			;;
 		'-o'|'--output')
-			# FIXME: how to append to a string with compgen?
-			local OUTPUT
-			OUTPUT="SOURCE TARGET FSTYPE OPTIONS VFS-OPTIONS
+			local prefix realcur OUTPUT_ALL OUTPUT
+			realcur="${cur##*,}"
+			prefix="${cur%$realcur}"
+
+			OUTPUT_ALL="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"
+
+			for WORD in $OUTPUT_ALL; do
+				if ! [[ $prefix == *"$WORD"* ]]; then
+					OUTPUT="$WORD $OUTPUT"
+				fi
+			done
 			compopt -o nospace
-			COMPREPLY=( $(compgen -W "$OUTPUT" -S ',' -- $cur) )
+			COMPREPLY=( $(compgen -P "$prefix" -W "$OUTPUT" -S ',' -- $realcur) )
 			return 0
 			;;
 		'-t'|'--types')
-- 
2.1.4

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




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux