mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Support cd .....
This commit is contained in:
parent
aab4991dda
commit
febda38c14
44
nnn.c
44
nnn.c
|
@ -284,8 +284,30 @@ xdirname(const char *path)
|
|||
return buf;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return number of dots of all chars in a string are dots, else 0
|
||||
*/
|
||||
static int
|
||||
all_dots(const char* ptr)
|
||||
{
|
||||
if (!ptr)
|
||||
return FALSE;
|
||||
|
||||
int count = 0;
|
||||
while (*ptr == '.') {
|
||||
count++;
|
||||
ptr++;
|
||||
}
|
||||
|
||||
if (*ptr)
|
||||
return 0;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/*
|
||||
* Spawns a child process. Behaviour can be controlled using flag:
|
||||
* Limited to a single argument to program, use system(3) if you need more
|
||||
* flag = 1: draw a marker to indicate nnn spawned e.g., a shell
|
||||
* flag = 2: do not wait in parent for child process e.g. DE file manager
|
||||
*/
|
||||
|
@ -1496,22 +1518,36 @@ nochange:
|
|||
} else if (tmp[0] == '-' && tmp[1] == '\0') {
|
||||
xstrlcpy(newpath, lastdir, sizeof(newpath));
|
||||
oldpath[0] = '\0';
|
||||
} else if (tmp[0] == '.' && tmp[1] == '\0')
|
||||
xstrlcpy(newpath, path, sizeof(newpath));
|
||||
else if (tmp[0] == '.' && tmp[1] == '.' && tmp[2] == '\0') {
|
||||
|
||||
} else if ((r = all_dots(tmp))) {
|
||||
if (r == 1) {
|
||||
free(input);
|
||||
break;
|
||||
}
|
||||
|
||||
r--;
|
||||
dir = path;
|
||||
|
||||
for (fd = 0; fd < r; fd++) {
|
||||
/* There is no going back */
|
||||
if (strcmp(path, "/") == 0 ||
|
||||
strchr(path, '/') == NULL) {
|
||||
if (fd == 0) {
|
||||
printmsg("You are at /");
|
||||
free(input);
|
||||
goto nochange;
|
||||
}
|
||||
dir = xdirname(path);
|
||||
|
||||
break;
|
||||
} else {
|
||||
dir = xdirname(dir);
|
||||
if (canopendir(dir) == 0) {
|
||||
printwarn();
|
||||
free(input);
|
||||
goto nochange;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Save history */
|
||||
xstrlcpy(oldpath, path, sizeof(oldpath));
|
||||
|
|
Loading…
Reference in a new issue