### Install nnn from Source on Ubuntu Source: https://github.com/jarun/nnn/wiki/Usage Installs necessary development packages and then compiles and installs nnn from source. Ensure you have the required dependencies like ncursesw and readline development libraries. ```shell sudo apt-get install pkg-config libncursesw5-dev libreadline-dev sudo make strip install ``` -------------------------------- ### Bash/Zsh Setup Command for NNN Previews Source: https://github.com/jarun/nnn/wiki/Live-previews This function sets up a custom preview command for NNN. It handles nested NNN sessions, configures the NNN_TMPFILE for directory changes on quit, creates a named pipe (NNN_FIFO) for selections, and launches a preview command using either tmux or xterm. Ensure you have `tmux` or `xterm` installed and replace `/path/to/preview_cmd.sh` with your actual preview script. ```shell nnn-preview () { # Block nesting of nnn in subshells if [ -n "$NNNLVL" ] && [ "${NNNLVL:-0}" -ge 1 ]; then echo "nnn is already running" return fi # The default behaviour is to cd on quit (nnn checks if NNN_TMPFILE is set) # If NNN_TMPFILE is set to a custom path, it must be exported for nnn to see. # To cd on quit only on ^G, remove the "export" and set NNN_TMPFILE *exactly* as this: # NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd" export NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd" # This will create a fifo where all nnn selections will be written to NNN_FIFO="$(mktemp --suffix=-nnn -u)" export NNN_FIFO (umask 077; mkfifo "$NNN_FIFO") # Preview command preview_cmd="/path/to/preview_cmd.sh" # Use `tmux` split as preview if [ -e "${TMUX%%,*}" ]; then tmux split-window -e "NNN_FIFO=$NNN_FIFO" -dh "$preview_cmd" # Use `xterm` as a preview window elif (which xterm &> /dev/null); then xterm -e "$preview_cmd" & # Unable to find a program to use as a preview window else echo "unable to open preview, please install tmux or xterm" fi nnn "$@" rm -f "$NNN_FIFO" } ``` -------------------------------- ### Install or Update Plugins Source: https://github.com/jarun/nnn/blob/master/plugins/README.md Installs or updates all available plugins for nnn. Ensure you have a backup before running. ```sh sh -c "$(curl -Ls https://raw.githubusercontent.com/jarun/nnn/master/plugins/getplugs)" ``` -------------------------------- ### SSHFS Mount Examples Source: https://github.com/jarun/nnn/wiki/Basic-use-cases Examples of how to specify remote hosts and paths for mounting using sshfs within NNN. ```shell phone phone:/tmp ``` -------------------------------- ### Example: Archive selected files Source: https://github.com/jarun/nnn/wiki/Concepts Shows how to use the %J variable to pass multiple selected file paths as arguments to tar for archiving. ```sh tar uvf archive.tar %J ``` -------------------------------- ### Install nnn Desktop Entry Source: https://github.com/jarun/nnn/wiki/Advanced-use-cases Install the nnn desktop integration file to make nnn appear in application menus and context menus. This can be done via 'make install-desktop' or by manually copying the file. ```bash make install-desktop ``` -------------------------------- ### Install Pager Dependencies Source: https://github.com/jarun/nnn/wiki/Advanced-use-cases Install necessary packages to support various file types when using a pager as an opener. ```bash antiword - support for word file cabextract - support for cab files cdrkit (cdrtools) - support for iso files fastjar - support for jar files html2text (python-html2text, python2-html2text) - support for html files mediainfo - support for some metadata for media files viu - support for some image file imagemagick - support for some image file p7zip - support for 7za files perl rpmextract - support for rpm files unrar - support for rar files unrtf - support for rtf file unzip - support for zip files source-highlight - support syntax highlighting ``` -------------------------------- ### Install termux-api package Source: https://github.com/jarun/nnn/wiki/Advanced-use-cases Install the termux-api package in Termux to enable API interactions, such as clipboard access. ```bash pkg in termux-api ``` -------------------------------- ### Example: Grep string in selected files Source: https://github.com/jarun/nnn/wiki/Concepts Demonstrates using the %j variable to pass multiple selected file paths as arguments to grep. ```sh printf "Searching for string in %s\n" "%j"; grep "string" "%j" ``` -------------------------------- ### SSHFS Host Configuration Example Source: https://github.com/jarun/nnn/wiki/Basic-use-cases Example SSH client configuration for connecting to a remote host. This file is read by sshfs to establish connections. ```shell Host * ServerAliveInterval 300 ServerAliveCountMax 2 Host phone HostName 192.168.43.1 User u0_a117 Port 8022 Compression no # Ciphers chacha20-poly1305@openssh.com # ProxyJump jumphost ``` -------------------------------- ### Install musl libc for Compilation Source: https://github.com/jarun/nnn/wiki/Developer-guides Install the musl C standard library and related development tools on Ubuntu 20.04. These are required for compiling nnn with musl. ```bash sudo apt install musl musl-dev musl-tools ``` -------------------------------- ### Install Ncurses after Cross-Compilation Source: https://github.com/jarun/nnn/wiki/Developer-guides Install the cross-compiled ncurses library to the specified Android environment prefix. ```bash make && make install ``` -------------------------------- ### Compile and Install nnn on Raspberry Pi Source: https://github.com/jarun/nnn/wiki/Developer-guides Compile the nnn source code and install it to the default system directory (/usr/local/bin). This command requires root privileges. ```bash sudo make strip install ``` -------------------------------- ### i3wm Shortcut for NNN File Manager Source: https://github.com/jarun/nnn/wiki/Advanced-use-cases An example configuration for sxhkd to launch NNN using a keyboard shortcut (Super + n) within an i3 window manager environment. ```shell ## File Manager super + n xfce4-terminal -e "nwrap $*" ``` -------------------------------- ### Install advcpmv-patched binaries Source: https://github.com/jarun/nnn/wiki/Advanced-use-cases Copy the advcpmv-patched binaries to your PATH and rename them to 'cpg' and 'mvg' to enable cp and mv progress monitoring on Linux. ```bash sudo cp src/cp /usr/local/bin/cpg sudo cp src/mv /usr/local/bin/mvg ``` -------------------------------- ### Compile with PCRE2 Support Source: https://github.com/jarun/nnn/wiki/Developer-guides Enable PCRE2 regex support by installing the PCRE2 development library and setting the O_PCRE2 make variable. ```bash make O_PCRE2=1 ``` -------------------------------- ### Install Dependencies for nnn on Raspberry Pi Source: https://github.com/jarun/nnn/wiki/Developer-guides Install the necessary development packages for compiling nnn on Raspbian Buster. This includes pkg-config and ncurses development libraries. ```bash sudo apt install pkg-config libncursesw5-dev libreadline-dev ``` -------------------------------- ### LFTP Help Commands Source: https://github.com/jarun/nnn/wiki/Advanced-use-cases Shows how to access the list of supported commands and get help on a specific command within the LFTP interactive prompt. ```bash lftp :~> ? ``` ```bash lftp :~> help put ``` -------------------------------- ### Static Compilation Source: https://github.com/jarun/nnn/wiki/Developer-guides Compile nnn statically by installing libgpm-dev and setting the O_STATIC=1 make variable. The 'strip' command is used to reduce binary size. ```bash make O_STATIC=1 strip ``` -------------------------------- ### Start Interactive Bash Shell as nnn Plugin Source: https://github.com/jarun/nnn/wiki/Basic-use-cases A simple bash script that can be used as an nnn plugin to start an interactive bash shell. It exports the nnn variable and then executes bash. ```sh #!/usr/bin/env bash # Description: Start an interactive bash shell. export nnn="$1" bash -i ``` -------------------------------- ### Configure cd on Quit for Bash Source: https://github.com/jarun/nnn/wiki/Basic-use-cases Integrate nnn with your shell to automatically change directory to the last working directory upon exiting nnn. This example shows the setup for bash. ```sh nnn_cd() { if ! [ -z "$NNN_PIPE" ]; then printf "%s\0" "0c${PWD}" > "${NNN_PIPE}" !& fi } trap nnn_cd EXIT ``` -------------------------------- ### Run Interactive Bash Shell using Run Cmd Plugin Source: https://github.com/jarun/nnn/wiki/Basic-use-cases An alternative method to start an interactive bash shell using nnn's 'run cmd as plugin' feature. ```sh s:!bash -i* ``` -------------------------------- ### Apply a Patch using Make Variable Source: https://github.com/jarun/nnn/blob/master/patches/README.md To apply a specific patch, use the corresponding make variable with a value of 1 during the compilation process. This example shows how to apply the 'namefirst' patch. ```bash make O_NAMEFIRST=1 ``` -------------------------------- ### Configure Ncurses for Android Cross-Compilation Source: https://github.com/jarun/nnn/wiki/Developer-guides Configure the ncurses library for static linking against Android's arm64 target. Ensure the ANDROID_ENV variable is set to the installation prefix. ```bash ./configure --enable-widec --enable-termcap --with-fallbacks=xterm-256color --disable-stripping --host=aarch64-linux-android --prefix=$ANDROID_ENV ``` -------------------------------- ### Take Quick Notes Source: https://github.com/jarun/nnn/blob/master/plugins/README.md Opens a synced file/directory for taking quick notes in Vim. ```sh n:-!vi /home/user/Dropbox/dir/note* ``` -------------------------------- ### Launch Application with Launch Plugin Source: https://github.com/jarun/nnn/wiki/Basic-use-cases Configure a keybind to open the launch plugin in a terminal. This allows for launching GUI applications using a drop-down menu. ```shell xfce4-terminal -e "${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/launch" ``` -------------------------------- ### Start nnn within tmux Source: https://github.com/jarun/nnn/wiki/Troubleshooting A shell function to start nnn, either directly or by creating a new tmux session. ```bash n () { if [ -n "$TMUX" ]; then nnn -a $@ else tmux -u new-session nnn -a $@ fi } ``` -------------------------------- ### Binary Size and Memory Usage Comparison (UPX) Source: https://github.com/jarun/nnn/wiki/Performance Shows results with aggressive make options, static binary, and UPX compression for nnn. ```text $ make O_NORL=1 O_NOMOUSE=1 O_NOLC=1 O_NOBATCH=1 O_NOSSN=1 O_NOFIFO=1 O_QSORT=1 O_NOUG=1 static strip $ upx nnn-static $ top BINSZ VIRT ** RES** SHR S %MEM COMMAND 582K 3136 ** 3056** 4 S 0.0 nnn-static -cdDEnQrux -t d ~/images // 11K files 582K 2428 ** 2240** 4 S 0.0 nnn-static -cdDEnQrux -t d /usr/bin // 1.5K files ``` -------------------------------- ### Configure Plugin Keybindings Source: https://github.com/jarun/nnn/blob/master/plugins/README.md Assigns keybindings to plugins for quick access. Use the plugin shortcut (;) followed by the assigned key. ```sh export NNN_PLUG='f:finder;o:fzopen;p:mocq;d:diffs;t:nmount;v:imgview' ``` -------------------------------- ### Optimized Static Compilation and Compression Source: https://github.com/jarun/nnn/wiki/Developer-guides Compile nnn with various optimizations and static linking, then compress the binary using upx. This demonstrates a method for achieving a smaller executable size. ```bash $ make CFLAGS+=-march=native O_NORL=1 O_NOMOUSE=1 O_NOLC=1 O_NOBATCH=1 O_NOSSN=1 O_NOFIFO=1 O_QSORT=1 O_NOUG=1 static $ upx nnn-static $ ls -l nnn-static -rwxrwxr-x 1 user user 593808 Nov 2 00:45 nnn-static # top output (/usr/bin has 1544 files) PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 31953 user 20 0 2428 2244 4 S 0.0 0.0 0:00.02 ./nnn-static -cdDEnQrux /usr/bin ``` -------------------------------- ### Quick Find First Match in Subtree and Open in Nuke Source: https://github.com/jarun/nnn/blob/master/plugins/README.md This plugin prompts the user for a file pattern, searches the current directory subtree for the first matching file using `find`, and opens it with the `nuke` utility if found. The `nuke` utility path is configurable via XDG_CONFIG_HOME. ```sh #!/usr/bin/env sh NUKE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/nuke" printf "file name: " read -r pattern entry=$(find . -type f -iname "$pattern" -print -quit 2>/dev/null) if [ -n "$entry" ]; then "$NUKE" "$entry" fi ``` -------------------------------- ### LFTP Command Prompt Usage Source: https://github.com/jarun/nnn/wiki/Advanced-use-cases Demonstrates the sequence of commands to use within the LFTP prompt after connecting to a server, including listing aliases, transferring files, and exiting. ```bash lftp :~> mob lftp :~> lst lftp :~> mv lftp :~> bye ``` -------------------------------- ### Get Last Executed cwd Path in tmux Source: https://github.com/jarun/nnn/wiki/Troubleshooting Retrieve the path from the last executed `cwd` command for nnn within tmux. ```bash lsof -w -c nnn | grep cwd | tail -n 1 | awk '{print $9}' ``` -------------------------------- ### Run GUI App as Plugin Source: https://github.com/jarun/nnn/blob/master/plugins/README.md Launches a GUI application as a plugin. Add an ampersand (&) after the exclamation mark (!). The '-' prefix can still be used to disable directory refresh. ```sh export NNN_PLUG='m:-!&mousepad "$nnn"' ``` -------------------------------- ### Get Current Working Directory in tmux for nnn Source: https://github.com/jarun/nnn/wiki/Troubleshooting Extract the current working directory when nnn is running in tmux, useful for scripting. ```bash lsof -c nnn | grep cwd ``` -------------------------------- ### Compile with Alexey Tourbin's QSORT Source: https://github.com/jarun/nnn/wiki/Developer-guides Enable Alexey Tourbin's QSORT algorithm by setting the O_QSORT make variable to 1. ```bash make O_QSORT=1 ``` -------------------------------- ### Binary Size and Memory Usage Comparison (Vanilla) Source: https://github.com/jarun/nnn/wiki/Performance Compares the stripped binary size and memory usage of nnn against other file managers using GNU libc and ncursesw. ```text BINSZ VIRT ** RES** SHR S %MEM COMMAND 650K 139720 **91220** 8460 S 1.1 ranger 1M 50496 **15328** 4076 S 0.2 vifm 1M 72152 **12468** 7336 S 0.2 mc 110K 15740 ** 4348** 2460 S 0.1 nnn -t d ``` -------------------------------- ### Clear Terminal Line Settings Source: https://github.com/jarun/nnn/wiki/Troubleshooting Clear specific terminal line settings like start, stop, lwrap, and lnext to resolve broken Ctrl-key combinations. ```bash stty start undef stty stop undef stty lwrap undef stty lnext undef ``` -------------------------------- ### Display Help Information Source: https://github.com/jarun/nnn/wiki/Usage Use these commands to display help information for nnn. The `-h` flag shows command-line options, and `man nnn` provides the full manual page. ```sh nnn -h ``` ```sh man nnn ``` -------------------------------- ### Extended Archive Regex for NNN Source: https://github.com/jarun/nnn/wiki/Usage This example shows an extended regular expression for NNN_ARCHIVE, including more archive types like .a, .ace, .alz, etc., and ISO 9660 images. ```bash export NNN_ARCHIVE="\.(7z|a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|rar|rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip)$" ``` -------------------------------- ### Compile nnn with Colemak Keybinds Source: https://github.com/jarun/nnn/wiki/Advanced-use-cases Build nnn with Colemak keybindings enabled using the O_COLEMAK=1 flag. ```bash make O_COLEMAK=1 ``` -------------------------------- ### Open NNN as Root Source: https://github.com/jarun/nnn/wiki/Basic-use-cases Create an alias to open a new instance of NNN with root privileges using 'sudo'. ```shell alias N='sudo -E nnn -dH' ``` -------------------------------- ### Extract and Navigate to nnn Source Directory Source: https://github.com/jarun/nnn/wiki/Developer-guides Extract the nnn source tarball and change into the newly created directory, preparing for compilation. ```bash tar -zxvf nnn-3.5.tar.gz cd nnn-3.5 ``` -------------------------------- ### Set Bookmarks via Environment Variable Source: https://github.com/jarun/nnn/wiki/Basic-use-cases Define bookmarks using the NNN_BMS environment variable. Key-value pairs are separated by semicolons, where the key is a character to trigger the bookmark. ```sh export NNN_BMS="d:$HOME/Documents;u:/home/user/Cam Uploads;D:$HOME/Downloads/" ``` -------------------------------- ### Wrapper Script for nnn Environment Variables Source: https://github.com/jarun/nnn/wiki/Advanced-use-cases Use a wrapper shell script to set necessary environment variables, such as NNN_BMS and NNN_COLORS, before launching nnn. This is useful when the display manager does not source user profile files. ```sh #!/bin/sh # If you use pywal, you need to restore the scheme here # (cat ~/.cache/wal/sequences &) export NNN_BMS="D:$HOME/Downloads;v:$HOME/Videos" export NNN_COLORS="5236" alias nsel="cat ${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection | tr '\0' '\n'" # To use a CLI opener, specify the `-c` option to `nnn` # export NNN_OPENER="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/nuke" nnn ``` -------------------------------- ### Show Git Log Source: https://github.com/jarun/nnn/blob/master/plugins/README.md Displays the git log for the current project. ```sh l:-!git log ``` -------------------------------- ### Directory Listing Time Comparison: nnn vs. ls Source: https://github.com/jarun/nnn/wiki/Performance Compares the time taken by nnn and ls to list the contents of a directory with 2083 files. nnn is shown to be significantly faster. ```bash $ time nnn /usr/bin 0.00user 0.01system 0:00.02elapsed 42%CPU (0avgtext+0avgdata 3540maxresident)k 1608inputs+0outputs (3major+325minor)pagefaults 0swaps ``` ```bash $ export LS_COLORS='ex=00:su=00:sg=00:ca=00:' $ time ls -l /usr/bin 0.01user 0.01system 0:00.05elapsed 47%CPU (0avgtext+0avgdata 3800maxresident)k 784inputs+0outputs (0major+303minor)pagefaults 0swaps ``` -------------------------------- ### Configure Help Page Command Execution in NNN Source: https://github.com/jarun/nnn/wiki/Usage Use NNN_HELP to specify a command and its arguments to be executed and displayed on the help page. This allows for custom help content. ```bash export NNN_HELP='pwy paris' ``` -------------------------------- ### Verify Static Binary Source: https://github.com/jarun/nnn/wiki/Developer-guides Check the file type of the compiled nnn binary to confirm it is statically linked. ```bash file nnn nnn: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.32, BuildID[sha1]=1be54d27687f83cf42393dd59dba2723798956de, stripped ``` -------------------------------- ### Xdg-open Wrapper for Chromium Source: https://github.com/jarun/nnn/wiki/Advanced-use-cases A wrapper script for xdg-open that resets the XDG_CURRENT_DESKTOP environment variable, restoring default behavior within Chromium when needed. ```shell #!/bin/sh XDG_CURRENT_DESKTOP='' /usr/bin/xdg-open "$@" ``` -------------------------------- ### Quick Find using fd Source: https://github.com/jarun/nnn/blob/master/plugins/README.md This plugin utilizes the `fd` command to perform a quick search. It prompts for a pattern, then sends the `fd` command with the pattern to NNN_PIPE. Requires the nnn-plugin-helper script. ```sh #!/usr/bin/env sh . "$(dirname "$0")"/.nnn-plugin-helper printf "pattern: " read -r pattern if [ -n "$pattern" ]; then printf "%s" "+l" > "$NNN_PIPE" eval "fd -HI $pattern -0" > "$NNN_PIPE" fi ``` -------------------------------- ### Compile musl-fts Shared and Static Libraries with musl-gcc Source: https://github.com/jarun/nnn/wiki/Developer-guides Clone the musl-fts repository, bootstrap, configure, and compile both shared and static libraries using musl-gcc. The compiled libraries are then copied to a custom directory. ```bash git clone https://github.com/void-linux/musl-fts --depth=1 cd musl-fts ./bootstrap.sh ./configure make CC=musl-gcc CFLAGS=-O3 LDFLAGS=-static -j$(($(nproc)+1)) sudo cp .libs/libfts.a /opt/nnn-libs/ make clean make CC=musl-gcc CFLAGS=-O3 -j$(($(nproc)+1)) sudo cp .libs/libfts.so.0.0.0 /opt/nnn-libs/libfts.so ``` -------------------------------- ### Make File Executable Source: https://github.com/jarun/nnn/blob/master/plugins/README.md Changes the permissions of the hovered file to make it executable. ```sh x:!chmod +x "$nnn" ``` -------------------------------- ### Organize Plugins into Sections Source: https://github.com/jarun/nnn/blob/master/plugins/README.md Breaks down long plugin lists into manageable sections using separate environment variables. Combine them into NNN_PLUG. ```sh NNN_PLUG_PERSONAL='g:personal/convert2zoom;p:personal/echo' NNN_PLUG_WORK='j:work/prettyjson;d:work/foobar' NNN_PLUG_INLINE='e:!go run "$nnn"* NNN_PLUG_DEFAULT='1:ipinfo;p:preview-tui;o:fzz;b:nbak' NNN_PLUG="$NNN_PLUG_PERSONAL;$NNN_PLUG_WORK;$NNN_PLUG_DEFAULT;$NNN_PLUG_INLINE" export NNN_PLUG ``` -------------------------------- ### Define Key-Bookmark Pairs in NNN Source: https://github.com/jarun/nnn/wiki/Usage Use NNN_BMS to map keys to specific directory paths, enabling quick navigation to frequently used locations. Bookmarks are defined as key:path pairs. ```bash export NNN_BMS="d:$HOME/Documents;D:$HOME/Docs archive/" ``` -------------------------------- ### Configure Custom Opener in NNN Source: https://github.com/jarun/nnn/wiki/Usage Specify a custom program to open files by setting the NNN_OPENER environment variable. This allows for user-defined file handling logic. ```bash export NNN_OPENER="/path/to/custom/opener" ``` -------------------------------- ### Create a Copy of the Hovered File Source: https://github.com/jarun/nnn/blob/master/plugins/README.md Creates a recursive copy of the hovered file. ```sh C:!cp -rv "$nnn" "$nnn".cp ``` -------------------------------- ### Launch Application in Background Source: https://github.com/jarun/nnn/wiki/Basic-use-cases Launch applications from the NNN prompt in the background using '&'. This prevents NNN from being blocked. ```shell application_executable & ``` -------------------------------- ### nnn Keyboard Shortcuts Overview Source: https://github.com/jarun/nnn/wiki/Usage This is a comprehensive list of keyboard shortcuts for nnn, categorized by function. Refer to this for all available commands. ```text NAVIGATION Up k Up PgUp ^U Page up Dn j Down PgDn ^D Page down Lt h Parent ~ ` @ - ~, /, start, prev Ret Rt l Open ' First file/match g ^A Top J Jump to entry/offset G ^E End ^J Toggle auto-advance on open B (,) Book(mark) b ^/ Select bookmark 1-4 Context (Sh)Tab Cycle/new context 2Esc ^Q Quit ^y Next young ^G QuitCD Q Pick/err, quit q Alt+Esc Quit context ^L Refresh dir FILTER & PROMPT / Filter ^N Toggle type-to-nav Esc Exit prompt ^L Toggle last filter . Toggle hidden FILES o ^O Open with... n Create new/link f ^F File details d Detail mode toggle ^R Rename/dup r Batch rename z Archive e Edit file * Toggle exe > Export list Space + (Un)select m-m Select range/clear a Select all A Invert sel p ^P Copy here w ^W Cp/mv sel as v ^V Move here E Edit sel list x ^X Delete or trash S Listed sel size X Delete (rm -rf) Esc Send to FIFO MISC Alt ; Select plugin = Launch app ! ^] Shell ] Cmd prompt c Connect remote u Unmount remote/archive t ^T Sort toggles s Manage session T Set time type 0 Lock ^L Redraw ? Help, conf ``` -------------------------------- ### Compile with Readline Support Source: https://github.com/jarun/nnn/wiki/Developer-guides Enable readline support by setting the O_NORL make variable to 0. ```bash make O_NORL=0 ``` -------------------------------- ### Pick Multiple Files for Mutt Attachment Source: https://github.com/jarun/nnn/wiki/Basic-use-cases Use NNN in file picker mode to select multiple files and pipe their paths as arguments to 'neomutt' for email attachments. ```shell neomutt -a $(nnn -p -) ... ``` -------------------------------- ### Run Arbitrary Commands as Plugins Source: https://github.com/jarun/nnn/blob/master/plugins/README.md Assigns keys to non-background CLI commands. Prefix the command with '!'. Use double quotes for variables like "$nnn". ```sh export NNN_PLUG='x:!chmod +x "$nnn";g:!git log;s:!smplayer "$nnn"' ``` -------------------------------- ### Simplify selection redirection with a variable Source: https://github.com/jarun/nnn/wiki/Power-toys Define a 'sel' variable for the .selection file path to simplify commands that redirect selections to a command. ```shell export sel=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection ``` ```shell xargs -0 ls -l < $sel ``` -------------------------------- ### Show Git Diff Source: https://github.com/jarun/nnn/blob/master/plugins/README.md Displays the git diff for the current project. ```sh g:-!git diff ``` -------------------------------- ### lftp script for file transfer Source: https://github.com/jarun/nnn/wiki/Advanced-use-cases A sample lftp script to automate file transfers to and from a remote server using SFTP. This includes connecting, listing, creating directories, uploading, and downloading files. ```bash # lftp script_file to transfer files to/from a server # server has sshd service running and support scp # open connection open -u user,password -p port sftp://server_ip_address # list files on server ls # create a directory mkdir uploads # upload some files to the directory uploads put -O uploads file1 file2 # download some files to the current directory pget -O downloads file3 file4 ``` -------------------------------- ### Disk Usage Performance Comparison Source: https://github.com/jarun/nnn/wiki/Performance Compares disk usage performance between different commits of nnn. Captured using 'time nnn -T d /'. ```shell time nnn -T d / ``` -------------------------------- ### List files using xargs and the sel variable Source: https://github.com/jarun/nnn/wiki/Concepts Utilize the exported 'sel' variable with xargs to list files from the .selection file. ```shell xargs -0 ls -l < $sel ``` -------------------------------- ### Display Command Output in Floating Window Source: https://github.com/jarun/nnn/blob/master/plugins/README.md Shows the output of run-and-exit commands in a floating window. Add a right arrow (>) after '!'. Ignores '*' and '-' options. ```sh export NNN_PLUG='m:!>mediainfo "$nnn";t:!>tree -ps;l:!>ls -lah --group-directories-first' ``` -------------------------------- ### Configure Pager as Opener Source: https://github.com/jarun/nnn/wiki/Advanced-use-cases Configure your shell to use a custom pager script for opening files, allowing for richer viewing experiences within nnn. ```bash export PAGER=less [ -r "$HOME/git/lesspipe/lesspipe.sh" ] && export LESSOPEN="| $HOME/git/lesspipe/lesspipe.sh %s" export LESS='-Ri ' ``` -------------------------------- ### Compile netbsd-curses Shared and Static Libraries with musl-gcc Source: https://github.com/jarun/nnn/wiki/Developer-guides Clone the netbsd-curses repository, checkout a specific version, and compile both shared and static libraries using musl-gcc. The compiled libraries are then copied to a custom directory. ```bash git clone https://github.com/sabotage-linux/netbsd-curses cd netbsd-curses git checkout v0.3.2 make CC=musl-gcc CFLAGS="-O3 -Wall -fPIC" -j$(($(nproc)+1)) all sudo mkdir /opt/nnn-libs sudo cp libcurses/libcurses.so libterminfo/libterminfo.so /opt/nnn-libs/ make clean make CC=musl-gcc CFLAGS=-O3 LDFLAGS=-static all-static sudo cp libcurses/libcurses.a libterminfo/libterminfo.a /opt/nnn-libs/ ``` -------------------------------- ### Configure Readline for Android Cross-Compilation Source: https://github.com/jarun/nnn/wiki/Developer-guides Configure the readline library for static linking against Android's arm64 target, ensuring it uses ncurses. Ensure the ANDROID_ENV variable is set. ```bash ./configure --enable-multibyte --with-curses --disable-shared --host=aarch64-linux-android --prefix=$ANDROID_ENV ``` -------------------------------- ### Show Git Log with Changes Source: https://github.com/jarun/nnn/blob/master/plugins/README.md Displays the git log with changes for a specific file, useful for quick reviews. ```sh #!/usr/bin/env sh git log -p -- "$1" ``` -------------------------------- ### Browser Wrapper Script for Chromium Source: https://github.com/jarun/nnn/wiki/Advanced-use-cases A script to launch a browser with a specific XDG_CURRENT_DESKTOP environment variable set, forcing it to use the custom kdialog script for file operations. ```shell #!/bin/sh XDG_CURRENT_DESKTOP=KDE "$@" ``` -------------------------------- ### Set Default Application for Mimetypes Source: https://github.com/jarun/nnn/wiki/Troubleshooting Use `xdg-mime` to set default applications for specific mimetypes when using `xdg-open`. ```bash xdg-mime default application mimetype(s) e.g. xdg-mime default sxiv.desktop image/jpeg image/png ``` -------------------------------- ### Quick Grep using rg Source: https://github.com/jarun/nnn/blob/master/plugins/README.md This plugin uses the `rg` (ripgrep) command for quick content searching. It prompts for a pattern and pipes the results (file names) to NNN_PIPE. Requires the nnn-plugin-helper script. ```sh #!/usr/bin/env sh . "$(dirname "$0")"/.nnn-plugin-helper printf "pattern: " read -r pattern if [ -n "$pattern" ]; then printf "%s" "+l" > "$NNN_PIPE" eval "rg -l0 --hidden -S $pattern" > "$NNN_PIPE" fi ``` -------------------------------- ### Make copier script executable and export NNN_COPIER Source: https://github.com/jarun/nnn/wiki/Advanced-use-cases Make the clipboard copier script executable and export the NNN_COPIER environment variable to integrate clipboard functionality in Termux. ```bash chmod +x /path/to/copier export NNN_COPIER="/path/to/copier" ``` -------------------------------- ### Performance Comparison Table Source: https://github.com/jarun/nnn/wiki/Performance Table showing disk usage performance metrics (real, user, sys time) for different nnn commits under uncached and cached conditions. ```text Uncached | `real 0m4.153s`
`user 0m4.320s`
`sys 0m5.455s` | `real 0m3.700s`
`user 0m0.130s`
`sys 0m4.590s` | `real 0m0.748s`
`user 0m0.188s`
`sys 0m6.394s` | Cached | `real 0m0.780s`
`user 0m0.931s`
`sys 0m2.330s` | `real 0m0.577s`
`user 0m0.108s`
`sys 0m1.681s` | `real 0m0.192s`
`user 0m0.170s`
`sys 0m2.414s` | ``` -------------------------------- ### Send Hovered File to X Selection Source: https://github.com/jarun/nnn/blob/master/plugins/README.md This plugin reads files from NNN_FIFO and pipes each file path to xsel, effectively sending it to the X selection buffer. Ensure NNN_FIFO is set. ```sh #!/usr/bin/env sh if [ -z "$NNN_FIFO" ] ; then exit 1 fi while read FILE ; do printf "%s" "$FILE" | xsel done < "$NNN_FIFO" & disown ``` -------------------------------- ### Run custom commands with hotkeys using NNN_PLUG Source: https://github.com/jarun/nnn/wiki/Power-toys Define custom commands or plugins to be executed with hotkeys by setting the NNN_PLUG environment variable. This allows for quick access to frequently used commands. ```shell export NNN_PLUG='l:-_lnav $nnn*' ``` -------------------------------- ### Basic NNN Wrapper Script Source: https://github.com/jarun/nnn/wiki/Advanced-use-cases A simple shell script to wrap NNN, allowing it to be called with arguments and made executable. Useful for adding to PATH. ```shell #!/bin/sh # Start nnn with your preferred options nnn "$@" ``` -------------------------------- ### Check for Key Collisions Source: https://github.com/jarun/nnn/wiki/Advanced-use-cases After customizing keybindings in nnn, compile the program and run 'nnn -K' to detect any key collisions. This helps ensure your custom shortcuts are unique. ```bash nnn -K ``` -------------------------------- ### C Program for Performance Test Source: https://github.com/jarun/nnn/wiki/Performance A simple C program that prints 'hello' one million times. Used to measure execution time against other languages. ```c #include int main(void) { for (int i = 0; i < 1000000; i++) printf("hello\n"); return 0; } ``` -------------------------------- ### Set Binary Options for NNN Source: https://github.com/jarun/nnn/wiki/Usage Use the NNN_OPTS environment variable to pass binary options directly to the nnn executable. These options modify nnn's runtime behavior. ```bash export NNN_OPTS="cEnrx" ``` -------------------------------- ### Open Hovered File in Hex Editor Source: https://github.com/jarun/nnn/blob/master/plugins/README.md Opens the hovered file using the hx hex editor. ```sh h:-!hx "$nnn"* ``` -------------------------------- ### Redirect selected files to a command Source: https://github.com/jarun/nnn/wiki/Power-toys Use the .selection file to pass selected files as input to a command. This allows batch processing of selected files. ```shell xargs -0 ls -l < "${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection" ``` -------------------------------- ### List files from current directory with fd and nnn Source: https://github.com/jarun/nnn/wiki/Concepts Pipe NUL-separated file paths found by 'fd' to nnn for listing. Use -d 1 for current directory only and -S +1M for size. ```shell # fd -d 2 -S +1M -0 | nnn ``` -------------------------------- ### Append Files to MOC Playlist Source: https://github.com/jarun/nnn/wiki/Basic-use-cases Use NNN in file picker mode to select files and append their paths to a MOC playlist. ```shell mocp -a $(nnn -p -) ``` -------------------------------- ### Change Directory Plugin Configuration Source: https://github.com/jarun/nnn/blob/master/plugins/README.md This is a configuration string for an NNN plugin that allows changing the directory. It prompts the user for a full path and writes it to NNN_PIPE if provided. ```shell NNN_PLUG='c:!read -p "full path: " -r to && [ -n "$to" ] && printf "0c%s" "${to}" > "$NNN_PIPE"' ``` -------------------------------- ### Change Directory to Clipboard Content Source: https://github.com/jarun/nnn/blob/master/plugins/README.md Changes the current directory to the path stored in the clipboard, using a helper script. ```sh #!/usr/bin/env sh . $(dirname $0)/.nnn-plugin-helper nn_cd "$(xsel -ob)" ``` -------------------------------- ### Edit File as Root in Vim Source: https://github.com/jarun/nnn/blob/master/plugins/README.md Opens the hovered file for editing with root privileges using Vim. ```sh e:-!sudo -E vim "$nnn"* ```