Micro text editor

Hi!

Recently I found awesome text editor called micro.
After some time of using it want to say Goodbye to vim and nano.
There is any way to run it under OpenWRT?

1 Like

I would prefer micro to other editors if it works on openwrt. Is there any progress in this direction?

The big problem of micro is the size. Compared to vim, nano or even the integrated editor in mc, it is huge!
Anyway, I am sure there are ways to make it smaller. It would be a matter of time until someone makes a tiny version of micro editor for embedded systems.

You don't need a package to use micro if your router has a standard processor architecture.

For instance for the E8450 (ARM64 architecture), I just download the file into /usr/bin using the command in my router:

wget https://github.com/zyedidia/micro/releases/download/v2.0.10/micro-2.0.10-linux-
arm64.tar.gz -qO- |tar xz && mv ./*/micro /usr/bin

If your router uses a different architecture, golang compiler can quickly generate code for linux in these architectures: 386,amd64,arm,arm64,ppc64,ppc64le,mips,mipsle,mips64 and mips64le.
Just install the golang compiler (go version over 1.16) and do something like this in your build PC:

git clone https://github.com/zyedidia/micro
cd micro
GOOS=linux GOARCH=mips make build
sudo apt install upx
upx --lzma --best micro
scp micro root@192.168.1.1:/usr/bin

Obviously use the GOARCH according yo your router's architecture and use the right IP of your router for the scp command.

Please note that the size of the optimized binary is around 2.6MB!!!! so, micro is not by any means a small program, and can only be an option for routers with enough storage. Just check your available storage in your router.

regarding the size, there are ways to optimize it. I use UPX as it is more efficient than the gzip-like algorithm squashfs uses.

3 Likes

By the way, there is another way of having a modern CLI text editor in OpenWrt. Instead of using the nano package, use the package nano-plus. It allows for extra configuration features while keeping a tiny footprint.

With this new plus version we can customize it using the ~/.nanorc config file. If you create it with the following configuration, then you won't miss the micro editor:

bind ^X cut main        # CTRL+X - Cut
bind ^C copy main       # CTRC+C - Copy
bind ^V paste all       # CTRL+V - Past
bind ^Q exit all        # CTRL+Q - Quit program
bind ^S savefile main   # CTRL+S - Save
bind ^Z undo all        # CTRL+Z - Undo
bind ^Y redo all        # CTRL+Y - Redo
bind ^H replace main    # CTRL+H - Replace
bind ^F whereis main    # CTRL+F - Find
bind F3 findnext main   # F3     - Find next
#bind ^/ comment main    # CTRL+/ - Comment

set atblanks            # don't cut words when doing line wrap.
set nohelp              # don't display help messages
set softwrap            # don't break lines
set suspend             # don't suspend the shell
set tabsize 4           # tab stops every 4 spaces
set tabstospaces        # convert tabs to spaces
set constantshow        # show constants
set linenumbers         # show line numbers Alt+N to toggle
set casesensitive       # case sensitive
set zap                 # zap to the end of the line
set autoindent          # auto indent
set indicator           # show the cursor position
set minibar             # show the minibar
set nonewlines          # don't insert newlines
#set backup              # don't make backups
#set backupdir "/tmp"    # where to put the backups

include /usr/share/nano/*
1 Like

Does nano-plus support syntax highlighting?

The standard nano-plus doesn't support it, but with a small patch it can generate a nano-plusplus. The ipk of this nano++ package is 156 KB, so it could be used in any device with small size. It is about 49 KB more than the standard nano-plus.
This is how it looks using SSH:

And this is using the integrated TTY:

And it highlights these languages:
autoconf elisp java nanohelp php tcl awk email javascript nanorc po tex c json nftables python texinfo changelog go lua objc ruby xml cmake groff makefile ocaml rust yaml css guile man patch sh ada fortran haskell povray spec.

Who needs a 10 MB micro editor when nano can do pretty much the same with a 156 KB package?

Hmm, I guess I could give it a try. Where to get and how to apply this patch? By the way, will the syntax highlighting work for .conf files?

Sure, just use this conf.nanorc file and place it into /usr/share/nano/

syntax "\conf$" "conf" "bash_profile" "bash_history" "\rc$" "(\.|/|)control$" "(\.(repo|conf|config|cfg|cnf|rc|lst|list|defs|ini|desktop|mime|types|preset|cache|seat|service|htaccess)$|(^|/)(\w*crontab|mirrorlist|group|hosts|passwd|rpc|netconfig|shadow|fstab|inittab|inputrc|protocols|sudoers)$|conf.d/|.config/|config/)"


# default text
color white "^.*$"

# special values
icolor brightblue "(^|\s|=)(default|true|false|on|off|yes|no)(\s|$)"

# keys
icolor cyan "^\s*(set\s+)?[A-Z0-9_\/\.\%\@+-]+\s*([:]|\>)"

# commands
color blue "^\s*set\s+\<"

# punctuation
color blue "[.]"

# numbers
color red "(^|\s|[[/:|<>(){}=,]|\])[-+]?[0-9](\.?[0-9])*%?($|\>)"

# keys
icolor cyan "^\s*(\$if )?([A-Z0-9_\/\.\%\@+-]|\s)+="

# punctuation
color blue "/"
color brightwhite "(\]|[()<>[{},;:=])"
color brightwhite "(^|\[|\{|\:)\s*-(\s|$)"

# section headings
icolor brightyellow "^\s*(\[([A-Z0-9_\.-]|\s)+\])+\s*$"
color brightcyan "^\s*((Sub)?Section\s*(=|\>)|End(Sub)?Section\s*$)"
color brightcyan "^\s*\$(end)?if(\s|$)"

# URLs
icolor green "\b(([A-Z]+://|www[.])[A-Z0-9/:#?&$=_\.\-]+)(\b|$| )"

# XML-like tags
icolor brightcyan "</?\w+((\s*\w+\s*=)?\s*("[^"]*"|'[^']*'|!?[A-Z0-9_:/]))*(\s*/)?>"

color green "\<(break|case|continue|do|done|elif|else|esac|exit|fi|for|function|if|in|read|return|select|shift|then|time|until|while)\>"
color green "\<(declare|eval|exec|export|let|local)\>"
color green "[{}():;|`$<>!=&\\]" "(\]|\[)"
color green "-[Ldefgruwx]\>"
color green "-(eq|ne|gt|lt|ge|le|s|n|z)\>"
color brightblue "\<(awk|cat|cd|ch(grp|mod|own)|cp|echo|env|grep|install|ln|make|mkdir|mv|popd|printf|pushd|rm|rmdir|sed|set|tar|touch|umask|unset)\>"

# Basic variable names (no braces).
color brightred "\$[-0-9@*#?$!]" "\$[[:alpha:]_][[:alnum:]_]*"
# More complicated variable names; handles braces and replacements and arrays.
color brightred "\$\{[#!]?([-@*#?$!]|[0-9]+|[[:alpha:]_][[:alnum:]_]*)(\[([[:space:]]*[[:alnum:]_]+[[:space:]]*|@)\])?(([#%/]|:?[-=?+])[^}]*\}|\[|\})"

# Comments.
color brightblack "(^|[[:space:]])#.*$"

# Strings.
color brightyellow ""(\\.|[^"])*"" "'(\\.|[^'])*'"

# Trailing whitespace.
color ,green "[[:space:]]+$"

A full featured nano-full package doesn't exsist yet, but it is in the oven. You can build it yourself by modifying the Makefile of the nano package, and then build the image. The details on the nano-full package are being discussed here too:

For the instructions on how to install the full version with all the features enabled, I have posted the instructions here:

1 Like