case SEL_BACK:
/* There is no going back */
if (strcmp(path, "/") == 0 ||
- strcmp(path, ".") == 0 ||
strchr(path, '/') == NULL) {
printmsg("You are at /");
goto 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));
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");
"%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 */
/* Reset filter */
xstrlcpy(fltr, ifilter, sizeof(fltr));
DPRINTF_S(path);
- oldpath[0] = '\0';
free(input);
goto begin;
}
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: