- [File type abbreviations](#file-type-abbreviations)
- [Help](#help)
- [How to](#how-to)
+ - [cd on quit](#cd-on-quit)
- [Copy current file path to clipboard](#copy-current-file-path-to-clipboard)
- [Change file associations](#change-file-associations)
- [Developers](#developers)
- Removed navigation restriction with relative paths (and let permissions handle it)
- Sort entries by file size (largest to smallest)
- Shortcut to invoke file name copier (set using environment variable `NNN_COPIER`)
+ - Change to last visited directory on quit
#### File association
- Set `NNN_OPENER` to let a desktop opener handle it all. E.g.:
nnn needs libncursesw on Linux (or ncurses on OS X) and standard libc.
-- If you are using Homebrew, run:
+- If you are using **Homebrew**, run:
brew install jarun/nnn/nnn
- Packages are available on
| `^L` | Force a redraw |
| `?` | Toggle help screen |
| `q` | Quit |
+| `Q` | Quit and change directory |
#### Filters
### How to
+#### cd on quit
+
+Pick the appropriate file for your shell from [misc/quitcd](https://github.com/jarun/nnn/tree/master/misc/quitcd) and add the contents to your shell's rc file. You'll need to spawn a new shell for the change to take effect. You should start nnn as `n` (or modify the function name to something else).
+
+As you might notice, nnn uses the environment variable `NNN_TMPFILE` to write the last visited directory path. You can change it.
+
#### Copy current file path to clipboard
nnn can pipe the absolute path of the current file to a copier script. For example, you can use `xsel` on Linux or `pbcopy` on OS X.
struct key bindings[] = {
/* Quit */
{ 'q', SEL_QUIT, "", "" },
+ { 'Q', SEL_CDQUIT, "", "" },
/* Back */
{ KEY_BACKSPACE, SEL_BACK, "", "" },
{ KEY_LEFT, SEL_BACK, "", "" },
--- /dev/null
+export NNN_TMPFILE="/tmp/nnn"
+
+n()
+{
+ nnn -d
+ if [ -f $NNN_TMPFILE ]; then
+ . $NNN_TMPFILE
+ rm $NNN_TMPFILE
+ fi
+}
--- /dev/null
+export NNN_TMPFILE="/tmp/nnn"
+
+function n --description 'support nnn quit and change directory'
+ nnn -d
+ if test -e $NNN_TMPFILE
+ . $NNN_TMPFILE
+ rm $NNN_TMPFILE
+ end
+end
--- /dev/null
+export NNN_TMPFILE="/tmp/nnn"
+
+n()
+{
+ nnn -d
+ if [ -f $NNN_TMPFILE ]; then
+ . $NNN_TMPFILE
+ rm $NNN_TMPFILE
+ fi
+}
Toggle help screen
.It Ic q
Quit
+.It Ic Q
+Quit and change directory
.El
.Pp
Backing up one directory level will set the cursor position at the
and recompiling the code.
.Pp
See the environment and examples sections below for more options and information.
+.Pp
+Configuring
+.Nm
+to change to the last visited directory on quit requires shell integration in a
+few easy steps. Please visit the project page (linked below) for the
+instructions.
.Sh FILTERS
Filters support regexes to display only the matched
entries in the current directory view. This effectively allows
.Pp
If
.Nm
-is invoked as root the default filter will also match hidden
-files.
+is invoked as root the default filter will also match hidden files.
.Sh ENVIRONMENT
The SHELL, EDITOR and PAGER environment variables take precedence
when dealing with the !, e and p commands respectively.
/* Supported actions */
enum action {
SEL_QUIT = 1,
+ SEL_CDQUIT,
SEL_BACK,
SEL_GOIN,
SEL_FLTR,
static size_t fs_free;
static int open_max;
static const double div_2_pow_10 = 1.0 / 1024.0;
-static const char* size_units[] = {"B", "K", "M", "G", "T", "P", "E", "Z", "Y"};
+static const char *size_units[] = {"B", "K", "M", "G", "T", "P", "E", "Z", "Y"};
/*
* Layout:
^K Invoke file name copier\n\
^L Force a redraw\n\
? Toggle help screen\n\
- q Quit\n");
+ q Quit\n\
+ Q Quit and change directory\n");
/* Show exit keys */
printw("\n\n << (?/q)");
nochange:
sel = nextsel(&run, &env);
switch (sel) {
+ case SEL_CDQUIT:
+ {
+ char *tmpfile = getenv("NNN_TMPFILE");
+ if (tmpfile) {
+ FILE *fp = fopen(tmpfile, "w");
+ if (fp) {
+ fprintf(fp, "cd \"%s\"", path);
+ fclose(fp);
+ }
+ }
+ }
case SEL_QUIT:
dentfree(dents);
return;