From e7cbf38af74b7841baf350ddcc85699d2295aeb7 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 19 Jan 2018 10:05:08 +1100 Subject: [PATCH] Introduce a $kak_config env var containing the Kakoune user config dir Makes it easier for users who want to locate their kakrc file, and does not require to go through shell expansion to get it as "${XDG_CONFIG_DIR:-${HOME}/.config}/kak" Fixes #1740 --- share/kak/kakrc | 18 +++++++----------- src/main.cc | 12 ++++++++++++ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/share/kak/kakrc b/share/kak/kakrc index 7a9f1692..f8e4415c 100644 --- a/share/kak/kakrc +++ b/share/kak/kakrc @@ -1,7 +1,6 @@ def -params 1 -docstring "colorscheme : enable named colorscheme" \ -shell-candidates %{ - localconfdir=${XDG_CONFIG_HOME:-${HOME}/.config}/kak - for col in ${kak_runtime}/colors/*.kak ${localconfdir}/colors/*.kak; do + for col in ${kak_runtime}/colors/*.kak ${kak_config}/colors/*.kak; do candidate=$(basename "${col}" .kak) case ${candidate} in \**) ;; @@ -10,10 +9,9 @@ def -params 1 -docstring "colorscheme : enable named colorscheme" \ done } \ colorscheme %{ %sh{ - localconfdir=${XDG_CONFIG_HOME:-${HOME}/.config}/kak if [ $# -eq 1 ]; then - if [ -f "${localconfdir}/colors/$1.kak" ];then - echo "source '${localconfdir}/colors/$1.kak'" + if [ -f "${kak_config}/colors/$1.kak" ];then + echo "source '${kak_config}/colors/$1.kak'" else echo "source '${kak_runtime}/colors/$1.kak'" fi @@ -28,12 +26,10 @@ def -params 1 -docstring "colorscheme : enable named colorscheme" \ -exec printf 'try %%{ source "%s" } catch %%{ echo -debug Autoload: could not load "%s" }\n' '{}' '{}' \; } - localconfdir=${XDG_CONFIG_HOME:-${HOME}/.config}/kak - echo "colorscheme default" - if [ -d "${localconfdir}/autoload" ]; then - autoload_directory ${localconfdir}/autoload + if [ -d "${kak_config}/autoload" ]; then + autoload_directory ${kak_config}/autoload elif [ -d "${kak_runtime}/autoload" ]; then autoload_directory ${kak_runtime}/autoload fi @@ -42,7 +38,7 @@ def -params 1 -docstring "colorscheme : enable named colorscheme" \ echo "source '${kak_runtime}/kakrc.local'" fi - if [ -f "${localconfdir}/kakrc" ]; then - echo "source '${localconfdir}/kakrc'" + if [ -f "${kak_config}/kakrc" ]; then + echo "source '${kak_config}/kakrc'" fi } diff --git a/src/main.cc b/src/main.cc index b9f995f6..aff7f9f2 100644 --- a/src/main.cc +++ b/src/main.cc @@ -68,6 +68,14 @@ String runtime_directory() return "/usr/share/kak"; } +String config_directory() +{ + StringView config_home = getenv("XDG_CONFIG_HOME"); + if (config_home.empty()) + return format("{}/.config/kak", getenv("HOME")); + return format("{}/kak", config_home); +} + void register_env_vars() { static const struct { @@ -112,6 +120,10 @@ void register_env_vars() "runtime", false, [](StringView name, const Context& context) { return runtime_directory(); } + }, { + "config", false, + [](StringView name, const Context& context) + { return config_directory(); } }, { "opt_", true, [](StringView name, const Context& context)