nano Syndicate content

» Git commit message highlighting in nano

Sat, 11/24/2012 - 16:07

For those who use nano as their CLI editor of choice: Here’s a syntax highlighting file for Git commit messages which also supports the special KDE commit hook keywords.

  1. ## syntax highlighting for git commit messages of KDE projects
  2. syntax "patch" ".git/COMMIT_EDITMSG$"
  3.  
  4. # overlong lines
  5. color brightred "^.{70,}.+$"
  6.  
  7. # KDE commit hook keywords, see: http://community.kde.org/Sysadmin/GitKdeOrgManual#Commit_hook_keywords
  8. color yellow "^(FEATURE|BUG|CCBUG|FIXED-IN|CCMAIL|REVIEW|GUI|DIGEST):.*$"
  9. color yellow "(SVN_SILENT|GIT_SILENT|SVN_MERGE)"
  10.  
  11. # comment
  12. color blue "^#.*$"
  13.  
  14. # special comment lines
  15. color green "^# Changes to be committed:"
  16. color red "^# Changes not staged for commit:"
  17. color brightblue "^# Untracked files:"
  18. color brightblue "^# On branch .+$"
  19. color brightblue "^# Your branch is ahead of .+$"
  20.  
  21. # diff files
  22. # meh - cannot match against \t ... should be: ^#\t.*$
  23. color cyan "^#[^ a-zA-Z0-9][^ ].*$"

Just put this file as gitcommit.nanorc or similar somewhere on your disk and load it from your .nanorc or even /etc/nanorc like this:

  1. include "/path/to/gitcommit.nanorc"
Screenshot of highlighted git commit message
Screenshot of highlighted git commit message

» highlighted APT sources.list in nano

Tue, 04/10/2007 - 18:17

And here another syntax file for Nano. This time it highlights the /etc/apt/sources.list:

  1. ## syntax highlighting for /etc/apt/sources.list
  2.  
  3. syntax "apt/sources.list" "sources\.list(\.old|~)?$"
  4. # component
  5. color brightmagenta "^deb(-src)? ((http|file|ftp):/[^ ]+|cdrom:\[[^\]]+\]/|cdrom:\[[a-zA-Z0-9\._-\(\) ]+\]/) [^ ]+ .+$"
  6. # distribution
  7. color brightred "^deb(-src)? ((http|file|ftp):/[^ ]+|cdrom:\[[^\]]+\]/|cdrom:\[[a-zA-Z0-9\._-\(\) ]+\]/) [^ ]+"
  8. # URI
  9. color brightgreen "(http|file|ftp):/[^ ]+"
  10. # cdroms
  11. # [^\]] does not work…
  12. color brightgreen "cdrom:\[[a-zA-Z0-9\._-\(\) ]+\]/"
  13. # deb / deb-src
  14. color cyan "^deb"
  15. color brightblue "^deb-src"
  16. # comments
  17. color brightyellow "#.*"

» Syntax Highlighting in Nano

Tue, 04/10/2007 - 17:14

When I’m messing around with config files on the command line my editor of choice is Nano. It’s simple, fast and pretty much straight forward. You don’t have to learn any commands and can use keyboard shortcuts just like in GUI programs.

Settings

Today I had a look on the project website and saw that there are tons of settings which I really missed before. Just have a look into your /etc/nanorc for a default config file with all settings and their default values. Here are those I like most:

  • smooth (scrolling)
  • autoindent
  • mouse (though I use it rarely)
  • smarthome
  • tabsize (8 is far to much, I love 4)
Syntax Highlighting

Yes! Nano supports syntax highlighting! And I never knew it, but heck - it’s never to late. Not for neat features like this one, though I really wonder why this is not activated by default…

In the aforementioned /etc/nanorc are already some default languages which just wait to be commented out. You might also want to have a look into /usr/share/nano, there are some languages you can include in your nanorc file with:

include “/usr/share/nano/html.nanorc”

Additionally I found some more languages on the gentoo wiki. And of course I’ll post any homebrew syntax files in my Snippets section.

my syntax highlighting files

» syntax highlighting for *.ini files in nano

Tue, 04/10/2007 - 17:01

Use the snippet below in your ~/.nanorc or /etc/nanorc file to highlight *.ini files like php.ini in Nano.

  1. # ini highlighting
  2. syntax "ini" "\.ini(\.old|~)?$"
  3.  
  4. # values
  5. color brightred "=.*$"
  6. # equal sign
  7. color green "="
  8. # numbers
  9. color brightblue "-?[0-9\.]+\s*($|;)"
  10. # ON/OFF
  11. color brightmagenta "ON|OFF|On|Off|on|off\s*($|;)"
  12. # sections
  13. color brightcyan "^\s*\[.*\]"
  14. # keys
  15. color cyan "^\s*[a-zA-Z0-9_\.]+"
  16. # comments
  17. color brightyellow ";.*$"