aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/os')
-rw-r--r--src/nvim/os/os.h1
-rw-r--r--src/nvim/os/stdpaths.c100
-rw-r--r--src/nvim/os/unix_defs.h29
-rw-r--r--src/nvim/os/win_defs.h1
4 files changed, 101 insertions, 30 deletions
diff --git a/src/nvim/os/os.h b/src/nvim/os/os.h
index 69bd1ff4fd..198f9ae897 100644
--- a/src/nvim/os/os.h
+++ b/src/nvim/os/os.h
@@ -12,6 +12,7 @@
# include "os/mem.h.generated.h"
# include "os/env.h.generated.h"
# include "os/users.h.generated.h"
+# include "os/stdpaths.h.generated.h"
#endif
#endif // NVIM_OS_OS_H
diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c
new file mode 100644
index 0000000000..230e760d7d
--- /dev/null
+++ b/src/nvim/os/stdpaths.c
@@ -0,0 +1,100 @@
+#include "nvim/os/os.h"
+#include "nvim/strings.h"
+#include "nvim/path.h"
+#include "nvim/garray.h"
+
+typedef enum {
+ kXDGConfigHome,
+ kXDGDataHome,
+ kXDGCacheHome,
+ kXDGRuntimeDir,
+ kXDGConfigDirs,
+ kXDGDataDirs,
+} XDGDirType;
+
+static const char *xdg_env_vars[] = {
+ [kXDGConfigHome] = "XDG_CONFIG_HOME",
+ [kXDGDataHome] = "XDG_DATA_HOME",
+ [kXDGCacheHome] = "XDG_CACHE_HOME",
+ [kXDGRuntimeDir] = "XDG_RUNTIME_DIR",
+ [kXDGConfigDirs] = "XDG_CONFIG_DIRS",
+ [kXDGDataDirs] = "XDG_DATA_DIRS",
+};
+
+static const char *const xdg_defaults[] = {
+ // Windows, Apple stuff are just shims right now
+#ifdef WIN32
+ // Windows
+#elif APPLE
+ // Apple (this includes iOS, which we might need to handle differently)
+ [kXDGConfigHome] = "~/Library/Preferences",
+ [kXDGDataHome] = "~/Library/Application Support",
+ [kXDGCacheHome] = "~/Library/Caches",
+ [kXDGRuntimeDir] = "~/Library/Application Support",
+ [kXDGConfigDirs] = "/Library/Application Support",
+ [kXDGDataDirs] = "/Library/Application Support",
+#else
+ // Linux, BSD, CYGWIN
+ [kXDGConfigHome] = "~/.config",
+ [kXDGDataHome] = "~/.local/share",
+ [kXDGCacheHome] = "~/.cache",
+ [kXDGRuntimeDir] = "",
+ [kXDGConfigDirs] = "/etc/xdg/",
+ [kXDGDataDirs] = "/usr/local/share/:/usr/share/",
+};
+#endif
+
+static const char *get_xdg(XDGDirType idx)
+{
+ const char *env = xdg_env_vars[idx];
+ const char *fallback = xdg_defaults[idx];
+
+ const char *ret = os_getenv(env);
+ if (!ret && fallback) {
+ ret = (const char *)expand_env_save((char_u *)fallback);
+ }
+
+ return ret;
+}
+
+static const char *get_xdg_home(XDGDirType idx)
+{
+ const char *dir = get_xdg(idx);
+ if (dir) {
+ dir = (const char *)concat_fnames(dir, "nvim", true);
+ }
+ return dir;
+}
+
+static void create_dir(const char *dir, int mode, const char *suffix)
+{
+ char *failed;
+ if (!os_mkdir_recurse(dir, mode, &failed)) {
+ // TODO: Create a folder in $TMPDIR instead
+ DLOG("Create dir failed");
+ }
+}
+
+const char *get_user_conf_dir(void)
+{
+ return get_xdg_home(kXDGConfigHome);
+}
+
+const char *get_from_user_conf(const char * fname)
+{
+ return (const char *)concat_fnames(get_user_conf_dir(), fname, true);
+}
+
+const char *get_user_data_dir(void)
+{
+ return get_xdg_home(kXDGDataHome);
+}
+
+const char *get_from_user_data(const char * fname)
+{
+ const char *dir = (const char *)concat_fnames(get_user_data_dir(), fname, true);
+ if (!os_isdir((char_u *)dir)) {
+ create_dir(dir, 0755, fname);
+ }
+ return dir;
+}
diff --git a/src/nvim/os/unix_defs.h b/src/nvim/os/unix_defs.h
index 949973bf40..83c6752ff7 100644
--- a/src/nvim/os/unix_defs.h
+++ b/src/nvim/os/unix_defs.h
@@ -31,12 +31,6 @@
#ifndef USR_EXRC_FILE
# define USR_EXRC_FILE "~/.exrc"
#endif
-#ifndef USR_VIMRC_FILE
-# define USR_VIMRC_FILE "~/.nvimrc"
-#endif
-#ifndef USR_VIMRC_FILE2
-# define USR_VIMRC_FILE2 "~/.nvim/nvimrc"
-#endif
#ifndef EXRC_FILE
# define EXRC_FILE ".exrc"
#endif
@@ -47,27 +41,4 @@
# define SHADA_FILE "~/.nvim/shada/main.shada"
#endif
-// Default for 'backupdir'.
-#ifndef DFLT_BDIR
-# define DFLT_BDIR ".,~/tmp,~/"
-#endif
-
-// Default for 'directory'.
-#ifndef DFLT_DIR
-# define DFLT_DIR ".,~/tmp,/var/tmp,/tmp"
-#endif
-
-// Default for 'viewdir'.
-#ifndef DFLT_VDIR
-# define DFLT_VDIR "~/.nvim/view"
-#endif
-
-#ifdef RUNTIME_GLOBAL
-# define DFLT_RUNTIMEPATH "~/.nvim," RUNTIME_GLOBAL ",$VIMRUNTIME," \
- RUNTIME_GLOBAL "/after,~/.nvim/after"
-#else
-# define DFLT_RUNTIMEPATH \
- "~/.nvim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.nvim/after"
-#endif
-
#endif // NVIM_OS_UNIX_DEFS_H
diff --git a/src/nvim/os/win_defs.h b/src/nvim/os/win_defs.h
index b7ec50a109..62889a7d2f 100644
--- a/src/nvim/os/win_defs.h
+++ b/src/nvim/os/win_defs.h
@@ -8,7 +8,6 @@
// Defines needed to fix the build on Windows:
// - USR_EXRC_FILE
-// - USR_VIMRC_FILE
// - SHADA_FILE
// - DFLT_DIR
// - DFLT_BDIR