R@ndom Curve

Making nano work MAC OS X
Andres C. Rodriguez 2015-09-02

I have a lot of editors in my computer. I have Atom (after Textmate and Sublime), I edit code via IntelliJ and Eclipse, I maintain a diary via Day One and I maintain notes via Quiver. But once in a while, I want nano. I know I shouldn’t (based on the now famous XKCD cartoon about Real Programmers).

Nano Editor

The problem is nano is very bare bones in Mac OS X. It is an old version (that I suppose Apple is no longer interested in updating) and it does not come with at least syntax highlighting. Here is a description of how fix that.

Syntax Highlighting

In order to make nano do syntax highlighting we need to fetch the syntaxes. I found an old version of them that works almost well with the nano that ships with Macs. Note that this old files are preferable to new versions because they have less non-supported constructs.

First, download and install the *.nanorc files.

curl -O http://webapp.org.ua/wp-content/uploads/2011/07/nanorc.tar
cd /usr/local/share
sudo mkdir nano
cd nano
sudo cp ~/usr/local/share/nano/*.nanorc .

This downloads the nano rc files and copies them to their canonical location. Afterward we create a file ~/.nanorc with the following content (could be done via nano itself bu typing nano ~/.nanorc):

set nowrap
set tabsize 4
set tabstospaces
set mouse
include "/usr/local/share/nano/asm.nanorc"
include "/usr/local/share/nano/awk.nanorc"
include "/usr/local/share/nano/c.nanorc"
include "/usr/local/share/nano/cmake.nanorc"
include "/usr/local/share/nano/css.nanorc"
include "/usr/local/share/nano/debian.nanorc"b
include "/usr/local/share/nano/fortran.nanorc"
include "/usr/local/share/nano/gentoo.nanorc"
include "/usr/local/share/nano/groff.nanorc"
include "/usr/local/share/nano/html.nanorc"
include "/usr/local/share/nano/java.nanorc"
include "/usr/local/share/nano/makefile.nanorc"
include "/usr/local/share/nano/man.nanorc"
include "/usr/local/share/nano/mutt.nanorc"
include "/usr/local/share/nano/nanorc.nanorc"
include "/usr/local/share/nano/objc.nanorc"
include "/usr/local/share/nano/ocaml.nanorc"
include "/usr/local/share/nano/patch.nanorc"
include "/usr/local/share/nano/php.nanorc"
include "/usr/local/share/nano/pov.nanorc"
include "/usr/local/share/nano/sh.nanorc"
include "/usr/local/share/nano/tcl.nanorc"
include "/usr/local/share/nano/tex.nanorc"
include "/usr/local/share/nano/xml.nanorc"

Correcting rc files

You might have to correct a few header errors depending on the version of nano. For example, the version of sh.nanorc on the date I am writing this was:

## Here is an example for Bourne shell scripts.
##
syntax "sh" "\.sh$"
header "^#!.*/(ba|k|pdk)?sh[-0-9_]*"
icolor brightgreen "^[0-9A-Z_]+\(\)"

# ...

color ,green "[[:space:]]+$"

And header is a new command that nano does not understand, therefore it should be commented out. Additionally, if we want the shell syntax to be recognized in .profile for example, we should change the syntax line for:

syntax "sh" "\.sh$" "\.profile$"