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
62
nnn.c
62
nnn.c
|
@ -284,8 +284,30 @@ xdirname(const char *path)
|
||||||
return buf;
|
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:
|
* 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 = 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
|
* flag = 2: do not wait in parent for child process e.g. DE file manager
|
||||||
*/
|
*/
|
||||||
|
@ -1496,21 +1518,35 @@ nochange:
|
||||||
} else if (tmp[0] == '-' && tmp[1] == '\0') {
|
} else if (tmp[0] == '-' && tmp[1] == '\0') {
|
||||||
xstrlcpy(newpath, lastdir, sizeof(newpath));
|
xstrlcpy(newpath, lastdir, sizeof(newpath));
|
||||||
oldpath[0] = '\0';
|
oldpath[0] = '\0';
|
||||||
} else if (tmp[0] == '.' && tmp[1] == '\0')
|
|
||||||
xstrlcpy(newpath, path, sizeof(newpath));
|
} else if ((r = all_dots(tmp))) {
|
||||||
else if (tmp[0] == '.' && tmp[1] == '.' && tmp[2] == '\0') {
|
if (r == 1) {
|
||||||
/* There is no going back */
|
|
||||||
if (strcmp(path, "/") == 0 ||
|
|
||||||
strchr(path, '/') == NULL) {
|
|
||||||
printmsg("You are at /");
|
|
||||||
free(input);
|
free(input);
|
||||||
goto nochange;
|
break;
|
||||||
}
|
}
|
||||||
dir = xdirname(path);
|
|
||||||
if (canopendir(dir) == 0) {
|
r--;
|
||||||
printwarn();
|
dir = path;
|
||||||
free(input);
|
|
||||||
goto nochange;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
dir = xdirname(dir);
|
||||||
|
if (canopendir(dir) == 0) {
|
||||||
|
printwarn();
|
||||||
|
free(input);
|
||||||
|
goto nochange;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save history */
|
/* Save history */
|
||||||
|
|
Loading…
Reference in a new issue