diff --git a/src/builtin_cd.cpp b/src/builtin_cd.cpp index b86981e5c..98a4da3fe 100644 --- a/src/builtin_cd.cpp +++ b/src/builtin_cd.cpp @@ -33,33 +33,31 @@ int builtin_cd(parser_t &parser, io_streams_t &streams, wchar_t **argv) { return STATUS_CMD_OK; } - env_var_t dir_in; + wcstring dir_in; wcstring dir; if (argv[optind]) { - dir_in = env_var_t(wcstring(argv[optind]), 0); // unamed var + dir_in = argv[optind]; } else { auto maybe_dir_in = env_get(L"HOME"); if (maybe_dir_in.missing_or_empty()) { streams.err.append_format(_(L"%ls: Could not find home directory\n"), cmd); return STATUS_CMD_ERROR; } - dir_in = std::move(*maybe_dir_in); + dir_in = maybe_dir_in->as_string(); } if (!path_get_cdpath(dir_in, &dir)) { if (errno == ENOTDIR) { - streams.err.append_format(_(L"%ls: '%ls' is not a directory\n"), cmd, - dir_in.as_string().c_str()); + streams.err.append_format(_(L"%ls: '%ls' is not a directory\n"), cmd, dir_in.c_str()); } else if (errno == ENOENT) { streams.err.append_format(_(L"%ls: The directory '%ls' does not exist\n"), cmd, - dir_in.as_string().c_str()); + dir_in.c_str()); } else if (errno == EROTTEN) { - streams.err.append_format(_(L"%ls: '%ls' is a rotten symlink\n"), cmd, - dir_in.as_string().c_str()); + streams.err.append_format(_(L"%ls: '%ls' is a rotten symlink\n"), cmd, dir_in.c_str()); } else { streams.err.append_format(_(L"%ls: Unknown error trying to locate directory '%ls'\n"), - cmd, dir_in.as_string().c_str()); + cmd, dir_in.c_str()); } if (!shell_is_interactive()) streams.err.append(parser.current_line()); diff --git a/src/highlight.cpp b/src/highlight.cpp index 7d98b896e..b620f6d3d 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -350,8 +350,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; - env_var_t dir_var(cd_dir, 0); - bool can_cd = path_get_cdpath(dir_var, &path, working_directory.c_str(), vars); + bool can_cd = path_get_cdpath(cd_dir, &path, working_directory.c_str(), vars); if (can_cd && !paths_are_same_file(working_directory, path)) { suggestionOK = true; } diff --git a/src/path.cpp b/src/path.cpp index a7d5bbe4a..e9ba42d44 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -157,11 +157,10 @@ wcstring_list_t path_get_paths(const wcstring &cmd) { return paths; } -bool path_get_cdpath(const env_var_t &dir_var, wcstring *out, const wchar_t *wd, +bool path_get_cdpath(const wcstring &dir, wcstring *out, const wchar_t *wd, const env_vars_snapshot_t &env_vars) { int err = ENOENT; - if (dir_var.empty()) return false; - wcstring dir = dir_var.as_string(); + if (dir.empty()) return false; if (wd) { size_t len = wcslen(wd); @@ -229,10 +228,7 @@ bool path_can_be_implicit_cd(const wcstring &path, wcstring *out_path, const wch if (string_prefixes_string(L"/", exp_path) || string_prefixes_string(L"./", exp_path) || string_prefixes_string(L"../", exp_path) || string_suffixes_string(L"/", exp_path) || exp_path == L"..") { - // These paths can be implicit cd, so see if you cd to the path. Note that a single period - // cannot (that's used for sourcing files anyways). - env_var_t path_var(L"n/a", exp_path); - result = path_get_cdpath(path_var, out_path, wd, vars); + result = path_get_cdpath(exp_path, out_path, wd, vars); } return result; } diff --git a/src/path.h b/src/path.h index 2b62dfa03..371d0ef86 100644 --- a/src/path.h +++ b/src/path.h @@ -61,7 +61,7 @@ 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 env_var_t &dir, wcstring *out_or_NULL, const wchar_t *wd = NULL, +bool path_get_cdpath(const wcstring &dir, wcstring *out_or_NULL, const wchar_t *wd = NULL, 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