aboutsummaryrefslogtreecommitdiffstats
path: root/nnn.c
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2017-04-20 21:57:24 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2017-04-20 21:57:24 +0530
commit79c1c56cbfefdc3288f5ddf832d2256056d46d2c (patch)
tree1f35c0e8f45c60f4dfa99f3811f04ecc618d0e8d /nnn.c
parent89224cfa980f4e3470e7e52decf5f9f19831dba6 (diff)
downloadnnn-79c1c56cbfefdc3288f5ddf832d2256056d46d2c.tar.gz
Support . and .. at chdir prompt
Diffstat (limited to 'nnn.c')
-rw-r--r--nnn.c50
1 files changed, 39 insertions, 11 deletions
diff --git a/nnn.c b/nnn.c
index 85bbdf5..a6f282c 100644
--- a/nnn.c
+++ b/nnn.c
@@ -1292,7 +1292,6 @@ nochange:
case SEL_BACK:
/* There is no going back */
if (strcmp(path, "/") == 0 ||
- strcmp(path, ".") == 0 ||
strchr(path, '/') == NULL) {
printmsg("You are at /");
goto nochange;
@@ -1302,12 +1301,12 @@ nochange:
printwarn();
goto nochange;
}
+
/* Save history */
xstrlcpy(oldpath, path, sizeof(oldpath));
/* Save last working directory */
xstrlcpy(lastdir, path, sizeof(lastdir));
-
xstrlcpy(path, dir, sizeof(path));
/* Reset filter */
xstrlcpy(fltr, ifilter, sizeof(fltr));
@@ -1468,21 +1467,25 @@ nochange:
exitcurses();
char *tmp = readline("chdir: ");
initcurses();
- tmp = tmp[0] ? tmp : NULL;
+
if (chdir(cwd) == -1)
printwarn();
- if (tmp == NULL) {
- /* Save current */
- if (ndents > 0)
- mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));
+ /* Save current */
+ if (ndents > 0)
+ mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));
+ if (tmp[0] == '\0')
goto begin;
- } else
+ else
add_history(tmp);
char *input = tmp;
tmp = strstrip(tmp);
+ if (tmp[0] == '\0') {
+ free(input);
+ goto begin;
+ }
if (tmp[0] == '~') {
char *home = getenv("HOME");
@@ -1491,10 +1494,35 @@ nochange:
"%s%s", home, tmp + 1);
else
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));
- 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));
+ oldpath[0] = '\0';
+ }
if (canopendir(newpath) == 0) {
/* Save current */
@@ -1513,7 +1541,6 @@ nochange:
/* Reset filter */
xstrlcpy(fltr, ifilter, sizeof(fltr));
DPRINTF_S(path);
- oldpath[0] = '\0';
free(input);
goto begin;
}
@@ -1540,6 +1567,7 @@ nochange:
xstrlcpy(newpath, lastdir, sizeof(newpath));
xstrlcpy(lastdir, path, sizeof(lastdir));
xstrlcpy(path, newpath, sizeof(path));
+ oldpath[0] = '\0';
DPRINTF_S(path);
goto begin;
case SEL_TOGGLEDOT: