Ssh – Why does nano sometimes show colors over SSH

nanosshsyntax highlighting

Typically when I'm editing a small file over SSH I'll just open up nano. I look at my apache2 access.log a good bit. Since I don't have fail2ban or anything enabled on this box, I typically look at access.log.1 as well. I've noticed in my access.log.(#) a particular line always has an odd highlighting:

GET /w00tw00t.at.ISC.SANS.DFind:) HTTP/1.1" 400 516 "-" "-"
enter image description here

More things I've noticed:

  • This only happens if there is a .B or a .I in the line, and every letter after that on the line is red
  • This only happens in files that end in a number; it occurs in access.log.1, but not access.log. Same for any test.log.1
  • This only works for filename.1 through filename.9
  • From the line syntax "man" "\.[1-9]x?$" I get that files .1 through .9 are highlighted.. but why?

Apparently the files in /usr/share/nano handle syntax highlighting, After a bit of digging, I found out that one file in particular is responsible for this: man.nanorc. Here are the contents of it:

## Here is an example for manpages.
##
syntax "man" "\.[1-9]x?$"
color green "\.(S|T)H.*$"
color brightgreen "\.(S|T)H" "\.TP"
color brightred "\.(BR?|I[PR]?).*$"
color brightblue "\.(BR?|I[PR]?|PP)"
color brightwhite "\\f[BIPR]"
color yellow "\.(br|DS|RS|RE|PD)"

For files such as wp-config.php on a wordpress site, nano does syntax highlighting correctly. What is so special about .I and .B that makes the first character blue and the rest red, and what does this have to do with the .1?

Best Answer

With those syntax-highlighting rules files, nano assumes that filenames ending in .1 - .9 are man pages.

It's been quite a while since I edited a man page, but I'm pretty sure that in groff -man, .I is for italic and .Bis for bold.

Related Question