mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Support . and .. at chdir prompt
This commit is contained in:
parent
89224cfa98
commit
79c1c56cbf
44
nnn.c
44
nnn.c
|
@ -1292,7 +1292,6 @@ nochange:
|
||||||
case SEL_BACK:
|
case SEL_BACK:
|
||||||
/* There is no going back */
|
/* There is no going back */
|
||||||
if (strcmp(path, "/") == 0 ||
|
if (strcmp(path, "/") == 0 ||
|
||||||
strcmp(path, ".") == 0 ||
|
|
||||||
strchr(path, '/') == NULL) {
|
strchr(path, '/') == NULL) {
|
||||||
printmsg("You are at /");
|
printmsg("You are at /");
|
||||||
goto nochange;
|
goto nochange;
|
||||||
|
@ -1302,12 +1301,12 @@ nochange:
|
||||||
printwarn();
|
printwarn();
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save history */
|
/* Save history */
|
||||||
xstrlcpy(oldpath, path, sizeof(oldpath));
|
xstrlcpy(oldpath, path, sizeof(oldpath));
|
||||||
|
|
||||||
/* Save last working directory */
|
/* Save last working directory */
|
||||||
xstrlcpy(lastdir, path, sizeof(lastdir));
|
xstrlcpy(lastdir, path, sizeof(lastdir));
|
||||||
|
|
||||||
xstrlcpy(path, dir, sizeof(path));
|
xstrlcpy(path, dir, sizeof(path));
|
||||||
/* Reset filter */
|
/* Reset filter */
|
||||||
xstrlcpy(fltr, ifilter, sizeof(fltr));
|
xstrlcpy(fltr, ifilter, sizeof(fltr));
|
||||||
|
@ -1468,21 +1467,25 @@ nochange:
|
||||||
exitcurses();
|
exitcurses();
|
||||||
char *tmp = readline("chdir: ");
|
char *tmp = readline("chdir: ");
|
||||||
initcurses();
|
initcurses();
|
||||||
tmp = tmp[0] ? tmp : NULL;
|
|
||||||
if (chdir(cwd) == -1)
|
if (chdir(cwd) == -1)
|
||||||
printwarn();
|
printwarn();
|
||||||
|
|
||||||
if (tmp == NULL) {
|
|
||||||
/* Save current */
|
/* Save current */
|
||||||
if (ndents > 0)
|
if (ndents > 0)
|
||||||
mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));
|
mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));
|
||||||
|
|
||||||
|
if (tmp[0] == '\0')
|
||||||
goto begin;
|
goto begin;
|
||||||
} else
|
else
|
||||||
add_history(tmp);
|
add_history(tmp);
|
||||||
|
|
||||||
char *input = tmp;
|
char *input = tmp;
|
||||||
tmp = strstrip(tmp);
|
tmp = strstrip(tmp);
|
||||||
|
if (tmp[0] == '\0') {
|
||||||
|
free(input);
|
||||||
|
goto begin;
|
||||||
|
}
|
||||||
|
|
||||||
if (tmp[0] == '~') {
|
if (tmp[0] == '~') {
|
||||||
char *home = getenv("HOME");
|
char *home = getenv("HOME");
|
||||||
|
@ -1491,10 +1494,35 @@ nochange:
|
||||||
"%s%s", home, tmp + 1);
|
"%s%s", home, tmp + 1);
|
||||||
else
|
else
|
||||||
mkpath(path, tmp, newpath, sizeof(newpath));
|
mkpath(path, tmp, newpath, sizeof(newpath));
|
||||||
} else if (tmp[0] == '-' && tmp[1] == '\0')
|
|
||||||
|
oldpath[0] = '\0';
|
||||||
|
} else if (tmp[0] == '-' && tmp[1] == '\0') {
|
||||||
xstrlcpy(newpath, lastdir, sizeof(newpath));
|
xstrlcpy(newpath, lastdir, sizeof(newpath));
|
||||||
else
|
oldpath[0] = '\0';
|
||||||
|
} else if (tmp[0] == '.' && tmp[1] == '\0')
|
||||||
|
xstrlcpy(newpath, path, sizeof(newpath));
|
||||||
|
else if (tmp[0] == '.' && tmp[1] == '.' && tmp[2] == '\0') {
|
||||||
|
/* There is no going back */
|
||||||
|
if (strcmp(path, "/") == 0 ||
|
||||||
|
strchr(path, '/') == NULL) {
|
||||||
|
printmsg("You are at /");
|
||||||
|
free(input);
|
||||||
|
goto nochange;
|
||||||
|
}
|
||||||
|
dir = xdirname(path);
|
||||||
|
if (canopendir(dir) == 0) {
|
||||||
|
printwarn();
|
||||||
|
free(input);
|
||||||
|
goto nochange;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Save history */
|
||||||
|
xstrlcpy(oldpath, path, sizeof(oldpath));
|
||||||
|
xstrlcpy(newpath, dir, sizeof(newpath));
|
||||||
|
} else {
|
||||||
mkpath(path, tmp, newpath, sizeof(newpath));
|
mkpath(path, tmp, newpath, sizeof(newpath));
|
||||||
|
oldpath[0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
if (canopendir(newpath) == 0) {
|
if (canopendir(newpath) == 0) {
|
||||||
/* Save current */
|
/* Save current */
|
||||||
|
@ -1513,7 +1541,6 @@ nochange:
|
||||||
/* Reset filter */
|
/* Reset filter */
|
||||||
xstrlcpy(fltr, ifilter, sizeof(fltr));
|
xstrlcpy(fltr, ifilter, sizeof(fltr));
|
||||||
DPRINTF_S(path);
|
DPRINTF_S(path);
|
||||||
oldpath[0] = '\0';
|
|
||||||
free(input);
|
free(input);
|
||||||
goto begin;
|
goto begin;
|
||||||
}
|
}
|
||||||
|
@ -1540,6 +1567,7 @@ nochange:
|
||||||
xstrlcpy(newpath, lastdir, sizeof(newpath));
|
xstrlcpy(newpath, lastdir, sizeof(newpath));
|
||||||
xstrlcpy(lastdir, path, sizeof(lastdir));
|
xstrlcpy(lastdir, path, sizeof(lastdir));
|
||||||
xstrlcpy(path, newpath, sizeof(path));
|
xstrlcpy(path, newpath, sizeof(path));
|
||||||
|
oldpath[0] = '\0';
|
||||||
DPRINTF_S(path);
|
DPRINTF_S(path);
|
||||||
goto begin;
|
goto begin;
|
||||||
case SEL_TOGGLEDOT:
|
case SEL_TOGGLEDOT:
|
||||||
|
|
Loading…
Reference in a new issue