mirror of
https://github.com/jarun/nnn.git
synced 2024-11-01 00:47:18 +00:00
Allow creating a new file on startup
An accessibe parent directory must exist to allow creation
This commit is contained in:
parent
2a673b4eb1
commit
28ea6e0f36
9
nnn.1
9
nnn.1
|
@ -29,9 +29,14 @@ subshell spawning and much more. It remains a simple and
|
||||||
efficient file manager that stays out of your way.
|
efficient file manager that stays out of your way.
|
||||||
.Pp
|
.Pp
|
||||||
.Nm
|
.Nm
|
||||||
opens the current working directory by default if
|
opens the current working directory if
|
||||||
.Ar PATH
|
.Ar PATH
|
||||||
is not specified.
|
is not specified. If the
|
||||||
|
.Ar PATH
|
||||||
|
doesn't exist,
|
||||||
|
.Nm
|
||||||
|
will prompt to create a new regular file. If the parent directory
|
||||||
|
is specified, it must exist and be accessible.
|
||||||
.Sh KEYBINDS
|
.Sh KEYBINDS
|
||||||
.Pp
|
.Pp
|
||||||
Press
|
Press
|
||||||
|
|
25
src/nnn.c
25
src/nnn.c
|
@ -195,6 +195,7 @@
|
||||||
#define LIST_INPUT_MAX ((size_t)LIST_FILES_MAX * PATH_MAX)
|
#define LIST_INPUT_MAX ((size_t)LIST_FILES_MAX * PATH_MAX)
|
||||||
#define SCROLLOFF 3
|
#define SCROLLOFF 3
|
||||||
#define COLOR_256 256
|
#define COLOR_256 256
|
||||||
|
#define CREATE_NEW_KEY 0xFFFFFFFF
|
||||||
|
|
||||||
/* Time intervals */
|
/* Time intervals */
|
||||||
#define DBLCLK_INTERVAL_NS (400000000)
|
#define DBLCLK_INTERVAL_NS (400000000)
|
||||||
|
@ -6616,7 +6617,7 @@ static bool browse(char *ipath, const char *session, int pkey)
|
||||||
|
|
||||||
newpath[0] = runfile[0] = '\0';
|
newpath[0] = runfile[0] = '\0';
|
||||||
|
|
||||||
presel = pkey ? ';' : ((cfg.filtermode
|
presel = pkey ? ((pkey == CREATE_NEW_KEY) ? 'n' : ';') : ((cfg.filtermode
|
||||||
|| (session && (g_ctx[cfg.curctx].c_fltr[0] == FILTER
|
|| (session && (g_ctx[cfg.curctx].c_fltr[0] == FILTER
|
||||||
|| g_ctx[cfg.curctx].c_fltr[0] == RFILTER)
|
|| g_ctx[cfg.curctx].c_fltr[0] == RFILTER)
|
||||||
&& g_ctx[cfg.curctx].c_fltr[1])) ? FILTER : 0);
|
&& g_ctx[cfg.curctx].c_fltr[1])) ? FILTER : 0);
|
||||||
|
@ -7534,9 +7535,17 @@ nochange:
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case SEL_NEW:
|
case SEL_NEW:
|
||||||
|
if (!pkey) {
|
||||||
r = get_input(messages[MSG_NEW_OPTS]);
|
r = get_input(messages[MSG_NEW_OPTS]);
|
||||||
|
tmp = NULL;
|
||||||
|
} else {
|
||||||
|
r = 'f';
|
||||||
|
tmp = g_ctx[0].c_name;
|
||||||
|
pkey = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
if (r == 'f' || r == 'd')
|
if (r == 'f' || r == 'd')
|
||||||
tmp = xreadline(NULL, messages[MSG_NEW_PATH]);
|
tmp = xreadline(tmp, messages[MSG_NEW_PATH]);
|
||||||
else if (r == 's' || r == 'h')
|
else if (r == 's' || r == 'h')
|
||||||
tmp = xreadline(nselected == 1 ? xbasename(pselbuf) : NULL,
|
tmp = xreadline(nselected == 1 ? xbasename(pselbuf) : NULL,
|
||||||
messages[nselected <= 1?MSG_NEW_PATH:MSG_LINK_PREFIX]);
|
messages[nselected <= 1?MSG_NEW_PATH:MSG_LINK_PREFIX]);
|
||||||
|
@ -8583,11 +8592,17 @@ int main(int argc, char *argv[])
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
|
||||||
if (stat(initpath, &sb) == -1) {
|
if (stat(initpath, &sb) == -1) {
|
||||||
xerror();
|
arg = xbasename(initpath);
|
||||||
|
if (arg != initpath) { /* We have a directory */
|
||||||
|
if (!xdiraccess(xdirname(initpath))) {
|
||||||
|
xerror(); /* Fail non-existent/inaccessible directory */
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
*--arg = '/'; /* Restore the complete path */
|
||||||
if (!S_ISDIR(sb.st_mode))
|
}
|
||||||
|
pkey = CREATE_NEW_KEY; /* Override plugin key */
|
||||||
|
g_state.initfile = 1;
|
||||||
|
} else if (!S_ISDIR(sb.st_mode))
|
||||||
g_state.initfile = 1;
|
g_state.initfile = 1;
|
||||||
|
|
||||||
if (session)
|
if (session)
|
||||||
|
|
Loading…
Reference in a new issue