aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/path.cpp
diff options
context:
space:
mode:
authorGravatar Jeff Kowalski <jeff.kowalski@gmail.com>2015-09-16 21:31:08 -0700
committerGravatar David Adam <zanchey@ucc.gu.uwa.edu.au>2015-10-16 07:39:49 +0800
commit2971887bbdd34813c86bd3e2f1959e4f608eb4f0 (patch)
treef9ff4b1a0c0f997f9873faa557ac810f4433c314 /src/path.cpp
parentb776327b9dcaeac798b43c0f82f0a1b37545f57f (diff)
Access fish_history from $XDG_DATA_HOME
Add new functions path_get_data and path_create_data which parallel existing functions path_get_config and path_create_data. The new functions refer to XDG_DATA_HOME, if it is defined, or ./local/share if not. Modify history_filename to use the new function path_get_data. As a consequence, fish_history will now be located in XDG_DATA_HOME, not XDG_CONFIG_HOME. Note that these changes mirror what is already used in fish-shell/share/tools/create_manpage_completions.py, which stores the completions in XDG_DATA_HOME This change matches recommendations in the xdg basedir spec at http://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html ($XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used.) It addresses suggestions from the following issues: 1. Don't put history in $XDG_CONFIG_HOME (closes #744) https://github.com/fish-shell/fish-shell/issues/744 2. Fish is placing non-config files in $XDG_CONFIG_HOME #1257 https://github.com/fish-shell/fish-shell/issues/1257 3. Move non-config data out of $XDG_CONFIG_HOME #1669 https://github.com/fish-shell/fish-shell/issues/1669
Diffstat (limited to 'src/path.cpp')
-rw-r--r--src/path.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/path.cpp b/src/path.cpp
index 62a31a63..b8cfd516 100644
--- a/src/path.cpp
+++ b/src/path.cpp
@@ -276,6 +276,42 @@ static wcstring path_create_config()
return res;
}
+static wcstring path_create_data()
+{
+ bool done = false;
+ wcstring res;
+
+ const env_var_t xdg_dir = env_get_string(L"XDG_DATA_HOME");
+ if (! xdg_dir.missing())
+ {
+ res = xdg_dir + L"/fish";
+ if (!create_directory(res))
+ {
+ done = true;
+ }
+ }
+ else
+ {
+ const env_var_t home = env_get_string(L"HOME");
+ if (! home.missing())
+ {
+ res = home + L"/.local/share/fish";
+ if (!create_directory(res))
+ {
+ done = true;
+ }
+ }
+ }
+
+ if (! done)
+ {
+ res.clear();
+
+ debug(0, _(L"Unable to create a data directory for fish. Your history will not be saved. Please set the $XDG_DATA_HOME variable to a directory where the current user has write access."));
+ }
+ return res;
+}
+
/* Cache the config path */
bool path_get_config(wcstring &path)
{
@@ -284,6 +320,14 @@ bool path_get_config(wcstring &path)
return ! result.empty();
}
+/* Cache the data path */
+bool path_get_data(wcstring &path)
+{
+ static const wcstring result = path_create_data();
+ path = result;
+ return ! result.empty();
+}
+
__attribute__((unused))
static void replace_all(wcstring &str, const wchar_t *needle, const wchar_t *replacement)
{