mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 14:23:38 +08:00
Rely on $PWD instead of getcwd() more often
Fixes https://github.com/fish-shell/fish-shell/issues/696
This commit is contained in:
parent
807c5f2ef2
commit
fe6699f0bf
14
env.cpp
14
env.cpp
|
@ -507,6 +507,20 @@ int env_set_pwd()
|
|||
return 1;
|
||||
}
|
||||
|
||||
wcstring env_get_pwd_slash(void)
|
||||
{
|
||||
env_var_t pwd = env_get_string(L"PWD");
|
||||
if (pwd.missing_or_empty())
|
||||
{
|
||||
return L"";
|
||||
}
|
||||
if (! string_suffixes_string(L"/", pwd))
|
||||
{
|
||||
pwd.push_back(L'/');
|
||||
}
|
||||
return pwd;
|
||||
}
|
||||
|
||||
/**
|
||||
Set up default values for various variables if not defined.
|
||||
*/
|
||||
|
|
10
env.h
10
env.h
|
@ -213,14 +213,12 @@ const char * const * env_export_arr(bool recalc);
|
|||
*/
|
||||
wcstring_list_t env_get_names(int flags);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Update the PWD variable
|
||||
directory
|
||||
*/
|
||||
/** Update the PWD variable directory */
|
||||
int env_set_pwd();
|
||||
|
||||
/* Returns the PWD with a terminating slash */
|
||||
wcstring env_get_pwd_slash();
|
||||
|
||||
class env_vars_snapshot_t
|
||||
{
|
||||
std::map<wcstring, wcstring> vars;
|
||||
|
|
|
@ -1320,14 +1320,12 @@ void highlight_shell(const wcstring &buff, std::vector<int> &color, size_t pos,
|
|||
std::fill(color.begin(), color.end(), -1);
|
||||
|
||||
/* Do something sucky and get the current working directory on this background thread. This should really be passed in. Note that we also need this as a vector (of one directory). */
|
||||
const wcstring working_directory = get_working_directory();
|
||||
const wcstring working_directory = env_get_pwd_slash();
|
||||
|
||||
/* Tokenize the string */
|
||||
tokenize(buff.c_str(), color, pos, error, working_directory, vars);
|
||||
|
||||
/*
|
||||
Locate and syntax highlight cmdsubsts recursively
|
||||
*/
|
||||
/* Locate and syntax highlight cmdsubsts recursively */
|
||||
|
||||
wchar_t * const subbuff = wcsdup(buff.c_str());
|
||||
wchar_t * subpos = subbuff;
|
||||
|
|
|
@ -1639,7 +1639,7 @@ file_detection_context_t::file_detection_context_t(history_t *hist, const wcstri
|
|||
history(hist),
|
||||
command(cmd),
|
||||
when(time(NULL)),
|
||||
working_directory(get_working_directory())
|
||||
working_directory(env_get_pwd_slash())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
15
path.cpp
15
path.cpp
|
@ -446,18 +446,3 @@ bool paths_are_same_file(const wcstring &path1, const wcstring &path2)
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
wcstring get_working_directory(void)
|
||||
{
|
||||
wcstring wd = L"./";
|
||||
wchar_t dir_path[4096];
|
||||
const wchar_t *cwd = wgetcwd(dir_path, 4096);
|
||||
if (cwd)
|
||||
{
|
||||
wd = cwd;
|
||||
/* Make sure the working directory ends with a slash */
|
||||
if (! wd.empty() && wd.at(wd.size() - 1) != L'/')
|
||||
wd.push_back(L'/');
|
||||
}
|
||||
return wd;
|
||||
}
|
||||
|
|
3
path.h
3
path.h
|
@ -78,7 +78,4 @@ 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);
|
||||
|
||||
/* Returns the current working directory as returned by wgetcwd */
|
||||
wcstring get_working_directory(void);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1275,7 +1275,7 @@ struct autosuggestion_context_t
|
|||
cursor_pos(pos),
|
||||
searcher(*history, term, HISTORY_SEARCH_TYPE_PREFIX),
|
||||
detector(history, term),
|
||||
working_directory(get_working_directory()),
|
||||
working_directory(env_get_pwd_slash()),
|
||||
vars(env_vars_snapshot_t::highlighting_keys),
|
||||
generation_count(s_generation_count),
|
||||
has_tried_reloading(false)
|
||||
|
|
Loading…
Reference in New Issue
Block a user