Skip to content

Instantly share code, notes, and snippets.

@BlakeGardner
Last active August 18, 2025 18:20
Show Gist options
  • Save BlakeGardner/5587269 to your computer and use it in GitHub Desktop.
Save BlakeGardner/5587269 to your computer and use it in GitHub Desktop.
Syntax highlighting in nano on Mac OS
# Last updated May, 2024 for Apple silicon Macs
# Install Homebrew if you don't already have it: https://brew.sh
# install nano from homebrew
brew install nano nanorc
# update your nanorc file
echo 'include "'"$(brew --cellar nano)"'/*/share/nano/*.nanorc"' >> ~/.nanorc
# close and re-open your terminal and you'll have syntax highlighting
@w601sxs
Copy link

w601sxs commented Jul 23, 2025

as of today, may 13th 2024, the following works without issues on sonoma 14.4.1 with and brew 4.2.21:

brew install nano
echo 'include "'"$(brew --cellar nano)"'/*/share/nano/*.nanorc"' >> ~/.nanorc

thanks everyone for keeping this going :)

+1 thanks @tobsn

@bryan-poulin
Copy link

bryan-poulin commented Aug 18, 2025

As of today, may 13th 2024, the following works without issues on macOS Sequoia 15.6 (24G84) and Homebrew 4.6.4:

brew install nano
echo 'include "'"$(brew --cellar nano)"'/*/share/nano/*.nanorc"' >> ~/.nanorc

@bryan-poulin
Copy link

bryan-poulin commented Aug 18, 2025

Why does every file need to be listed? The following works for me:

brew install nano
echo 'include "/usr/local/share/nano/*.nanorc"' >> ~/.nanorc

The main difference between the two code snippets lies in how they handle the installation and configuration of nano and nanorc using Homebrew on macOS.

Key Differences:

  • Installation of nanorc: The first snippet (@BlakeGardner) explicitly installs nanorc, while the second snippet (@lorthirk) does not. However, nano might still include syntax highlighting files that can be used without the separate nanorc formula.
  • Path Dynamism: The first snippet dynamically finds the path to nano Cellar and includes syntax highlighting files from there. The second snippet uses a fixed path that assumes Homebrew's standard symlink behavior.
  • Flexibility and Portability: The dynamic path approach in the first snippet might be more flexible and resilient to changes in Homebrew's directory structure or nano formula. The fixed path in the second snippet might break if Homebrew changes its symlink structure or if nano formula's installation path changes.

Choosing Between Them

  • Use the first snippet if you want to ensure you're getting the syntax highlighting configurations specifically packaged with nano in a way that's dynamically linked to Homebrew's Cellar structure.
  • Use the second snippet if you're relying on the standard Homebrew symlink structure and want a simpler configuration line, assuming nano includes necessary syntax highlighting files in /usr/local/share/nano/.

Given the current Homebrew structure and nano formula, both approaches should work, but the dynamic path might offer more future-proofing against changes in Homebrew or the formulae.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment