- [sample scripts](#sample-scripts)
- [change dir color](#change-dir-color)
- [file copy, move, delete](#file-copy-move-delete)
- - [boost chdir prompt](#boost-chdir-prompt)
- [work faster at rename prompt](#work-faster-at-rename-prompt)
- [set idle timeout](#set-idle-timeout)
- [show hot plugged drives](#show-hot-plugged-drives)
#### Dependencies
-`nnn` needs libreadline, libncursesw (on Linux or ncurses on OS X) and standard libc.
+`nnn` needs libncursesw (on Linux or ncurses on OS X) and standard libc.
#### From a package manager
To cook yourself, download the [latest stable release](https://github.com/jarun/nnn/releases/latest) or clone this repository (*risky*). Then install the dependencies and compile (e.g. on Ubuntu 16.04):
- $ sudo apt-get install libncursesw5-dev libreadline6-dev
+ $ sudo apt-get install libncursesw5-dev
$ make
$ sudo make install
In addition, `nnn` integrates with vidir. vidir supports batch file move and delete.
-#### boost chdir prompt
-
-`nnn` uses libreadline for the chdir prompt input. So all the fantastic features of readline (e.g. case insensitive tab completion, history, reverse-i-search) are available to you based on your readline [configuration](https://wiki.archlinux.org/index.php/Readline).
-
#### work faster at rename prompt
The rename prompt supports some bash-like command-line shortcuts - <kbd>^A</kbd>, <kbd>^E</kbd>, <kbd>^U</kbd>. <kbd>^L</kbd> clears the name.
#include <string.h>
#include <time.h>
#include <unistd.h>
-#include <readline/history.h>
-#include <readline/readline.h>
#ifndef __USE_XOPEN_EXTENDED
#define __USE_XOPEN_EXTENDED 1
#endif
return c;
}
-/* Trim all whitespace from both ends, / from end */
-static char *
-strstrip(char *s)
-{
- if (!s || !*s)
- return s;
-
- size_t len = strlen(s) - 1;
-
- while (len != 0 && (isspace(s[len]) || s[len] == '/'))
- --len;
- s[len + 1] = '\0';
-
- while (*s && isspace(*s))
- ++s;
-
- return s;
-}
-
static char *
getmime(const char *file)
{
break;
case SEL_CD:
{
- char *input;
- int truecd;
-
- /* Save the program start dir */
- tmp = getcwd(newpath, PATH_MAX);
- if (tmp == NULL) {
- printwarn();
- goto nochange;
- }
-
- /* Switch to current path for readline(3) */
- if (chdir(path) == -1) {
- printwarn();
- goto nochange;
- }
+ int truecd = 0;
- exitcurses();
- tmp = readline("cd: ");
- refresh();
-
- /* Change back to program start dir */
- if (chdir(newpath) == -1)
- printwarn();
-
- if (tmp[0] == '\0')
- break;
-
- /* Add to readline(3) history */
- add_history(tmp);
-
- input = tmp;
- tmp = strstrip(tmp);
- if (tmp[0] == '\0') {
- free(input);
+ tmp = xreadline(NULL, "cd: ");
+ if (tmp == NULL || tmp[0] == '\0')
break;
- }
-
- truecd = 0;
if (tmp[0] == '~') {
/* Expand ~ to HOME absolute path */
if (home)
snprintf(newpath, PATH_MAX, "%s%s", home, tmp + 1);
else {
- free(input);
printmsg(messages[STR_NOHOME_ID]);
goto nochange;
}
} else if (tmp[0] == '-' && tmp[1] == '\0') {
- if (lastdir[0] == '\0') {
- free(input);
+ if (lastdir[0] == '\0')
break;
- }
/* Switch to last visited dir */
xstrlcpy(newpath, lastdir, PATH_MAX);
truecd = 1;
} else if ((r = all_dots(tmp))) {
- if (r == 1) {
+ if (r == 1)
/* Always in the current dir */
- free(input);
break;
- }
/* Show a message if already at / */
if (istopdir(path)) {
- free(input);
-
/* Continue in navigate-as-you-type mode, if enabled */
if (cfg.filtermode)
presel = FILTER;
dir = xdirname(dir);
if (access(dir, R_OK) == -1) {
printwarn();
- free(input);
goto nochange;
}
}
} else
mkpath(path, tmp, newpath, PATH_MAX);
- free(input);
-
if (!xdiraccess(newpath))
goto nochange;