On 17/06/19 15:06, Pádraig Brady wrote:
> On 15/06/19 03:35, Dan Jacobson wrote:
>> Some files might only have numeric user ids,
>>
>> # ls -l
>> -rw-r--r-- 1  777 root   0 06-15 10:14 a
>> -rw-r--r-- 1 root 777777 0 06-15 10:11 b
>> -rw-r--r-- 1 root root   0 06-15 10:12 c
>> -rw-r--r-- 1 root    777 0 06-15 10:12 d
> 
> I guess the numeric IDs are usually the minority in the mixed case,
> so it would be best to align left in that case?
> Are mixed names/IDs a common case for you?
> I.E. is it worth worrying about this?
> It's easy enough to fix, but it would be nice
> to know if it was a common issue, as I've not encountered it at least.

Patch attached to do as described above

>From b75ed390aa86a3bb44f003ed9961a14613a1b6d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Mon, 17 Jun 2019 16:02:51 +0100
Subject: [PATCH] ls: align mixed user IDs left

* src/ls.c [id_alignment]: A new global that is reset to align left
upon successful user name or group lookup.
Addresses https://bugs.gnu.org/36220
---
 src/ls.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/ls.c b/src/ls.c
index 120ce15..0e2c46a 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -505,6 +505,9 @@ static bool print_group = true;
 
 static bool numeric_ids;
 
+/* Default to numeric right alignment, but reset upon name lookup.  */
+static mbs_align_t id_alignment = MBS_ALIGN_RIGHT;
+
 /* True means mention the size in blocks of each file.  -s  */
 
 static bool print_block_size;
@@ -3943,7 +3946,7 @@ format_user_or_group (char const *name, unsigned long int id, int width)
     }
   else
     {
-      printf ("%*lu ", width, id);
+      printf ("%*lu ", width * (id_alignment == MBS_ALIGN_LEFT ? -1 : 1), id);
       len = width;
     }
 
@@ -3976,6 +3979,7 @@ format_user_or_group_width (char const *name, unsigned long int id)
 {
   if (name)
     {
+      id_alignment = MBS_ALIGN_LEFT;
       int len = mbswidth (name, 0);
       return MAX (0, len);
     }
-- 
2.9.3

Reply via email to