diff --git a/src/browser.c b/src/browser.c index 4d784bd..cb83b46 100644 --- a/src/browser.c +++ b/src/browser.c @@ -272,6 +272,33 @@ char *do_browser(char *path) if (strcmp(filelist[i], path) == 0) selected = i; + /* If given path is parent directory of previous working + * directory, highlight it. Also handle: grandparent, + * great-grandparent, great-great-grandparent directory and + * so on. */ + i = 0; + present_name = mallocstrcpy(present_name, path); + while (strcmp(tail(present_name), "..") == 0) { + present_name = free_and_assign(present_name, + striponedir(present_name)); + ++i; + } + + while (--i > 0) { + present_name = free_and_assign(present_name, + striponedir(present_name)); + /* Number of directories stripped is greater than the + * number of directories that were present in the path; + * it isn't possible to move up from the root directory. */ + if (strchr(present_name, '/') == 0) + statusline(MILD, "Can't move up a directory"); + } + + if (strcmp(present_name, path) == 0) { + free(present_name); + present_name = NULL; + } + /* Try opening and reading the specified directory. */ goto read_directory_contents; } else if (func == do_enter) {