[PATCH 12/16] ls: add --column

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

 



Signed-off-by: Nguyán ThÃi Ngác Duy <pclouds@xxxxxxxxx>
---
 builtin/ls-files.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index cab7a10..3195f75 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -13,6 +13,7 @@
 #include "parse-options.h"
 #include "resolve-undo.h"
 #include "string-list.h"
+#include "column.h"
 
 static int abbrev;
 static int show_deleted;
@@ -45,8 +46,19 @@ static const char *tag_modified = "";
 static const char *tag_skip_worktree = "";
 static const char *tag_resolve_undo = "";
 
+static struct string_list output;
+static int column_mode;
+
 static void write_name(const char* name, size_t len)
 {
+	/* No quoting in column layout. It will be done by the end. */
+	if (column_mode & COL_MODE) {
+		struct strbuf sb = STRBUF_INIT;
+		strbuf_add(&sb, name, len);
+		string_list_append(&output, strbuf_detach(&sb, NULL));
+		return;
+	}
+
 	write_name_quoted_relative(name, len, prefix, prefix_len, stdout,
 			line_terminator);
 }
@@ -637,6 +649,7 @@ int cmd_ls(int argc, const char **argv, const char *cmd_prefix)
 			DIR_SHOW_IGNORED),
 		OPT_BOOLEAN('k', "killed", &show_killed,
 			"show files on the filesystem that need to be removed"),
+		OPT_COLUMN(0, "column", &column_mode, "show files in columns" ),
 		OPT_END()
 	};
 
@@ -652,6 +665,8 @@ int cmd_ls(int argc, const char **argv, const char *cmd_prefix)
 	if (read_cache() < 0)
 		die("index file corrupt");
 
+	column_mode = core_column;
+
 	argc = parse_options(argc, argv, prefix, builtin_ls_files_options,
 			ls_files_usage, 0);
 
@@ -669,5 +684,6 @@ int cmd_ls(int argc, const char **argv, const char *cmd_prefix)
 		show_cached = 1;
 
 	show_files(&dir);
+	display_columns(&output, column_mode, term_columns(), 2, NULL);
 	return 0;
 }
-- 
1.7.2.2

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


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]