Attmept to create PATH if PATH is non-existent

This commit is contained in:
Arun Prakash Jana 2022-12-11 00:03:24 +05:30
parent 93de728eab
commit d4c3e52f2f
No known key found for this signature in database
GPG key ID: A75979F35C080412
2 changed files with 30 additions and 12 deletions

17
nnn.1
View file

@ -31,12 +31,21 @@ efficient file manager that stays out of your way.
.Nm
opens the current working directory if
.Ar PATH
is not specified. If the
is not specified. If
.Ar PATH
doesn't exist,
is specified and it exists,
.Nm
will prompt to create a new regular file. If the parent directory
is specified, it must exist and be accessible.
will open it. If the
.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
.Pp
Press

View file

@ -8571,7 +8571,9 @@ int main(int argc, char *argv[])
} else { /* Open a file */
arg = argv[optind];
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;
initpath = abspath(arg, NULL, NULL);
DPRINTF_S(initpath);
@ -8592,16 +8594,23 @@ int main(int argc, char *argv[])
struct stat sb;
if (stat(initpath, &sb) == -1) {
arg = xbasename(initpath);
if (arg != initpath) { /* We have a directory */
if (!xdiraccess(xdirname(initpath))) {
xerror(); /* Fail non-existent/inaccessible directory */
bool dir = (arg[len - 1] == '/');
if (!dir) {
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;
}
*--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))
g_state.initfile = 1;