Colorize Terminal on the Mac
When programming, it is common to spend a lot of time using a command-line shell. On the Mac, the program used is Terminal.
Recently I discovered that it is possible to spruce up the mundane appearance of Terminal by adding color. There are two techniques that I will show to add color, one to colorize the output from the 'ls' command, and another that colorizes the two simple text editors, nano and pico.
First, let us begin with colorizing the 'ls' command, which is helpful for file system navigation. With this setting, directories are displayed as one color, regular files another, executables yet another, and so on. To make this happen, add the following two lines to either ~/.bash_profile to apply for just the single user, or to /etc/bashrc for all users.
export CLICOLOR=1 export LSCOLORS=ExGxCxDxBxegedabagacad
You can add the two lines using pico, or some other editor, or you can add them in one command, using the append '>>' sign.
echo "export CLICOLOR=1 export LSCOLORS=ExGxCxDxBxegedabagacad" >> ~/.bash_profile
The colors can be changed by editing the LSCOLORS value. You can find a LSCOLORS generator here.
The second modification is to edit the /etc/nanorc file. This file is the configuration file for both nano and pico. I personally use 'ssh' quite a bit, for which I use pico as the text editor of choice. However, it can be difficult to use pico to edit certain files since it does not colorize the different keywords of the programming languages. I am so accustomed to programming on text editors (like TextWrangler) that have color that I find the plain white text of pico to be a handicap. This can be fixed by editing the /etc/nanorc file, configuring the editor to add colors to certain types of files (php, c++, java, and so on).
The configuration of the /etc/nanorc file that I am currently using is as follows:
/etc/nanorc
## Initialization file for GNU nano ## Please note that you must have configured nano with --enable-nanorc ## for this file to be read! Also note that characters especially ## interpreted by the shell should not be escaped here. ## ## To make sure a value is not enabled, use "unset <option>" ## ## For the options that take parameters, the default value is given. ## Other options are unset by default. ## ## Quotes inside string parameters don't have to be escaped with ## backslashes. The last double quote in the string will be treated as ## its end. For example, for the "brackets" option, ""')>]}" will match ## ", ', ), >, ], and }. ## Use auto-indentation set autoindent ## Backup files to filename~ # set backup ## The directory to put the backup files in. # set backupdir "" ## Do backwards searches by default. # set backwards ## Use bold text instead of reverse video text. # set boldtext ## The characters treated as closing brackets when justifying ## paragraphs. They cannot contain blank characters. Only closing ## punctuation, optionally followed by closing brackets, can end ## sentences. ## # set brackets ""')>]}" ## Do case sensitive searches by default. # set casesensitive ## Constantly display the cursor position in the status bar. set const ## Use cut to end of line with ^K by default # set cut ## Set the line length for wrapping text and justifying paragraphs. ## If fill is negative, the line length will be the screen width less ## this number. ## # set fill -8 ## Enable ~/.nano_history for saving and reading search/replace strings. # set historylog ## The opening and closing brackets that can be found by bracket ## searches. They cannot contain blank characters. The former set must ## come before the latter set, and both must be in the same order. ## # set matchbrackets "(<[{)>]}" ## Use the blank line below the titlebar as extra editing space. # set morespace ## Enable mouse support, if available for your system. When enabled, ## mouse clicks can be used to place the cursor, set the mark (with a ## double click), and execute shortcuts. The mouse will work in the X ## Window System, and on the console when gpm is running. ## # set mouse ## Allow multiple file buffers (using ^R inserts into separate buffer). ## You must have configured with --enable-multibuffer or --enable-extra ## for this to work. ## ## set multibuffer ## Don't convert files from DOS/Mac format # set noconvert ## Don't follow symlinks when writing files # set nofollow ## Don't display the help lists at the bottom of the screen # set nohelp ## Don't add newlines to the ends of files. # set nonewlines ## Don't wrap text at all set nowrap ## Set operating directory. nano will not read or write files outside ## this directory and its subdirectories. Also, the current directory ## is changed to here, so files are inserted from this dir. A blank ## string means the operating directory feature is turned off. ## # set operatingdir "" ## Preserve the XON and XOFF keys (^Q and ^S) # set preserve ## The characters treated as closing punctuation when justifying ## paragraphs. They cannot contain blank characters. Only closing ## punctuation, optionally followed by closing brackets, can end ## sentences. ## # set punct "!.?" ## Do quick statusbar blanking. Statusbar messages will disappear after ## 1 keystroke instead of 26. Note that "const" overrides this. ## # set quickblank ## The email-quote string, used to justify email-quoted paragraphs. ## This is an extended regular expression if your system supports them, ## otherwise a literal string. Default: # set quotestr "^([ ]*[\|>:}#])+" ## if you have regexps, otherwise: # set quotestr "> " ## You can get old nano quoted-justify behavior via: # set quotestr "(> )+" ## Fix Backspace/Delete confusion problem # set rebinddelete ## Fix numeric keypad key confusion problem. # set rebindkeypad ## Do extended regular expression searches by default set regexp ## Make the Home key smarter. When Home is pressed anywhere but at the ## very beginning of non-blackspace characters on a line, the cursor ## will jump to that beginning (either forwards or backwards). If the ## cursor is already at that position, it will jump to the true ## beginning of the line. # set smarthome ## Use smooth scrolling as the default set smooth ## Use this spelling checker instead of the internal one. This option ## does not properly have a default value. ## # set speller "aspell -c" ## Allow nano to be suspended with ^Z # set suspend ## Use this tab size instead of the default; it must be greater than 0 set tabsize 4 ## Convert typed tabs to spaces. # set tabstospaces ## Use this tab char instead of the default space; it can either be the ## ascii value of the character you wish to see (refer to ascii(7)) or ## it can be a single character. 187 seems to be a 'good' value. # set tabconvert 32 ## Same as tabconverting above, but applied to spaces. ## it can be a single character. 183 seems to be a 'good' value. # set spaceconvert 32 ## Finally, you can toggle whitespace converting with this # set wsconvert ## Save automatically on exit, don't prompt # set tempfile ## Disallow file modification, why would you want this in an rc file? ;) # set view ## The two single-column characters used to display the first characters ## of tabs and spaces. 187 in ISO 8859-1 (0000BB in Unicode) and 183 in ## ISO-8859-1 (0000B7 in Unicode) seem to be good values for these. # set blackspace " " ## Detect word boundaries more accurately by treating punctuation ## characters as part of a word. # set wordbounds ## Color setup ## ## Format: ## ## syntax "short description" ["filename regex" ...] ## ## The "none" syntax is reserved; specifying it on the command line is ## the same as not having a syntax at all. The "default" syntax is ## special: it takes no filename regexes, and applies to files that ## don't match any other syntax's filename regexes. ## ## color foreground,background "regex" ["regex"...] ## or ## icolor foreground,background "regex" ["regex"...] ## ## "color" will do case sensitive matches, while "icolor" will do case ## insensitive matches. ## ## Valid colors: black, white, red, blue, green, yellow, magenta, cyan. ## For foreground colors, you may use the prefix "" to get a ## stronger highlight. ## ## To use multi-line regexes, use the start="regex" end="regex" ## [start="regex" end="regex"...] format. ## ## If your system supports transparency, not specifying a background ## color will use a transparent color. If you don't want this, be sure ## to set the background color to black or black. ## ## If you wish, you may put your syntaxes in separate files. You can ## make use of such files (which can only include "syntax", "color", and ## "icolor" commands) as follows: ## ## include "/path/to/syntax_file.nanorc" ## ## Unless otherwise noted, the name of the syntax file (without the ## ".nanorc" extension) should be the same as the "short description" ## name inside that file. These names are kept fairly short to make ## them easier to remember and faster to type using nano's -Y option. ## ## All regexes should be extended regular expressions. ## Nanorc files #include "/usr/share/nano/nanorc.nanorc" syntax "nanorc" "\.?nanorc$" ## Possible errors and parameters #icolor black "^[[:space:]]*((un)?set|include|syntax|i?color).*$" ## Keywords icolor green "^[[:space:]]*(set|unset)[[:space:]]+(autoindent|backup|backupdir|backwards|boldtext|brackets|casesensitive|const|cut|fill|historylog|matchbrackets|morespace|mouse|multibuffer|noconvert|nofollow|nohelp|nonewlines|nowrap|operatingdir|preserve|punct)\>" "^[[:space:]]*(set|unset)[[:space:]]+(quickblank|quotestr|rebinddelete|rebindkeypad|regexp|smarthome|smooth|softwrap|speller|suspend|suspendenable|tabsize|tabstospaces|tempfile|undo|view|blackspace|wordbounds)\>" icolor green "^[[:space:]]*(set|unset|include|syntax|header)\>" ## Colors icolor yellow "^[[:space:]]*i?color[[:space:]]*()?(black|black|red|blue|green|yellow|magenta|cyan)?(,(black|black|red|blue|green|yellow|magenta|cyan))?\>" icolor magenta "^[[:space:]]*i?color\>" "\<(start|end)=" ## Strings #icolor black ""(\\.|[^"])*"" ## Comments icolor blue "^[[:space:]]*#.*$" icolor cyan "^[[:space:]]*##.*$" ## C/C++ #include "/usr/share/nano/c.nanorc" syntax "c" "\.(c(c|pp|xx)?|C)$" "\.(h(h|pp|xx)?|H)$" "\.ii?$" color red "\<[A-Z_][0-9A-Z_]+\>" color green "\<(float|double|bool|char|int|short|long|sizeof|enum|void|static|const|struct|union|typedef|extern|(un)?signed|inline)\>" color green "\<((s?size)|((u_?)?int(8|16|32|64|ptr)))_t\>" color green "\<(class|namespace|template|public|protected|private|typename|this|friend|virtual|using|mutable|volatile|register|explicit)\>" color yellow "\<(for|if|while|do|else|case|default|switch)\>" color yellow "\<(try|throw|catch|operator|new|delete)\>" color magenta "\<(goto|continue|break|return)\>" color cyan "^[[:space:]]*#[[:space:]]*(define|include|(un|ifn?)def|endif|el(if|se)|if|warning|error)" color magenta "'([^'\]|(\\["'abfnrtv\\]))'" "'\\(([0-3]?[0-7]{1,2}))'" "'\\x[0-9A-Fa-f]{1,2}'" ## ## GCC builtins color cyan "__attribute__[[:space:]]*\(\([^)]*\)\)" "__(aligned|asm|builtin|hidden|inline|packed|restrict|section|typeof|weak)__" ## ## String highlighting. You will in general want your comments and ## strings to come last, because syntax highlighting rules will be ## applied in the order they are read in. color yellow "<[^= ]*>" ""(\\.|[^"])*"" ## ## This string is VERY resource intensive! color yellow start=""(\\.|[^"])*\\[[:space:]]*$" end="^(\\.|[^"])*"" ## Comment highlighting color blue "//.*" color blue start="/\*" end="\*/" ## Trailing whitespace color ,green "[[:space:]]+$" ## Shell Scripts ## syntax "shellscript" "\.sh$" "\.?profile$" "\.?bashrc$" "\.?cshrc$" "^rc\..*" ## keywords color brightblue "\<(case|do|done|elif|else|esac|exit|fi|for|function|if|in|local|read|return|select|shift|then|time|until|while)\>" ## operators color white "(\{|\}|\(|\)|\;|\]|\[|`|\\|<|>|!|=|&|\|)" ## quotes (double/single/backticks) color brightcyan "`(\\.|[^`])*`" color yellow ""(\\.|[^\"])*"" color yellow "'(\\.|[^'])*'" ## variables (define/defined/bracketed/unhighlight '=') # color cyan "[a-zA-Z_0-9#?*@$<\-_!]+=" color cyan "\$[a-zA-Z_0-9?*@$<\-_!]+" color cyan "\$\{[^}]*\}" color cyan "\$#" # color white "=" ## comments ## hashes at line beg or after whitespace color green "((^#)|(\s#)).*$" ## magic number color brightgreen "#!.*$" ## Basic Conf Scripts ## # just color comments syntax "confile" "\.co?nf" "\.config$" "\.?logout$" "\.?inittab$" "pf.conf" "^hostname\." "fstab" "\.?nanorc" color green "#.*$" ## Patch files ## syntax "patch" "\.(patch|diff)$" color brightgreen "^\+.*" color green "^\+\+\+.*" color brightblue "^ .*" color brightred "^-.*" color red "^---.*" color brightcyan "^ <at> <at> .*" color magenta "^diff.*" ## Manpages #include "/usr/share/nano/man.nanorc" syntax "man" "\.[1-9]x?$" color green "\.(S|T)H.*$" color green "\.(S|T)H" "\.TP" color red "\.(BR?|I[PR]?).*$" color blue "\.(BR?|I[PR]?|PP)" color white "\\f[BIPR]" color yellow "\.(br|DS|RS|RE|PD)" ## Perl ## syntax "perl" "\.p[lm]$" ## subroutine execution color brightgreen "(.*\(.*\);)" ## operators and some symbol characters color brightred "(\&\&|\|\||\=\=|\,|\;| \/ | \* | \= |\$|\@|\%|\=\~)" ## builtin references color brightblue "\<(accept|alarm|atan2|bin(d|mode)|c(aller|h(dir|mod|omp|op|own|root)|lose(dir)?|onnect|os|rypt)|d(bm(close|open)|efined|elete|ie|o|ump)|e(ach|of|val|x(ec|ists|it|p))|f(cntl|ileno|lock|ork)|get(c|login|peername|pgrp|ppid|priority|pwnam|(host|net|proto|serv)byname|pwuid|grgid|(host|net)byaddr|protobynumber|servbyport)|([gs]et|end)(pw|gr|host|net|proto|serv)ent|getsock(name|opt)|gmtime|goto|grep|hex|index|int|ioctl|join|keys|kill|last|length|link|listen|local(time)?|log|lstat|m|mkdir|msg(ctl|get|snd|rcv)|next|oct|open(dir|2|3)?|ord|pack|pipe|pop|printf?|push|q|qq|qx|rand|re(ad(dir|link)?|cv|do|name|quire|set|turn|verse|winddir)|rindex|rmdir|scalar|seek|seekdir|se(lect|mctl|mget|mop|nd|tpgrp|tpriority|tsockopt)|shift|shm(ctl|get|read|write)|shutdown|sin|sleep|socket(pair)?|sort|spli(ce|t)|sprintf|sqrt|srand|stat|study|substr|symlink|sys(call|read|tem|write)|tell(dir)?|time|tr|y|truncate|umask|un(def|link|pack|shift)|utime|values|vec|wait(pid)?|wantarray|warn|write)\>" ## logical references color brightblue "\<(and|or|continue|else|elsif|do|for|foreach|if|unless|until|while|eq|ne|lt|gt|le|ge|cmp|x|my|sub|use|package|can|isa)\>" ## regexes (part 1) color brightcyan "[sm]/.*/" color brightcyan "[sm]/.*/.*/." ## try to do new/use.. doesnt work perfectly color white start="(^use| = new)" end=";" color white start="(^use| = new)" end=";" ## variables #color cyan start="[$@%]" end="( |\\W|-|\n)" color cyan "[$@%][a-zA-Z_0-9#?*@$<\-_!]+" ## try and fix the ;'s at the end of every statement color brightred "\;$|;.*#|;.*}" ## block reading color red "<.*>" ## try and tidy up ->'s, parenthesis's, curly braces and square braces color yellow "(\(|\)|->|\{|\}|\[|\])" ## regexes and quotations color brightcyan "/.*/|/.*/\w+" color brightyellow "'.*'|".*"|qq\|.*\|" ## comments - can get confused if inside quotations color green "#.*" ## block quotes/input color white start="<<STOP" end="STOP" color white start="<<EOF" end="EOF" color white start="<<START" end="START" ## HTML ## syntax "HTML" "\.html$" "\.htm$" ## legitimate tags color brightcyan start="</?(!DOCTYPE|A|ABBR|ACRONYM|ADDRESS|APPLET|AREA|B|BASE|BASEFONT|BDO|BGSOUND|BIG|BLINK|BLOCKQUOTE|BODY|BR|BUTTON|CAPTION|CENTER|CITE|CODE|COL|COLGROUP|DD|DEL|DFN|DIR|DIV|DL|DT|EM|EMBED|FIELDSET|FONT|FORM|FRAME|FRAMESET|H1|H2|H3|H4|H5|H6|HEAD|HR|HTML|I|IFRAME|ILAYER|IMG|INPUT|INS|ISINDEX|KBD|KEYGEN|LABEL|LAYER|LEGEND|LI|LINK|LISTING|MAP|MENU|META|MULTICOL|NOBR|NOEMBED|NOFRAMES|NOLAYER|NOSCRIPT|OBJECT|OL|OPTGROUP|OPTION|P|PARAM|PLAINTEXT|PRE|Q|S|SAMP|SCRIPT|SELECT|SERVER|SMALL|SOUND|SPACER|SPAN|STRIKE|STRONG|STYLE|SUB|SUP|TBODY|TEXTAREA|TITLE|TT|U|UL|VAR|WBR|XMPTABLE|TD|TFOOT|TH|THEAD|T)( |>)" end=">" color brightcyan start="</?(!doctype|a|abbr|acronym|address|applet|area|b|base|basefont|bdo|bgsound|big|blink|blockquote|body|br|button|caption|center|cite|code|col|colgroup|dd|del|dfn|dir|div|dl|dt|em|embed|fieldset|font|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|hr|html|i|iframe|ilayer|img|input|ins|isindex|kbd|keygen|label|layer|legend|li|link|listing|map|menu|meta|multicol|nobr|noembed|noframes|nolayer|noscript|object|ol|optgroup|option|p|param|plaintext|pre|q|s|samp|script|select|server|small|sound|spacer|span|strike|strong|style|sub|sup|tbody|textarea|title|tt|u|ul|var|wbr|xmp|table|td|tfoot|th|thead|tr)( |>)" end=">" ## table tags color brightred "</?(TABLE|TD|TFOOT|TH|THEAD|TR)" color brightred "</?(table|td|tfoot|th|thead|tr)" ## attributes color brightblue " (ACCESSKEY|ACTION|ALIGN|ALINK|ALT|BACKGROUND|BALANCE|BEHAVIOR|BGCOLOR|BGPROPERTIES|BORDER|BORDERCOLOR|BORDERCOLORDARK|BORDERCOLORLIGHT|BOTTOMMARGIN|CELLPADDING|CELLSPACING|CHECKED|CLASS|CLASSID|CLEAR|CODE|CODEBASE|CODETYPE|COLOR|COLS|COLSPAN|COMPACT|CONTENT|CONTROLS|COORDS|DATA|DATAFLD|DATAFORMATAS|DATASRC|DIRECTION|DISABLED|DYNSRC|ENCTYPE|EVENT|FACE|FOR|FRAME|FRAMEBORDER|FRAMESPACING|HEIGHT|HIDDEN|HREF|HSPACE|HTTP-EQUIV|ID|ISMAP|LANG|LANGUAGE|LEFTMARGIN|LINK|LOOP|LOWSRC|MARGINHEIGHT|MARGINWIDTH|MAXLENGTH|MAYSCRIPT|METHOD|METHODS|MULTIPLE|NAME|NOHREF|NORESIZE|NOSHADE|NOWRAP|PALETTE|PLUGINSPAGE|PUBLIC|READONLY|REL|REV|RIGHTMARGIN|ROWS|ROWSPAN|RULES|SCROLL|SCROLLAMOUNT|SCROLLDELAY|SCROLLING|SELECTED|SHAPE|SIZE|SPAN|SRC|START|STYLE|TABINDEX|TARGET|TEXT|TITLE|TOPMARGIN|TRUESPEED|TYPE|URL|URN|USEMAP|VALIGN|VALUE|VLINK|VOLUME|VRML|VSPACE|WIDTH|WRAP)" color brightblue " (accesskey|action|align|alink|alt|background|balance|behavior|bgcolor|bgproperties|border|bordercolor|bordercolordark|bordercolorlight|bottommargin|cellpadding|cellspacing|checked|class|classid|clear|code|codebase|codetype|color|cols|colspan|compact|content|controls|coords|data|datafld|dataformatas|datasrc|direction|disabled|dynsrc|enctype|event|face|for|frame|frameborder|framespacing|height|hidden|href|hspace|http-equiv|id|ismap|lang|language|leftmargin|link|loop|lowsrc|marginheight|marginwidth|maxlength|mayscript|method|methods|multiple|name|nohref|noresize|noshade|nowrap|palette|pluginspage|public|readonly|rel|rev|rightmargin|rows|rowspan|rules|scroll|scrollamount|scrolldelay|scrolling|selected|shape|size|span|src|start|style|tabindex|target|text|title|topmargin|truespeed|type|url|urn|usemap|valign|value|vlink|volume|vrml|vspace|width|wrap)" ## quotes within tags color yellow ""(\\.|[^\"])*"" color yellow "'(\\.|[^'])*'" ## everything outside of tags color white start=">" end="<" ## amp escapes color brightmagenta start="&" end=";" ## tag delimiters color brightcyan "<|>" ## comments color green start="<!--" end="-->" ## XML ## syntax "XML" "\.xml$" "\.fdi$" ## legitimate tags color brightcyan start="<" end=">" ## quotes within tags color yellow ""(\\.|[^\"])*"" color yellow "'(\\.|[^'])*'" ## everything outside of tags color brightwhite start=">" end="<" ## amp escapes color brightmagenta start="&" end=";" ## tag delimiters color brightcyan "<|>" ## comments color green start="<!--" end="-->" ## Javascript syntax "JavaScript" "\.(js)$" ## Default color white "^.+$" ## Decimal, cotal and hexadecimal numbers color yellow "\<[-+]?([1-9][0-9]*|0[0-7]*|0x[0-9a-fA-F]+)([uU][lL]?|[lL][uU]?)?\>" ## Floating point number with at least one digit before decimal point color yellow "\<[-+]?([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([EePp][+-]?[0-9]+)?[fFlL]?" color yellow "\<[-+]?([0-9]+[EePp][+-]?[0-9]+)[fFlL]?" ## Keywords color green "\<(break|case|catch|continue|default|delete|do|else|finally)\>" color green "\<(for|function|if|in|instanceof|new|null|return|switch)\>" color green "\<(switch|this|throw|try|typeof|undefined|var|void|while|with)\>" ## Type specifiers color red "\<(Array|Boolean|Date|Enumerator|Error|Function|Math)\>" color red "\<(Number|Object|RegExp|String)\>" color red "\<(true|false)\>" ## String color brightyellow "L?\"(\\"|[^"])*\"" color brightyellow "L?'(\'|[^'])*'" ## Escapes color red "\\[0-7][0-7]?[0-7]?|\\x[0-9a-fA-F]+|\\[bfnrt'"\?\\]" ## Comments color magenta start="/\*" end="\*/" color magenta "//.*$" ## PHP #include "/usr/share/nano/php.nanorc" syntax "php" "\.php$" "\.php[2345s]$" "\.phtml$" ##functions color brightmagenta "([A-Za-z0-9])" ##numbers #color brightblue "[0-9]" ##special color blue "(^|[^A-Za-z0-9])(<\?php|\?>|var|and|or|default|class|extends|true|false|global|function|new|switch|case|break|next|prev|elseif|if|else|foreach|for|as|do|while|exit|die|declare|require_once|require|include_once|include|return|echo|static|array|isset)([^A-Za-z0-9])" ##types color brightred "([^A-Za-z0-9])|[^A-Za-z](null|int|string|float|bool|object|resource)[^A-Za-z0-9_]+[^A-Za-z]" ##strings color brightyellow ""(\\.|[^\"])*"" color brightyellow "'(\\.|[^\'])*'" ##Variables color brightcyan "\$[]\[A-Za-z0-9_'\"]*" ##comments color green "//.*" color green "#.*" color green start="/\*" end="\*/" ## Java ## syntax "Java source" "\.java$" color cyan "\<(boolean|byte|char|double|float|int|long|new|short|this|transient|void)\>" color brightblue "\<(break|case|catch|continue|default|do|else|finally|for|if|return|switch|throw|try|while)\>" color brightcyan "\<(abstract|class|extends|final|implements|import|instanceof|interface|native|package|private|protected|public|static|strictfp|super|synchronized|throws|volatile)\>" color red ""[^\"]*"" color magenta "\<(true|false|null)\>" color green "//.*" color green start="/\*" end="\*/" color brightblue start="/\*\*" end="\*/" color brightgreen,green " +$" ## Python ## syntax "Python" "\.py$" ## operators # color red "\{|\[|\(|\)|\]|\}|\-|\+|\*|/|<|>|\!|~|%|^|&|\|=|\\" ## built-in objects, attributes, and functions color cyan "\<(None|self|__builtin__|__dict__|__methods__|__members__|__class__|__bases__|__import__|__name__|__doc__|__self__|__debug__|abs|append|apply|buffer|callable|chr|clear|close|closed|cmp|coerce|compile|complex|conjugate|copy|count|delattr|dir|divmod|eval|execfile|extend|fileno|filter|float|flush|get|getattr|globals|has_key|hasattr|hash|hex|id|index|input|insert|int|intern|isatty|isinstance|issubclass|items|keys|len|list|locals|long|map|max|min|mode|name|oct|open|ord|pop|pow|range|raw_input|read|readline|readlines|reduce|reload|remove|repr|reverse|round|seek|setattr|slice|softspace|sort|str|tell|truncate|tuple|type|unichr|unicode|update|values|vars|write|writelines|xrange|zip)\>" ## special method names color cyan "\<(__abs__|__add__|__and__|__call__|__cmp__|__coerce__|__complex__|__concat__|__contains__|__del__|__delattr__|__delitem__|__delslice__|__div__|__divmod__|__float__|__getattr__|__getitem__|__getslice__|__hash__|__hex__|__init__|__int__|__inv__|__invert__|__len__|__long__|__lshift__|__mod__|__mul__|__neg__|__nonzero__|__oct__|__or__|__pos__|__pow__|__radd__|__rand__|__rcmp__|__rdiv__|__rdivmod__|__repeat__|__repr__|__rlshift__|__rmod__|__rmul__|__ror__|__rpow__|__rrshift__|__rshift__|__rsub__|__rxor__|__setattr__|__setitem__|__setslice__|__str__|__sub__|__xor__)\>" ## exception classes # color cyan "\<(Exception|StandardError|ArithmeticError|LookupError|EnvironmentError|AssertionError|AttributeError|EOFError|FloatingPointError|IOError|ImportError|IndexError|KeyError|KeyboardInterrupt|MemoryError|NameError|NotImplementedError|OSError|OverflowError|RuntimeError|SyntaxError|SystemError|SystemExit|TypeError|UnboundLocalError|UnicodeError|ValueError|WindowsError|ZeroDivisionError)\>" ## types color brightcyan "\<(NoneType|TypeType|IntType|LongType|FloatType|ComplexType|StringType|UnicodeType|BufferType|TupleType|ListType|DictType|FunctionType|LambdaType|CodeType|ClassType|UnboundMethodType|InstanceType|MethodType|BuiltinFunctionType|BuiltinMethodType|ModuleType|FileType|XRangeType|TracebackType|FrameType|SliceType|EllipsisType)\>" ## definitions color brightcyan "def [a-zA-Z_0-9]+" ## keywords color brightblue "\<(and|assert|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|map|not|or|pass|print|raise|return|try|while)\>" ## quoted strings color yellow ""(\\.|[^\"])*"" color yellow "'(\\.|[^'])*'" ## comments ## block commenting of """ doesn't work - color quotes only instead color green """"" color green "'''" color green "#.*$" ## Awk #include "/usr/share/nano/awk.nanorc" syntax "awk" "\.awk$" ## records icolor brightred "\$[0-9A-Z_!@#$*?-]+" ## awk-set variables color red "\<(ARGC|ARGIND|ARGV|BINMODE|CONVFMT|ENVIRON|ERRNO|FIELDWIDTHS)\>" color red "\<(FILENAME|FNR|FS|IGNORECASE|LINT|NF|NR|OFMT|OFS|ORS)\>" color red "\<(PROCINFO|RS|RT|RSTART|RLENGTH|SUBSEP|TEXTDOMAIN)\>" ## function declarations and special patterns color brightgreen "\<(function|extension|BEGIN|END)\>" ## operators color green "(\{|\}|\(|\)|\;|\]|\[|\\|<|>|!|=|&|\+|-|\*|%|/|\?:|\^|\|)" ## flow control color brightyellow "\<(for|if|while|do|else|in|delete|exit)\>" color brightyellow "\<(break|continue|return)\>" ## I/O statements color brightgreen "\<(close|getline|next|nextfile|print|printf)\>" color brightgreen "\<(system|fflush)\>" ## standard functions color magenta "\<(atan2|cos|exp|int|log|rand|sin|sqrt|srand)\>" color magenta "\<(asort|asorti|gensub|gsub|index|length|match)\>" color magenta "\<(split|sprintf|strtonum|sub|substr|tolower|toupper)\>" color magenta "\<(mktime|strftime|systime)\>" color magenta "\<(and|compl|lshift|or|rshift|xor)\>" color magenta "\<(bindtextdomain|dcgettext|dcngettext)\>" ## ## String highlighting. You will in general want your comments and ## strings to come last, because syntax highlighting rules will be ## applied in the order they are read in. color brightyellow "<[^= ]*>" ""(\\.|[^"])*"" ## Comment highlighting color brightblue "(^|[[:space:]])#.*$" ## Trailing blackspace color ,green "[[:space:]]+$" ## Ruby #include "/usr/share/nano/ruby.nanorc" ## syntax "ruby" "\.rb$" ## Asciibetical list of reserved words color yellow "\<(BEGIN|END|alias|and|begin|break|case|class|def|defined\?|do|else|elsif|end|ensure|false|for|if|in|module|next|nil|not|or|redo|rescue|retry|return|self|super|then|true|undef|unless|until|when|while|yield)\>" ## Constants color brightblue "(\$|@|@@)?\<[A-Z]+[0-9A-Z_a-z]*" ## Ruby "symbols" icolor magenta "([ ]|^):[0-9A-Z_]+\>" ## Some unique things we want to stand out color brightyellow "\<(__FILE__|__LINE__)\>" ## Regular expressions color brightmagenta "/([^/]|(\\/))*/[iomx]*" "%r\{([^}]|(\\}))*\}[iomx]*" ## Shell command expansion is in `backticks` or like %x{this}. These are ## "double-quotish" (to use a perlism). color brightblue "`[^`]*`" "%x\{[^}]*\}" ## Strings, double-quoted color green ""([^"]|(\\"))*"" "%[QW]?\{[^}]*\}" "%[QW]?\([^)]*\)" "%[QW]?<[^>]*>" "%[QW]?\[[^]]*\]" "%[QW]?\$[^$]*\$" "%[QW]?\^[^^]*\^" "%[QW]?![^!]*!" ## Expression substitution. These go inside double-quoted strings, ## "like #{this}". color brightgreen "#\{[^}]*\}" ## Strings, single-quoted color green "'([^']|(\\'))*'" "%[qw]\{[^}]*\}" "%[qw]\([^)]*\)" "%[qw]<[^>]*>" "%[qw]\[[^]]*\]" "%[qw]\$[^$]*\$" "%[qw]\^[^^]*\^" "%[qw]![^!]*!" ## Comments color cyan "#[^{].*$" "#$" color brightcyan "##[^{].*$" "##$" ## "Here" docs color green start="<<-?'?EOT'?" end="^EOT" ## Some common markers color brightcyan "(XXX|TODO|FIXME|\?\?\?)" ############################################################################## # # Syntax highlighting for CSS files # # Author: Simon Rupf, simon.rupf(a)int-ag.ch # License: GPL 2 or later # # Version: 2005-02-14 # ############################################################################## syntax "css" "\.css$" color brightred "." color brightyellow start="\{" end="\}" color brightwhite start=":" end="[;^\{]" color brightblue ":active|:focus|:hover|:link|:visited|:link|:after|:before|$" color brightblue start="\/\*" end="\\*/" color green ";|:|\{|\}"
To install, you can either 1) copy and paste the text into the /etc/nanorc file using pico, or 2) download the nanorc file and install it by the command line, first backuping up the old nanorc, and then installing the downloaded nanorc. (Note: you will need the administrative password for your computer.)
sudo mv /etc/nanorc /etc/nanorc.bak sudo mv ~/Downloads/nanorc /etc/nanorc