[PATCH] lsblk: support -o +<attr> for adding attribute to output fields.

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

 



E.g. lsblk -o +model
(Maybe it would be nice to add this to other tools as well?)

Signed-off-by: Milan Broz <mbroz@xxxxxxxxxx>
---
 misc-utils/lsblk.c |   22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
index cb2b768..471f2d5 100644
--- a/misc-utils/lsblk.c
+++ b/misc-utils/lsblk.c
@@ -1213,6 +1213,7 @@ int main(int argc, char *argv[])
 	struct lsblk _ls;
 	int tt_flags = TT_FL_TREE;
 	int i, c, status = EXIT_FAILURE;
+	char *outarg = NULL;
 
 	enum {
 		EXCL_NONE,
@@ -1290,11 +1291,7 @@ int main(int argc, char *argv[])
 			tt_flags |= TT_FL_NOHEADINGS;
 			break;
 		case 'o':
-			ncolumns = string_to_idarray(optarg,
-						columns, ARRAY_SIZE(columns),
-						column_name_to_id);
-			if (ncolumns < 0)
-				return EXIT_FAILURE;
+			outarg = optarg;
 			break;
 		case 'P':
 			exclusive_option(&excl_rlP, EXCL_PAIRS, "--{raw,list,pairs}");
@@ -1363,6 +1360,21 @@ int main(int argc, char *argv[])
 		columns[ncolumns++] = COL_TARGET;
 	}
 
+	if (outarg) {
+		if (outarg[0] == '+')
+			outarg++;
+		else
+			ncolumns = 0;
+
+		c = string_to_idarray(outarg, &columns[ncolumns],
+					ARRAY_SIZE(columns) - ncolumns,
+					column_name_to_id);
+		if (c < 0)
+			return EXIT_FAILURE;
+
+		ncolumns += c;
+	}
+
 	if (nexcludes == 0 && nincludes == 0)
 		excludes[nexcludes++] = 1;	/* default: ignore RAM disks */
 
-- 
1.7.10.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