From owner-freebsd-bugs Tue Aug 8 6: 0: 6 2000 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id AB59D37B59E for ; Tue, 8 Aug 2000 06:00:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id GAA51378; Tue, 8 Aug 2000 06:00:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from slarti.muc.de (slarti.muc.de [193.149.48.10]) by hub.freebsd.org (Postfix) with SMTP id B700337B59E for ; Tue, 8 Aug 2000 05:55:09 -0700 (PDT) (envelope-from rse@en1.engelschall.com) Received: (qmail 28606 invoked by uid 66); 8 Aug 2000 13:03:43 -0000 Received: from en by slarti with UUCP; Tue Aug 8 13:03:43 2000 -0000 Received: by en1.engelschall.com (Sendmail 8.11.0+) id e78CsKx72276; Tue, 8 Aug 2000 14:54:20 +0200 (CEST) Message-Id: <200008081254.e78CsKx72276@en1.engelschall.com> Date: Tue, 8 Aug 2000 14:54:20 +0200 (CEST) From: "Ralf S. Engelschall" Reply-To: rse@engelschall.com To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: bin/20483: allowing old colors+paging combination with ls(1) again Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 20483 >Category: bin >Synopsis: allowing old colors+paging combination with ls(1) again >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Tue Aug 08 06:00:01 PDT 2000 >Closed-Date: >Last-Modified: >Originator: Ralf S. Engelschall >Release: FreeBSD 4.1-STABLE i386 >Organization: Engelschall, Germany. >Environment: FreeBSD en1.engelschall.com 4.1-STABLE FreeBSD 4.1-STABLE #0: Mon Aug 7 21:02:25 CEST 2000 rse@en1.engelschall.com:/usr/src/sys/compile/EN1 i386 >Description: Since years I used the following stuff in my shell to get three directory listing commands which both use color and (if any only if the listing is too large) also the pager. ls () { colorls -G -C "$@" | less -E -r } ll () { colorls -G -l "$@" | less -E -r } lx () { colorls -G -l -a "$@" | less -E -r } As you now, colorls and less were the beast from our ports, -G switched on the colors and less' -E -r options did the magic for display: -E caused less to automatically exit the first time it reached end-of-file, and -r forced less to display the color sequences. Now with FreeBSD 4.1 we got the nice color support built into our /bin/ls. Fine, except for the problem that the great colors+paging combination is no longer possible: ls () { /bin/ls -G -C "$@" | less -E -r } ll () { /bin/ls -G -l "$@" | less -E -r } lx () { /bin/ls -G -l -a "$@" | less -E -r } The result is that all colors are gone. The reason is a simple isatty(3) call in src/bin/ls/ls.c, line 205, which simple lets /bin/ls honor -G only if stdout is connected to a tty. Hmmm... obviously a useful check, because things like "ls *.c >filelist", etc. should not contain any color sequences. But OTOH this check seems a little-bit too restrictive and magic, because if I add -G I really mean -G. And if I don't want any colors in "ls *.c >How-To-Repeat: Run "/bin/ls -G -C | less -E -r" and recognize that colors are gone, because the pipe means ls' stdout is no longer connected to a tty. >Fix: I propose either this patch: Index: ls.c =================================================================== RCS file: /home/ncvs/src/bin/ls/ls.c,v retrieving revision 1.42 diff -u -d -r1.42 ls.c --- ls.c 2000/07/04 23:09:23 1.42 +++ ls.c 2000/08/08 12:44:55 @@ -202,7 +202,6 @@ fts_options |= FTS_COMFOLLOW; break; case 'G': - if (isatty(STDOUT_FILENO)) #ifdef COLORLS if (tgetent(termcapbuf, getenv("TERM")) == 1) { ansi_fgcol = tgetstr("AF", &bp); or alternatively the following patch: Index: ls.c =================================================================== RCS file: /home/ncvs/src/bin/ls/ls.c,v retrieving revision 1.42 diff -u -d -r1.42 ls.c --- ls.c 2000/07/04 23:09:23 1.42 +++ ls.c 2000/08/08 12:47:57 @@ -202,7 +202,7 @@ fts_options |= FTS_COMFOLLOW; break; case 'G': - if (isatty(STDOUT_FILENO)) + if (isatty(STDOUT_FILENO) || getenv("LSCOLORS_FORCED") != NULL) #ifdef COLORLS if (tgetent(termcapbuf, getenv("TERM")) == 1) { ansi_fgcol = tgetstr("AF", &bp); With the second patch, compatibility to the original intention ("be magic in case of non-tty") is preserved and one is at least able to use the following to achieve the old colors+paging combination: ls () { LSCOLORS_FORCED=1 /bin/ls -G -C "$@" | less -E -r } ll () { LSCOLORS_FORCED=1 /bin/ls -G -l "$@" | less -E -r } lx () { LSCOLORS_FORCED=1 /bin/ls -G -l -a "$@" | less -E -r } >Release-Note: >Audit-Trail: >Unformatted: >filelist" I should be able to type "/bin/ls *.c >filelist" or I better should avoid playing around with overridden commands. So, I would appreciate that we either just simply remove the isatty(3) check in ls.c because we treat it too extreme. Or we at least add another flag (oh no, not one more ;) or (certainly better) an env variable to ls(1) which forces the use of colors. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message