Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install Nano Editor v4.0 (with syntax highlighting) on the Mac
#!/bin/bash
# Install Nano Editor (https://www.nano-editor.org) with syntax highlighting on the Mac
# Version 4.0 ("Thy Rope of Sands") released March 24th 2019
cd ~/
wget https://www.nano-editor.org/dist/v4/nano-4.0.tar.gz
tar -xvf nano-4.0.tar.gz
mv nano-4.0 .nano
cd .nano/
./configure
make
sudo make install
touch ~/.nanorc
cat > "~/.nanorc" <<EOF
# Enable syntax highlighting in Nano
include ~/.nano/syntax/*.nanorc
EOF
exit
@fevangelou

This comment has been minimized.

Copy link
Owner Author

commented Mar 24, 2019

Hint: "wget" can be easily installed with "brew install wget" if you have Homebrew installed on your Mac.

Screenshot (editing .js file): https://jmp.sh/0VG9K9A

@fevangelou

This comment has been minimized.

Copy link
Owner Author

commented Mar 24, 2019

More syntax highlighting options can be found here: https://github.com/scopatz/nanorc

You can create a folder called "syntax_improved" inside ~./nano/ and copy all .nanorc files there, then simply extend your .nanorc file to read these new definitions as well with:

include ~/.nano/syntax_improved/*.nanorc
@centminmod

This comment has been minimized.

Copy link

commented Mar 24, 2019

nice or just git clone the lot (syntax highlighting) :)

  mkdir -p ~/.nano
  cd ~/.nano
  git clone --depth=1 https://github.com/scopatz/nanorc syntax_improved
  echo 'include ~/.nano/syntax_improved/*.nanorc' > ~/.nanorc
@arthurdapaz

This comment has been minimized.

Copy link

commented Apr 5, 2019

Nice! (Updated: April/16/2019)

Just merged all of your solutions and tips on a single-updated script, also, it doesn't require wget nor brew to be used... Since I made it partially variable-oriented, on future nano versions we will be able to re-use this script...

#!/usr/bin/env bash

# Install Nano (www.nano-editor.org) with syntax highlighting (MacOS)

VERSION="4.1"
NANO_SHORT="nano-$VERSION"
NANO_SRC="$NANO_SHORT.tar.gz"
NANO_URL="https://www.nano-editor.org/dist/v4"
NANO_EXTRA="https://github.com/scopatz/nanorc"

cd ~/
curl -Ok $NANO_URL/$NANO_SRC
tar -zxvf $NANO_SRC

mv $NANO_SHORT .nano && cd .nano/
./configure && make && sudo make install

git clone --depth=1 $NANO_EXTRA syntax_improved
cd ~/ && touch .nanorc

cat > .nanorc <<EOF
include ~/.nano/syntax/*.nanorc
include ~/.nano/syntax_improved/*.nanorc
EOF

rm -vf $NANO_SRC
printf "\nExit terminal and reopen to start using $NANO_SHORT\nTo uninstall it and revert to old:\ncd ~/.nano && sudo make clean uninstall && rm -rf ~/.nano\n"
exit

Updated:

  • Cleaned up the code
  • Using best practices for bash variables (uppercase)
  • Changed to latest version (4.1)
  • Tested on MacOS Mojave 10.14.* (including a hackintosh)
  • Tested on bash v3.* to v5.*
@fevangelou

This comment has been minimized.

Copy link
Owner Author

commented Apr 5, 2019

@arthurdapaz Cool, now it's compatible with both Mac and Linux variants.

@a3igner

This comment has been minimized.

Copy link

commented Apr 10, 2019

@arthurdapaz
i tried your script i get this error:

Error in /Users/andreas/.nanorc on line 2: Error reading ~/.nano/syntax/*.nanorc: No such file or directory

Error in /Users/andreas/.nanorc on line 3: Error reading ~/.nano/syntax_improved/*.nanorc: No such file or directory

even though the directories and files are there.

I changed the order of the way the PATHs are loaded in /etc/paths to load /usr/local/bin before /usr/bin so that the brew version of nano gets loaded before the default OSX version of nano in /usr/bin gets loaded! that fixes that error and it works perfectly now!

@Jvp2001

This comment has been minimized.

Copy link

commented Jun 12, 2019

Thank you very much for this extremely useful script. @arthurdapz

@terasakisatoshi

This comment has been minimized.

Copy link

commented Jul 5, 2019

@arthurdapaz
Thank you. it works fine for VERSION="4.3".

I also got error as @a3igner reported.

Error in /Users/andreas/.nanorc on line 2: Error reading ~/.nano/syntax/*.nanorc: No such file or directory
Error in /Users/andreas/.nanorc on line 3: Error reading ~/.nano/syntax_improved/*.nanorc: No such file or directory

My prescription is set alias nano at ~/.bash_profile

alias nano="/usr/local/bin/nano"

It's good to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.