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

2009-08-12 Thread Jim Meyering
Lennart Poettering wrote:
 [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

Thanks for the patch.
However, I'm inclined not to add the functionality even
via a separate option, because:

  - The bar for adding a new option to ls is very high;  you'd need
  more justification than someone complained or it's prettier, now.

  - It's easy to get nearly the same effect with a simple filter,
  as Pádraig suggested.  (of course, a naive filter fails if
  a file name contains  - , but the end result is solely for
  human consumption, not for mechanical parsing, so that's ok)

Just by the way, I compared your arrow and the one Pádraig
used in his example:

$ printf 'a - b\n'
a - b
$ printf 'a \xe2\x86\x92 b\n'
a → b
$ printf 'a \u25aa\u25b6 b\n'
a ▪▶ b

I found the 1-column-wide arrow to be disconcertingly similar to
a hyphen, when viewed via a 7-point (admittedly small) font in
a gnome-terminal.  Compare to underscore and hyphen:

$ printf 'a _\xe2\x86\x92- b\n'
a _→- b

As usual, if you come up with more justification, or many people
clamor for this option, we will revisit the decision.




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

2009-08-12 Thread Pádraig Brady
Lennart Poettering wrote:
 On Tue, 11.08.09 22:27, Pádraig Brady (p...@draigbrady.com) wrote:
 
 this is equivalent I think:

static const char *arrow =  - ;
 #ifdef HAVE_NL_LANGINFO
if (fancy_chars  STREQ (nl_langinfo (CODESET), UTF-8))
  arrow =  \xe2\x86\x92 ;
 #endif
DIRED_FPUTS_LITERAL (arrow, stdout);
 
 You evaluate the whole expression on every iteration. The whole point
 of making this variable static is to make sure this isn't necessary.

Oh right, so something like:

static const char *arrow;
if (!arrow)
  {
if (fancy_chars  STREQ (locale_charset(), UTF-8))
  arrow =  \xe2\x86\x92 ;
else
  arrow =  - ;
  }
DIRED_FPUTS_LITERAL (arrow, stdout);

Note the use of locale_charset() from gnulib for portability.

cheers,
Pádraig.




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

2009-08-12 Thread Pádraig Brady
Jim Meyering wrote:
 
   - It's easy to get nearly the same effect with a simple filter,
   as Pádraig suggested.  (of course, a naive filter fails if
   a file name contains  - , but the end result is solely for
   human consumption, not for mechanical parsing, so that's ok)
 
 Just by the way, I compared your arrow and the one Pádraig
 used in his example:
 
 $ printf 'a - b\n'
 a - b
 $ printf 'a \xe2\x86\x92 b\n'
 a → b
 $ printf 'a \u25aa\u25b6 b\n'
 a ▪▶ b

Just to address my OCD, the example alias I posted would not work
as somewhere along the line in pasting over a vnc session the
unicode characters were mangled. Also the previous alias didn't
precompute as much as it could, so:

alias lsf=ls -l --color | sed 's/ - / $(tput bold)▪▶$(tput sgr0) /'

cheers,
Pádraig.




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

2009-08-12 Thread Pádraig Brady
Pádraig Brady wrote:
 
 Oh right, so something like:
 
 static const char *arrow;
 if (!arrow)
   {
 if (fancy_chars  STREQ (locale_charset(), UTF-8))
   arrow =  \xe2\x86\x92 ;
 else
   arrow =  - ;
   }
 DIRED_FPUTS_LITERAL (arrow, stdout);
 
 Note the use of locale_charset() from gnulib for portability.

BTW I still don't think this patch should be applied,
as the benefit from the new option is not big enough,
and much the same affect can be achieved with a
little post processing as demonstrated.

cheers,
Pádraig.




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

2009-08-11 Thread Pádraig Brady
Lennart Poettering wrote:
 [Second version of the patch, makes this feature optional with --fancy-chars]

--fancy-chars :)
I'm not sure how serious this patch is.
How about:

alias lsf='ls -l --color | sed s/ - / $(tput bold)\u25aa\u25b6$(tput sgr0) /'

cheers,
Pádraig.

p.s. this chunk is far too verbose

 +#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

this is equivalent I think:

   static const char *arrow =  - ;
#ifdef HAVE_NL_LANGINFO
   if (fancy_chars  STREQ (nl_langinfo (CODESET), UTF-8))
 arrow =  \xe2\x86\x92 ;
#endif
   DIRED_FPUTS_LITERAL (arrow, stdout);





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

2009-08-11 Thread Lennart Poettering
On Tue, 11.08.09 22:27, Pádraig Brady (p...@draigbrady.com) wrote:

 this is equivalent I think:
 
static const char *arrow =  - ;
 #ifdef HAVE_NL_LANGINFO
if (fancy_chars  STREQ (nl_langinfo (CODESET), UTF-8))
  arrow =  \xe2\x86\x92 ;
 #endif
DIRED_FPUTS_LITERAL (arrow, stdout);

You evaluate the whole expression on every iteration. The whole point
of making this variable static is to make sure this isn't necessary.

Lennart

-- 
Lennart PoetteringRed Hat, Inc.
lennart [at] poettering [dot] net
http://0pointer.net/lennart/   GnuPG 0x1A015CC4




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

2009-08-06 Thread Erik Auerswald
Hello Lennart,

On Thu, Aug 06, 2009 at 07:24:42PM +0200, Lennart Poettering wrote:
 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.
 
 Ah, ls -l is so much prettier now with this oh-so-important patch! 
 For verification:
 
 http://pastie.org/573270

What if the used font does not include this symbol? Could you check this
as well?

BTW the symbol in the URL above looks different than that shown in xterm
(I used iceweasel for the URL, default fonts for xterm).

IMHO use of this symbol should not be enabled by default.

Br,
Erik
-- 
Premature optimization is the root of all evil.
-- Donald Knuth




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

2009-08-06 Thread Philip Rowlands

On Thu, 6 Aug 2009, Lennart Poettering wrote:


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.

Ah, ls -l is so much prettier now with this oh-so-important patch!
For verification:

http://pastie.org/573270

This will of course break scripts that try to parse the output of ls
-l and look for -. But quite frankly those scripts are broken
anyway and should be using LC_MESSAGES=C or suchlike. One could
argue this breakage might even be desirable.


Why are scripts which look for - broken? It's explicitly stated in 
the standard:


http://www.opengroup.org/onlinepubs/95399/utilities/ls.html


Cheers,
Phil