Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rely on $PWD instead of getcwd() more often

Fixes #696
  • Loading branch information...
commit fe6699f0bfb5b6aeb52ee223cdbfc00ae6a62a5e 1 parent 807c5f2
@ridiculousfish ridiculousfish authored
View
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.
*/
View
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;
View
6 highlight.cpp
@@ -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;
View
2  history.cpp
@@ -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())
{
}
View
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;
-}
View
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
View
2  reader.cpp
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.