-
-
Save bahamas10/542875bb47990933638d2b7dfaa501bf to your computer and use it in GitHub Desktop.
| # annotated by dave eddy (@yousuckatprogramming) | |
| # explained - https://youtu.be/D0sG2fj0G4Y | |
| # borrowed heavily from https://grml.org | |
| # Begin blinking text mode | |
| # I just use bold red here since my terminal has blinking disabled | |
| export LESS_TERMCAP_mb=$'\e[1;31m' | |
| # Begin bold text mode | |
| export LESS_TERMCAP_md=$'\e[1;31m' | |
| # End all special formatting started by mb/md/etc. | |
| export LESS_TERMCAP_me=$'\e[0m' | |
| # End standout mode | |
| export LESS_TERMCAP_se=$'\e[0m' | |
| # Begin standout mode | |
| # search results - bold, yellow foreground, blue background. | |
| export LESS_TERMCAP_so=$'\e[1;33;44m' | |
| # End underline mode | |
| export LESS_TERMCAP_ue=$'\e[0m' | |
| # Begin underline mode | |
| # underline and bold green | |
| export LESS_TERMCAP_us=$'\e[4;1;32m' | |
| # Begin reverse-video mode | |
| export LESS_TERMCAP_mr=$'\e[7m' | |
| # Begin dim/half-bright mode | |
| export LESS_TERMCAP_mh=$'\e[2m' | |
| # Begin subscript mode | |
| # (probably isn't supported) | |
| export LESS_TERMCAP_ZN=$'\e[74m' | |
| # End subscript mode | |
| # (probably isn't supported) | |
| export LESS_TERMCAP_ZV=$'\e[75m' | |
| # Begin superscript mode | |
| # (probably isn't supported) | |
| export LESS_TERMCAP_ZO=$'\e[73m' | |
| # End superscript mode | |
| # (probably isn't supported) | |
| export LESS_TERMCAP_ZW=$'\e[75m' | |
| # Finally wire up `man` to use `less` | |
| # this is usually the default but let's just be sure | |
| export MANPAGER='less' |
| export LESS_TERMCAP_mb=$'\e[1;31m' | |
| export LESS_TERMCAP_md=$'\e[1;31m' | |
| export LESS_TERMCAP_me=$'\e[0m' | |
| export LESS_TERMCAP_se=$'\e[0m' | |
| export LESS_TERMCAP_so=$'\e[1;33;44m' | |
| export LESS_TERMCAP_ue=$'\e[0m' | |
| export LESS_TERMCAP_us=$'\e[4;1;32m' | |
| export LESS_TERMCAP_mr=$'\e[7m' | |
| export LESS_TERMCAP_mh=$'\e[2m' | |
| export LESS_TERMCAP_ZN=$'\e[74m' | |
| export LESS_TERMCAP_ZV=$'\e[75m' | |
| export LESS_TERMCAP_ZO=$'\e[73m' | |
| export LESS_TERMCAP_ZW=$'\e[75m' | |
| export MANPAGER='less' |
| export LESS_TERMCAP_mb=$(tput bold; tput setaf 1) | |
| export LESS_TERMCAP_md=$(tput bold; tput setaf 1) | |
| export LESS_TERMCAP_me=$(tput sgr0) | |
| export LESS_TERMCAP_se=$(tput sgr0) | |
| export LESS_TERMCAP_so=$(tput bold; tput setaf 3; tput setab 4) | |
| export LESS_TERMCAP_ue=$(tput sgr0) | |
| export LESS_TERMCAP_us=$(tput smul; tput bold; tput setaf 2) | |
| export LESS_TERMCAP_mr=$(tput rev) | |
| export LESS_TERMCAP_mh=$(tput dim) | |
| export LESS_TERMCAP_ZN=$(tput ssubm) | |
| export LESS_TERMCAP_ZV=$(tput rsubm) | |
| export LESS_TERMCAP_ZO=$(tput ssupm) | |
| export LESS_TERMCAP_ZW=$(tput rsupm) | |
| export MANPAGER='less' |
All I had to do to get it working on zsh was to add export GROFF_NO_SGR=1 and it works! Thanks man! Also thank you Mark Jreed for the set -a tip it cuts down on the use of export which I like.
For all using Arch try export MANROFFOPT='-c' this activates Overstrike for me. To check if Overstrike is enabled use MAN_KEEP_FORMATTING=1 man ls | cat -v | head else it will not show the escape sequenzes.
for fish users:
(i just put this in ~/.config/fish/conf.d/man.fish)
# annotated by dave eddy (@yousuckatprogramming)
# explained - https://youtu.be/D0sG2fj0G4Y
# borrowed heavily from https://grml.org
# converted to fish syntax
# Begin blinking text mode
# I just use bold red here since my terminal has blinking disabled
set -x LESS_TERMCAP_mb (printf '\e[1;31m')
# Begin bold text mode
set -x LESS_TERMCAP_md (printf '\e[1;31m')
# End all special formatting started by mb/md/etc.
set -x LESS_TERMCAP_me (printf '\e[0m')
# End standout mode
set -x LESS_TERMCAP_se (printf '\e[0m')
# Begin standout mode
# search results - bold, yellow foreground, blue background.
set -x LESS_TERMCAP_so (printf '\e[1;33;44m')
# End underline mode
set -x LESS_TERMCAP_ue (printf '\e[0m')
# Begin underline mode
# underline and bold green
set -x LESS_TERMCAP_us (printf '\e[4;1;32m')
# Begin reverse-video mode
set -x LESS_TERMCAP_mr (printf '\e[7m')
# Begin dim/half-bright mode
set -x LESS_TERMCAP_mh (printf '\e[2m')
# Begin subscript mode
# (probably isn't supported)
set -x LESS_TERMCAP_ZN (printf '\e[74m')
# End subscript mode
# (probably isn't supported)
set -x LESS_TERMCAP_ZV (printf '\e[75m')
# Begin superscript mode
# (probably isn't supported)
set -x LESS_TERMCAP_ZO (printf '\e[73m')
# End superscript mode
# (probably isn't supported)
set -x LESS_TERMCAP_ZW (printf '\e[75m')
# Finally wire up `man` to use `less`
# this is usually the default but let's just be sure
set -x MANPAGER 'less'
# For all using Arch try export MANROFFOPT='-c' this activates Overstrike for me
set -x MANROFFOPT '-c'For anybody who had tried it out on Bash and wondered why colors did not appear, Claude helped me to find out why mentioning this one caveat:
Some systems/terminals use groff + less with different settings.
This extra environment variable must be added:
export GROFF_NO_SGR=1This forces groff to output old-style terminal escape codes that less can then interpret via the LESS_TERMCAP_* variables, rather than using its own SGR sequences.
In putty ssh
-
Enable 256-Color Mode: In the PuTTY Configuration window, go to Window -> Colours and ensure "Allow terminal to use xterm 256-colour mode" is checked.
-
Set Terminal Type: Go to Connection -> Data and set the "Terminal-type string" to xterm-256color.
-
Bold as Colour: Under Window -> Colours, ensure "Indicate bolded text by changing: Both" or "The colour" is selected so bold text appears as a different color rather than just a thicker font.
In addition to the bashrc settings in https://gist.github.com/bahamas10/542875bb47990933638d2b7dfaa501bf#file-zz-no-comments-bash also put
export MANROFFOPT='-c'
For anybody who had tried it out on Bash and wondered why colors did not appear, Claude helped me to find out why mentioning this one caveat:
Some systems/terminals use
groff+lesswith different settings. This extra environment variable must be added:export GROFF_NO_SGR=1This forces
groffto output old-style terminal escape codes thatlesscan then interpret via theLESS_TERMCAP_*variables, rather than using its own SGR sequences.
I was doing some digging myself for fun and it turns out without GROFF_NO_SGR, there is another way to have colors with -c like in the video. Other than setting MANROFFOPT or a huge chain like Dave showed, setting GROFF_NO_SGR is probably your best bet.
Here are some notes and things I found during this rabbit hole I went down.
Note
Theres no need to pipe cat into less, redundant even.
You do not need to do cat file | groff; groff file # works.
Note that I used troff which by default does not require -Z (disabling preprocessor), if you use groff -Z or -P-c is required.
Please note that I put GROFF_NO_SGR=null before grotty to test and it is not required so long as -c is declared somewhere between groff/grotty.
Also note that < <(ul) is not at all required but messing up ul will make u lose colors i.e. grotty -c | ul | colcrt or outright just shows nothing as ul dumbs down to cat with less reading an empty cat stdin .
colcrt is meant mroe for nroff and used by more, more is the older version of less with ironically less features and not as used nowadays.
Also note that as said in point 2, no need to cat file, directly groff file works meaning to say groff < <(cat /usr/share/man/man1/ls.1) will just work the same as groff /usr/share/man/man1/ls.1
As I was working through my way researchng this rabbit hole of man troff grotty nroff groff etc. rabbit hole, I was unable to get grotty to output the man pages correctly
That's because on my NixOS machine, my man files are gunzipped compressed which I am willing to bet most of you trying the tutorial have the same on debian machines. If not, yippe. I am using alacritty but the no color effect appeared on ghostty.
Warning
If your man file is compressed with .gz; Proceed to uncompress the file you're trying to use groff to read manually with gunzip /path/to/file e.g.: gunzip /usr/share/man/man1/lscpu.1.gz
Going through this rabbit hole of just plan using environmental variables for less to output colors even without it being compressed, as in, /usr/share/man/man1/ls, does not show colors without either grotty -c or groff -P-c or GROFF_NO_SGR. This is a matter of terminal rendering the old supported SGR and OCS sequences it seems.
Have a wonderful day ahead and thank you Dave for introducing this rabbit hole for myself to learn more!
FWIW, you can factor out the repeated
exports by just doingset -o allexport(orset -afor short) at the top and thenset +o allexport(orset +a) at the bottom. Cuts down on the noise, IMO.