diff options
author | Arun Prakash Jana <engineerarun@gmail.com> | 2017-04-20 21:57:24 +0530 |
---|---|---|
committer | Arun Prakash Jana <engineerarun@gmail.com> | 2017-04-20 21:57:24 +0530 |
commit | 79c1c56cbfefdc3288f5ddf832d2256056d46d2c (patch) | |
tree | 1f35c0e8f45c60f4dfa99f3811f04ecc618d0e8d /nnn.c | |
parent | 89224cfa980f4e3470e7e52decf5f9f19831dba6 (diff) | |
download | nnn-79c1c56cbfefdc3288f5ddf832d2256056d46d2c.tar.gz |
Support . and .. at chdir prompt
Diffstat (limited to 'nnn.c')
-rw-r--r-- | nnn.c | 50 |
1 files changed, 39 insertions, 11 deletions
@@ -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: |