mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-31 20:31:19 -03:00
path: Make working_directory wcstring
Kinda weird that that one was a wchar_t*
This commit is contained in:
@@ -351,7 +351,7 @@ bool autosuggest_validate_from_history(const history_item_t &item,
|
||||
string_prefixes_string(cd_dir, L"--help") || string_prefixes_string(cd_dir, L"-h");
|
||||
if (!is_help) {
|
||||
wcstring path;
|
||||
bool can_cd = path_get_cdpath(cd_dir, &path, working_directory.c_str(), vars);
|
||||
bool can_cd = path_get_cdpath(cd_dir, &path, working_directory, vars);
|
||||
if (can_cd && !paths_are_same_file(working_directory, path)) {
|
||||
suggestionOK = true;
|
||||
}
|
||||
@@ -1021,7 +1021,7 @@ static bool command_is_valid(const wcstring &cmd, enum parse_statement_decoratio
|
||||
|
||||
// Implicit cd
|
||||
if (!is_valid && implicit_cd_ok) {
|
||||
is_valid = path_can_be_implicit_cd(cmd, NULL, working_directory.c_str(), vars);
|
||||
is_valid = path_can_be_implicit_cd(cmd, NULL, working_directory, vars);
|
||||
}
|
||||
|
||||
// Return what we got.
|
||||
|
||||
13
src/path.cpp
13
src/path.cpp
@@ -157,15 +157,12 @@ wcstring_list_t path_get_paths(const wcstring &cmd) {
|
||||
return paths;
|
||||
}
|
||||
|
||||
bool path_get_cdpath(const wcstring &dir, wcstring *out, const wchar_t *wd,
|
||||
bool path_get_cdpath(const wcstring &dir, wcstring *out, const wcstring &wd,
|
||||
const env_vars_snapshot_t &env_vars) {
|
||||
int err = ENOENT;
|
||||
if (dir.empty()) return false;
|
||||
|
||||
if (wd) {
|
||||
size_t len = wcslen(wd);
|
||||
assert(wd[len - 1] == L'/');
|
||||
}
|
||||
assert(wd.empty() || wd.back() == L'/');
|
||||
|
||||
wcstring_list_t paths;
|
||||
if (dir.at(0) == L'/') {
|
||||
@@ -175,7 +172,7 @@ bool path_get_cdpath(const wcstring &dir, wcstring *out, const wchar_t *wd,
|
||||
dir == L"." || dir == L"..") {
|
||||
// Path is relative to the working directory.
|
||||
wcstring path;
|
||||
if (wd) path.append(wd);
|
||||
if (!wd.empty()) path.append(wd);
|
||||
path.append(dir);
|
||||
paths.push_back(path);
|
||||
} else {
|
||||
@@ -189,7 +186,7 @@ bool path_get_cdpath(const wcstring &dir, wcstring *out, const wchar_t *wd,
|
||||
}
|
||||
for (wcstring next_path : cdpathsv) {
|
||||
if (next_path.empty()) next_path = L".";
|
||||
if (next_path == L"." && wd != NULL) {
|
||||
if (next_path == L"." && !wd.empty()) {
|
||||
// next_path is just '.', and we have a working directory, so use the wd instead.
|
||||
// TODO: if next_path starts with ./ we need to replace the . with the wd.
|
||||
next_path = wd;
|
||||
@@ -221,7 +218,7 @@ bool path_get_cdpath(const wcstring &dir, wcstring *out, const wchar_t *wd,
|
||||
return success;
|
||||
}
|
||||
|
||||
bool path_can_be_implicit_cd(const wcstring &path, wcstring *out_path, const wchar_t *wd,
|
||||
bool path_can_be_implicit_cd(const wcstring &path, wcstring *out_path, const wcstring &wd,
|
||||
const env_vars_snapshot_t &vars) {
|
||||
wcstring exp_path = path;
|
||||
expand_tilde(exp_path);
|
||||
|
||||
@@ -61,14 +61,14 @@ wcstring_list_t path_get_paths(const wcstring &cmd);
|
||||
/// \param vars The environment variable snapshot to use (for the CDPATH variable)
|
||||
/// \return 0 if the command can not be found, the path of the command otherwise. The path should be
|
||||
/// free'd with free().
|
||||
bool path_get_cdpath(const wcstring &dir, wcstring *out_or_NULL, const wchar_t *wd = NULL,
|
||||
bool path_get_cdpath(const wcstring &dir, wcstring *out_or_NULL, const wcstring &wd = L"",
|
||||
const env_vars_snapshot_t &vars = env_vars_snapshot_t::current());
|
||||
|
||||
/// Returns whether the path can be used for an implicit cd command; if so, also returns the path by
|
||||
/// reference (if desired). This requires it to start with one of the allowed prefixes (., .., ~)
|
||||
/// and resolve to a directory.
|
||||
bool path_can_be_implicit_cd(const wcstring &path, wcstring *out_path = NULL,
|
||||
const wchar_t *wd = NULL,
|
||||
const wcstring &wd = L"",
|
||||
const env_vars_snapshot_t &vars = env_vars_snapshot_t::current());
|
||||
|
||||
/// Remove double slashes and trailing slashes from a path, e.g. transform foo//bar/ into foo/bar.
|
||||
|
||||
Reference in New Issue
Block a user