mirror of
https://github.com/jarun/nnn.git
synced 2024-09-11 13:06:14 +03:00
Attmept to create PATH if PATH is non-existent
This commit is contained in:
parent
93de728eab
commit
d4c3e52f2f
17
nnn.1
17
nnn.1
@ -31,12 +31,21 @@ efficient file manager that stays out of your way.
|
|||||||
.Nm
|
.Nm
|
||||||
opens the current working directory if
|
opens the current working directory if
|
||||||
.Ar PATH
|
.Ar PATH
|
||||||
is not specified. If the
|
is not specified. If
|
||||||
.Ar PATH
|
.Ar PATH
|
||||||
doesn't exist,
|
is specified and it exists,
|
||||||
.Nm
|
.Nm
|
||||||
will prompt to create a new regular file. If the parent directory
|
will open it. If the
|
||||||
is specified, it must exist and be accessible.
|
.Ar PATH
|
||||||
|
doesn't exist and ends with a \fB/\fR,
|
||||||
|
.Nm
|
||||||
|
will attempt to create the directory tree and open it. Otherwise,
|
||||||
|
.Ar PATH
|
||||||
|
is considered a path to a regular file and
|
||||||
|
.Nm
|
||||||
|
attempts to create the complete directory tree to the file, open
|
||||||
|
the parent directory and prompt to create the new file in it with
|
||||||
|
the base filename.
|
||||||
.Sh KEYBINDS
|
.Sh KEYBINDS
|
||||||
.Pp
|
.Pp
|
||||||
Press
|
Press
|
||||||
|
25
src/nnn.c
25
src/nnn.c
@ -8571,7 +8571,9 @@ int main(int argc, char *argv[])
|
|||||||
} else { /* Open a file */
|
} else { /* Open a file */
|
||||||
arg = argv[optind];
|
arg = argv[optind];
|
||||||
DPRINTF_S(arg);
|
DPRINTF_S(arg);
|
||||||
if (xstrlen(arg) > 7 && is_prefix(arg, "file://", 7))
|
size_t len = xstrlen(arg);
|
||||||
|
|
||||||
|
if (len > 7 && is_prefix(arg, "file://", 7))
|
||||||
arg = arg + 7;
|
arg = arg + 7;
|
||||||
initpath = abspath(arg, NULL, NULL);
|
initpath = abspath(arg, NULL, NULL);
|
||||||
DPRINTF_S(initpath);
|
DPRINTF_S(initpath);
|
||||||
@ -8592,16 +8594,23 @@ int main(int argc, char *argv[])
|
|||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
|
||||||
if (stat(initpath, &sb) == -1) {
|
if (stat(initpath, &sb) == -1) {
|
||||||
arg = xbasename(initpath);
|
bool dir = (arg[len - 1] == '/');
|
||||||
if (arg != initpath) { /* We have a directory */
|
|
||||||
if (!xdiraccess(xdirname(initpath))) {
|
if (!dir) {
|
||||||
xerror(); /* Fail non-existent/inaccessible directory */
|
arg = xbasename(initpath);
|
||||||
|
initpath = xdirname(initpath);
|
||||||
|
|
||||||
|
pkey = CREATE_NEW_KEY; /* Override plugin key */
|
||||||
|
g_state.initfile = 1;
|
||||||
|
}
|
||||||
|
if (dir || (arg != initpath)) { /* We have a directory */
|
||||||
|
if (!xdiraccess(initpath) && !xmktree(initpath, TRUE)) {
|
||||||
|
xerror(); /* Fail if directory cannot be created */
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
*--arg = '/'; /* Restore the complete path */
|
if (!dir) /* Restore the complete path */
|
||||||
|
*--arg = '/';
|
||||||
}
|
}
|
||||||
pkey = CREATE_NEW_KEY; /* Override plugin key */
|
|
||||||
g_state.initfile = 1;
|
|
||||||
} else if (!S_ISDIR(sb.st_mode))
|
} else if (!S_ISDIR(sb.st_mode))
|
||||||
g_state.initfile = 1;
|
g_state.initfile = 1;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user