mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +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 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,22 +1518,36 @@ 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) {
|
||||||
|
free(input);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
r--;
|
||||||
|
dir = path;
|
||||||
|
|
||||||
|
for (fd = 0; fd < r; fd++) {
|
||||||
/* There is no going back */
|
/* There is no going back */
|
||||||
if (strcmp(path, "/") == 0 ||
|
if (strcmp(path, "/") == 0 ||
|
||||||
strchr(path, '/') == NULL) {
|
strchr(path, '/') == NULL) {
|
||||||
|
if (fd == 0) {
|
||||||
printmsg("You are at /");
|
printmsg("You are at /");
|
||||||
free(input);
|
free(input);
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
dir = xdirname(path);
|
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
dir = xdirname(dir);
|
||||||
if (canopendir(dir) == 0) {
|
if (canopendir(dir) == 0) {
|
||||||
printwarn();
|
printwarn();
|
||||||
free(input);
|
free(input);
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Save history */
|
/* Save history */
|
||||||
xstrlcpy(oldpath, path, sizeof(oldpath));
|
xstrlcpy(oldpath, path, sizeof(oldpath));
|
||||||
|
|
Loading…
Reference in a new issue