- [How to](#how-to)
- [add bookmarks](#add-bookmarks)
- [copy file paths](#copy-file-paths)
+ - [selection shortcuts](#selection-shortcuts)
+ - [default copy](#default-copy)
- [to clipboard](#to-clipboard)
- - [when X is missing](#when-x-is-missing)
- [copy, move, delete files](#copy-move-delete-files)
- [cd on quit](#cd-on-quit)
- [run custom scripts](#run-custom-scripts)
- Batch rename/move/delete current directory entries in vidir (from moreutils)
- Spawn SHELL (fallback sh) in the current directory
- Run custom scripts in the current directory
- - Copy absolute file paths with/without X (*easy* shell integration)
+ - Copy absolute file paths with quotes
- Change directory at exit (*easy* shell integration)
- Open any file in EDITOR (fallback vi) or PAGER (fallback less)
- Open current directory in a custom GUI file manager
### Quickstart
1. Install the [utilities required](#file-handling) for your regular activities.
-2. Configure file path copy [using X clipboard](#to-clipboard) or [without X](#when-x-is-missing).
-3. Configure [cd on quit](#cd-on-quit).
-4. Optionally open all text files in EDITOR (fallback vi):
+2. Configure [cd on quit](#cd-on-quit).
+3. Optionally open all text files in EDITOR (fallback vi):
export NNN_USE_EDITOR=1
-5. Run `n`.
-6. Press <kbd>?</kbd> for help on keyboard shortcuts anytime.
-7. For additional functionality [setup custom scripts](#run-custom-scripts).
+4. Run `n`.
+5. Press <kbd>?</kbd> for help on keyboard shortcuts anytime.
+6. For additional functionality [setup custom scripts](#run-custom-scripts).
### How to
#### copy file paths
-File paths can be copied to the clipboard or to a specific temporary file (if X is unavailable, for example). When in multi-copy mode, currently copied file paths can be listed by pressing `y`.
-
-##### to clipboard
-
-`nnn` can pipe the absolute path of the current file or multiple files to a copier script. For example, you can use `xsel` on Linux or `pbcopy` on OS X.
-
-Sample Linux copier script:
-
- #!/bin/sh
-
- # comment the next line to convert newlines to spaces
- IFS=
-
- echo -n $1 | xsel --clipboard --input
-
-export `NNN_COPIER`:
-
- export NNN_COPIER="/path/to/copier.sh"
+##### selection shortcuts
Use <kbd>^K</kbd> to copy the absolute path (from `/`) of the file under the cursor to clipboard.
- select multiple files one by one by pressing <kbd>^K</kbd> on each entry; or,
- navigate to another file in the same directory to select a range of files.
+- list the currently copied file paths by pressing `y`.
Pressing <kbd>^Y</kbd> again copies the paths to clipboard and exits the multi-copy mode.
Note that the filename is not escaped. So copying may still fail for filenames having quote(s) in them.
-##### when X is missing
+##### default copy
-A very common scenario on headless remote servers connected via SSH. As the clipboard is missing, `nnn` copies the path names to the tmp file `DIR/.nnncp`, where `DIR` (by priority) is:
+By default file paths are copied to the temporary file `DIR/.nnncp`, where `DIR` (by priority) is:
$HOME or,
$TMPDIR or,
/tmp
-`nnn` needs to know X is unavailable:
-
- export NNN_NO_X=1
-
-To see the path to the copy file, run `nnn`, press `?` and look up `NNN_NO_X`.
-
-Note: despite the name of the environment variable, this method works even if X is available.
+To see the path to the temporary copy file, run `nnn`, press `?` and look up `copy file`.
Use <kbd>^Y</kbd> and/or <kbd>^K</kbd> to copy file paths as usual. To use the copied paths from the cmdline, use command substitution. For example, if `DIR` above is `/home/user`:
mv (ncp) .
rm (ncp) -rf
-Note that you may want to keep quotes disabled in this case.
+Note that you may want to keep quotes disabled (as it is by default) in this case.
+
+##### to clipboard
+
+`nnn` can pipe the absolute path of the current file or multiple files to a copier script. For example, you can use `xsel` on Linux or `pbcopy` on OS X.
+
+Sample Linux copier script:
+
+ #!/bin/sh
+
+ # comment the next line to convert newlines to spaces
+ IFS=
+
+ echo -n $1 | xsel --clipboard --input
+
+export `NNN_COPIER`:
+
+ export NNN_COPIER="/path/to/copier.sh"
#### copy, move, delete files
/* Settings */
typedef struct {
- uint filtermode : 1; /* Set to enter filter mode */
- uint mtimeorder : 1; /* Set to sort by time modified */
- uint sizeorder : 1; /* Set to sort by file size */
- uint apparentsz : 1; /* Set to sort by apparent size (disk usage) */
- uint blkorder : 1; /* Set to sort by blocks used (disk usage) */
- uint showhidden : 1; /* Set to show hidden files */
- uint copymode : 1; /* Set when copying files */
- uint autoselect : 1; /* Auto-select dir in nav-as-you-type mode */
- uint showdetail : 1; /* Clear to show fewer file info */
- uint showcolor : 1; /* Set to show dirs in blue */
- uint dircolor : 1; /* Current status of dir color */
- uint metaviewer : 1; /* Index of metadata viewer in utils[] */
- uint quote : 1; /* Copy paths within quotes */
- uint noxdisplay : 1; /* X11 is not available */
- uint color : 3; /* Color code for directories */
- uint reserved : 15;
+ ushort filtermode : 1; /* Set to enter filter mode */
+ ushort mtimeorder : 1; /* Set to sort by time modified */
+ ushort sizeorder : 1; /* Set to sort by file size */
+ ushort apparentsz : 1; /* Set to sort by apparent size (disk usage) */
+ ushort blkorder : 1; /* Set to sort by blocks used (disk usage) */
+ ushort showhidden : 1; /* Set to show hidden files */
+ ushort copymode : 1; /* Set when copying files */
+ ushort autoselect : 1; /* Auto-select dir in nav-as-you-type mode */
+ ushort showdetail : 1; /* Clear to show fewer file info */
+ ushort showcolor : 1; /* Set to show dirs in blue */
+ ushort dircolor : 1; /* Current status of dir color */
+ ushort metaviewer : 1; /* Index of metadata viewer in utils[] */
+ ushort quote : 1; /* Copy paths within quotes */
+ ushort color : 3; /* Color code for directories */
} settings;
/* GLOBALS */
/* Configuration */
-static settings cfg = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 4, 0};
+static settings cfg = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 4};
static struct entry *dents;
static char *pnamebuf, *pcopybuf;
{
exitcurses();
fprintf(stderr, "line %d: (%d) %s\n", linenum, errno, strerror(errno));
- if (cfg.noxdisplay && g_cppath[0])
+ if (g_cppath[0])
unlink(g_cppath);
exit(1);
}
/* Writes buflen char(s) from buf to a file */
static void writecp(const char *buf, const size_t buflen)
{
- if (!g_cppath[0])
+ if (!g_cppath[0]) {
+ printmsg(messages[STR_COPY_ID]);
return;
+ }
FILE *fp = fopen(g_cppath, "w");
dprintf(fd, "NNN_IDLE_TIMEOUT: %d secs\n", idletimeout);
if (copier)
dprintf(fd, "NNN_COPIER: %s\n", copier);
- if (getenv("NNN_NO_X"))
- dprintf(fd, "NNN_NO_X: %s (%s)\n", getenv("NNN_NO_X"), g_cppath);
+ else if (g_cppath[0])
+ dprintf(fd, "copy file: %s\n", g_cppath);
if (getenv("NNN_SCRIPT"))
dprintf(fd, "NNN_SCRIPT: %s\n", getenv("NNN_SCRIPT"));
if (getenv("NNN_MULTISCRIPT"))
copycurname();
goto begin;
case SEL_COPY:
- if (!(cfg.noxdisplay || copier)) {
- printmsg(messages[STR_COPY_ID]);
- goto nochange;
- }
-
if (!ndents)
goto nochange;
g_buf[r] = '\'';
g_buf[r + 1] = '\0';
- if (cfg.noxdisplay)
+ if (!copier)
writecp(g_buf, r + 1); /* Truncate NULL from end */
else
spawn(copier, g_buf, NULL, NULL, F_NOTRACE);
printmsg(g_buf + 1);
} else {
r = mkpath(path, dents[cur].name, newpath, PATH_MAX);
- if (cfg.noxdisplay)
+ if (!copier)
writecp(newpath, r - 1); /* Truncate NULL from end */
else
spawn(copier, newpath, NULL, NULL, F_NOTRACE);
}
goto nochange;
case SEL_COPYMUL:
- if (!(cfg.noxdisplay || copier)) {
- printmsg(messages[STR_COPY_ID]);
- goto nochange;
- }
-
if (!ndents)
goto nochange;
}
if (copybufpos) { /* File path(s) written to the buffer */
- if (cfg.noxdisplay)
+ if (!copier)
writecp(pcopybuf, copybufpos - 1); /* Truncate NULL from end */
else
spawn(copier, pcopybuf, NULL, NULL, F_NOTRACE);
g_tmpfplen = xstrlcpy(g_tmpfpath, "/tmp", MAX_HOME_LEN);
/* Check if X11 is available */
- if (!copier && g_tmpfplen && getenv("NNN_NO_X")) {
- cfg.noxdisplay = 1;
+ if (!copier && g_tmpfplen) {
xstrlcpy(g_cppath, g_tmpfpath, MAX_HOME_LEN);
xstrlcpy(g_cppath + g_tmpfplen - 1, "/.nnncp", MAX_HOME_LEN - g_tmpfplen);
}
browse(ipath, ifilter);
exitcurses();
- if (cfg.noxdisplay && g_cppath[0])
+ if (g_cppath[0])
unlink(g_cppath);
#ifdef LINUX_INOTIFY