Page 1 of 1

The 'less' command and colors

Posted: Sat 04 Jul 2020, 13:24
by jplt3
Hi all,

i wanted to have colors with the command less on the terminal but it does not work :

Code: Select all

In the help we have :
  -r  -R  ....  --raw-control-chars  --RAW-CONTROL-CHARS
                  Output "raw" control characters.
i test on bionicpup64 with lxterminal.

Posted: Sat 04 Jul 2020, 13:41
by Semme

Posted: Sat 04 Jul 2020, 15:56
by jplt3
Thanks Semme,

i already try this solution but all failed , so i use a lot vim then if i want d view a file , i open it with vim in read only mode , with an alias :

Code: Select all

alias read='vim -R'
In some linux distributions there "view" that does the same thing.

Posted: Sun 05 Jul 2020, 01:27
by Semme
This Ask Ubuntu method works on my end. Maybe here too.

Posted: Mon 06 Jul 2020, 06:32
by tallboy
Hi jplt3, which file did you modify? In my tahr64, there is a /root/.profile that seems to be of limited use, but there is an /etc/profile with this line included:

Code: Select all

[ -r /etc/profile.local ] && . /etc/profile.local
I made a /etc/profile.local file, and modifies my urxvt there.

Remember that the ls used in Puppy is the one from busybox, and it's options list looks like this, from the man page:

Code: Select all

ls
    ls [-1AaCxdLHRFplinsehrSXvctu] [-w WIDTH] [FILE]...

    List directory contents

            -1      One column output
            -a      Include entries which start with .
            -A      Like -a, but exclude . and ..
            -C      List by columns
            -x      List by lines
            -d      List directory entries instead of contents
            -L      Follow symlinks
            -H      Follow symlinks on command line
            -R      Recurse
            -p      Append / to dir entries
            -F      Append indicator (one of */=@|) to entries
            -l      Long listing format
            -i      List inode numbers
            -n      List numeric UIDs and GIDs instead of names
            -s      List allocated blocks
            -e      List full date and time
            -h      List sizes in human readable format (1K 243M 2G)
            -r      Sort in reverse order
            -S      Sort by size
            -X      Sort by extension
            -v      Sort by version
            -c      With -l: sort by ctime
            -t      With -l: sort by mtime
            -u      With -l: sort by atime
            -w N    Assume the terminal is N columns wide
            --color[={always,never,auto}]   Control coloring

Posted: Mon 06 Jul 2020, 17:57
by musher0
Hi jplt3.

The problem is lxterminal. It has its merits, but it filters out some stuff.
It may not understand the ANSI color codes sent by less.

May I suggest: go back to using urxvt as the terminal app.
Change /usr/local/bin/defaultterminal to

Code: Select all

#!/bin/ash
# type lxterminal >/dev/null 2>&1 && exec lxterminal "$@"
exec urxvt "$@"
Secondly, does your Pup have the real less application or only the link to
busybox? (It should be in /bin.) The busybox replacement of less is a farce.

Also, which version of less does your Pup have? My DPupBuster64 has less
version 487, whereas the most recent is less version 562beta as of this writing.
You can find out the version with

Code: Select all

less --version
Finally, the use of the parameter --color=always with ls or grep may help send
the ANSI codes to less. As explained here:
https://unix.stackexchange.com/question ... red-output
I get colored results with the following pipe, even under lxterminal:

Code: Select all

 ls -g --color=always | less -R -r
IHTH

Posted: Mon 06 Jul 2020, 21:48
by step
@jpit3, if you like vim -R as a pager take a look at vimpager for a better experience, such as vim key bindings, color schemes, and syntax highlighting support. I use it in tandem with less. Less is fast and reliable, a workhorse. vimpager is nicer when I want to study something in depth.

Posted: Thu 09 Jul 2020, 04:13
by musher0
Hi.

I just tripped on this while looking for something else.
I had forgotten about it.

Installing lesspipe could help coloring of text to some extent.
https://github.com/wofr06/lesspipe.sh/a ... sspipe.zip
lesspipe is a companion script to less and provides some coloring utiltiies
for less.

Unpack in its own directory
and
enter there with a console.
Type ./configure and then answer the yes / no questions.
Be patient, the list is long!

When finished configuring, copy
lesspipe.sh, code2color, sxw2txt and tarcolor to /usr/local/bin.
Then make a symlink of lesspipe.sh from /usr/local/bin to /usr/bin.

This should facilitate coloring of some text, as well as displaying in the less
viewer texts inside various types of archives. (There is also zless at /bin for
this, IIRC.)

IHTH

Posted: Fri 10 Jul 2020, 00:08
by tallboy
jplt3, I feel really stupid, you asked about less, not ls. Sorry, brainfart!

Posted: Fri 10 Jul 2020, 00:28
by Semme
TB, you must be :mrgreen: MAD! :D:wink: