mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-25 18:03:37 +08:00
Fix to prevent autosuggesting cd'ing to the current working directory
This commit is contained in:
parent
14b3a5be56
commit
ca1c8243c8
|
@ -562,9 +562,19 @@ bool autosuggest_handle_special(const wcstring &str, const env_vars &vars, const
|
|||
/* We can specially handle the cd command */
|
||||
handled = true;
|
||||
bool is_help = string_prefixes_string(dir, L"--help") || string_prefixes_string(dir, L"-h");
|
||||
if (! is_help && ! path_can_get_cdpath(dir, working_directory.c_str())) {
|
||||
if (is_help) {
|
||||
suggestionOK = false;
|
||||
break;
|
||||
} else {
|
||||
wchar_t *path = path_allocate_cdpath(dir.c_str(), working_directory.c_str());
|
||||
if (path == NULL) {
|
||||
suggestionOK = false;
|
||||
} else if (paths_are_same_file(working_directory, path)) {
|
||||
/* Don't suggest the working directory as the path! */
|
||||
suggestionOK = false;
|
||||
} else {
|
||||
suggestionOK = true;
|
||||
}
|
||||
free(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,5 +108,6 @@ rgb_color_t highlight_get_color( int highlight, bool is_background );
|
|||
|
||||
bool autosuggest_handle_special(const wcstring &str, const env_vars &vars, const wcstring &working_directory, bool *outSuggestionOK);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
12
path.cpp
12
path.cpp
|
@ -529,6 +529,18 @@ bool path_is_valid(const wcstring &path, const wcstring &working_directory)
|
|||
return path_is_valid;
|
||||
}
|
||||
|
||||
bool paths_are_same_file(const wcstring &path1, const wcstring &path2) {
|
||||
if (path1 == path2)
|
||||
return true;
|
||||
|
||||
struct stat s1, s2;
|
||||
if (wstat(path1.c_str(), &s1) == 0 && wstat(path2.c_str(), &s2) == 0) {
|
||||
return s1.st_ino == s2.st_ino && s1.st_dev == s2.st_dev;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
wcstring get_working_directory(void) {
|
||||
wcstring wd = L"./";
|
||||
wchar_t dir_path[4096];
|
||||
|
|
3
path.h
3
path.h
|
@ -65,6 +65,9 @@ void path_make_canonical( wcstring &path );
|
|||
|
||||
bool path_is_valid(const wcstring &path, const wcstring &working_directory);
|
||||
|
||||
/** Returns whether the two paths refer to the same file */
|
||||
bool paths_are_same_file(const wcstring &path1, const wcstring &path2);
|
||||
|
||||
wcstring get_working_directory(void);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user