bug-coreutils
[Top][All Lists]
Advanced

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

[PATCH] ls: Use pretty UTF-8 arrow when showing where symlinks point to


From: Lennart Poettering
Subject: [PATCH] ls: Use pretty UTF-8 arrow when showing where symlinks point to
Date: Tue, 11 Aug 2009 17:56:34 +0200
User-agent: Leviathan/19.8.0 [zh] (Cray 3; I; Solaris 4.711; Console)

[Second version of the patch, makes this feature optional with --fancy-chars]

Diego Pettenò complained that "ls -l" doesn't use the UTF-8 arrow
character to show where symlinks point to. This tiny patch fixes that.
With this applied the character is used when the CODESET is UTF-8
otherwise we fall back to the traditional "->" arrow.

This is only enabled if --fancy-chars is passed as argument.

Ah, "ls -l" is so much prettier now!

For verification:

http://pastie.org/573270

---
 src/ls.c |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/src/ls.c b/src/ls.c
index 07e9cf1..0d5be7c 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -496,6 +496,11 @@ static enum indicator_style const indicator_style_types[] =
 };
 ARGMATCH_VERIFY (indicator_style_args, indicator_style_types);
 
+/* Use fancy Unicode characters in output. At this point this simply
+   replaces the -> arrow for symlinks by a real Unicode arrow. */
+
+static bool fancy_chars;
+
 /* True means use colors to mark types.  Also define the different
    colors as well as the stuff for the LS_COLORS environment variable.
    The LS_COLORS variable is now in a termcap-like format.  */
@@ -758,6 +763,7 @@ enum
   AUTHOR_OPTION = CHAR_MAX + 1,
   BLOCK_SIZE_OPTION,
   COLOR_OPTION,
+  FANCY_CHARS_OPTION,
   DEREFERENCE_COMMAND_LINE_SYMLINK_TO_DIR_OPTION,
   FILE_TYPE_INDICATOR_OPTION,
   FORMAT_OPTION,
@@ -813,6 +819,7 @@ static struct option const long_options[] =
   {"time", required_argument, NULL, TIME_OPTION},
   {"time-style", required_argument, NULL, TIME_STYLE_OPTION},
   {"color", optional_argument, NULL, COLOR_OPTION},
+  {"fancy-chars", no_argument, NULL, FANCY_CHARS_OPTION},
   {"block-size", required_argument, NULL, BLOCK_SIZE_OPTION},
   {"context", no_argument, 0, 'Z'},
   {"author", no_argument, NULL, AUTHOR_OPTION},
@@ -1522,6 +1529,7 @@ decode_switches (int argc, char **argv)
   ignore_patterns = NULL;
   hide_patterns = NULL;
   print_scontext = false;
+  fancy_chars = false;
 
   /* FIXME: put this in a function.  */
   {
@@ -1866,6 +1874,10 @@ decode_switches (int argc, char **argv)
            break;
          }
 
+       case FANCY_CHARS_OPTION:
+         fancy_chars = true;
+         break;
+
        case INDICATOR_STYLE_OPTION:
          indicator_style = XARGMATCH ("--indicator-style", optarg,
                                       indicator_style_args,
@@ -3749,7 +3761,26 @@ print_long_format (const struct fileinfo *f)
     {
       if (f->linkname)
        {
+#ifdef HAVE_NL_LANGINFO
+         static const char *arrow = NULL;
+
+         if (!arrow)
+           {
+             arrow = " -> ";
+
+             if (fancy_chars)
+               {
+                 const char *cs;
+                 cs = nl_langinfo(CODESET);
+
+                 if (cs && strcmp(cs, "UTF-8") == 0)
+                   arrow = " \xe2\x86\x92 ";
+               }
+           }
+         DIRED_FPUTS_LITERAL (arrow, stdout);
+#else
          DIRED_FPUTS_LITERAL (" -> ", stdout);
+#endif
          print_name_with_quoting (f->linkname, f->linkmode, f->linkok - 1,
                                   f->stat_ok, f->filetype, NULL,
                                   f->stat.st_nlink, (p - buf) + w + 4);
@@ -4533,6 +4564,8 @@ Mandatory arguments to long options are mandatory for 
short options too.\n\
   -C                         list entries by columns\n\
       --color[=WHEN]         control whether color is used to distinguish 
file\n\
                                types.  WHEN may be `never', `always', or 
`auto'\n\
+      --fancy-chars          control whether fancy Unicode characters may be\n\
+                               used in the output.\n\
   -d, --directory            list directory entries instead of contents,\n\
                                and do not dereference symbolic links\n\
   -D, --dired                generate output designed for Emacs' dired mode\n\
-- 
1.6.4



Lennart

-- 
Lennart Poettering                        Red Hat, Inc.
lennart [at] poettering [dot] net         ICQ# 11060553
http://0pointer.net/lennart/           GnuPG 0x1A015CC4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]