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
This commit is contained in:
Maxime Coste 2018-01-19 10:05:08 +11:00
parent 55621fb4cc
commit e7cbf38af7
2 changed files with 19 additions and 11 deletions

View File

@ -1,7 +1,6 @@
def -params 1 -docstring "colorscheme <name>: 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 <name>: 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 <name>: 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 <name>: 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
}

View File

@ -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)