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:
parent
55621fb4cc
commit
e7cbf38af7
|
@ -1,7 +1,6 @@
|
||||||
def -params 1 -docstring "colorscheme <name>: enable named colorscheme" \
|
def -params 1 -docstring "colorscheme <name>: enable named colorscheme" \
|
||||||
-shell-candidates %{
|
-shell-candidates %{
|
||||||
localconfdir=${XDG_CONFIG_HOME:-${HOME}/.config}/kak
|
for col in ${kak_runtime}/colors/*.kak ${kak_config}/colors/*.kak; do
|
||||||
for col in ${kak_runtime}/colors/*.kak ${localconfdir}/colors/*.kak; do
|
|
||||||
candidate=$(basename "${col}" .kak)
|
candidate=$(basename "${col}" .kak)
|
||||||
case ${candidate} in
|
case ${candidate} in
|
||||||
\**) ;;
|
\**) ;;
|
||||||
|
@ -10,10 +9,9 @@ def -params 1 -docstring "colorscheme <name>: enable named colorscheme" \
|
||||||
done
|
done
|
||||||
} \
|
} \
|
||||||
colorscheme %{ %sh{
|
colorscheme %{ %sh{
|
||||||
localconfdir=${XDG_CONFIG_HOME:-${HOME}/.config}/kak
|
|
||||||
if [ $# -eq 1 ]; then
|
if [ $# -eq 1 ]; then
|
||||||
if [ -f "${localconfdir}/colors/$1.kak" ];then
|
if [ -f "${kak_config}/colors/$1.kak" ];then
|
||||||
echo "source '${localconfdir}/colors/$1.kak'"
|
echo "source '${kak_config}/colors/$1.kak'"
|
||||||
else
|
else
|
||||||
echo "source '${kak_runtime}/colors/$1.kak'"
|
echo "source '${kak_runtime}/colors/$1.kak'"
|
||||||
fi
|
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' '{}' '{}' \;
|
-exec printf 'try %%{ source "%s" } catch %%{ echo -debug Autoload: could not load "%s" }\n' '{}' '{}' \;
|
||||||
}
|
}
|
||||||
|
|
||||||
localconfdir=${XDG_CONFIG_HOME:-${HOME}/.config}/kak
|
|
||||||
|
|
||||||
echo "colorscheme default"
|
echo "colorscheme default"
|
||||||
|
|
||||||
if [ -d "${localconfdir}/autoload" ]; then
|
if [ -d "${kak_config}/autoload" ]; then
|
||||||
autoload_directory ${localconfdir}/autoload
|
autoload_directory ${kak_config}/autoload
|
||||||
elif [ -d "${kak_runtime}/autoload" ]; then
|
elif [ -d "${kak_runtime}/autoload" ]; then
|
||||||
autoload_directory ${kak_runtime}/autoload
|
autoload_directory ${kak_runtime}/autoload
|
||||||
fi
|
fi
|
||||||
|
@ -42,7 +38,7 @@ def -params 1 -docstring "colorscheme <name>: enable named colorscheme" \
|
||||||
echo "source '${kak_runtime}/kakrc.local'"
|
echo "source '${kak_runtime}/kakrc.local'"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "${localconfdir}/kakrc" ]; then
|
if [ -f "${kak_config}/kakrc" ]; then
|
||||||
echo "source '${localconfdir}/kakrc'"
|
echo "source '${kak_config}/kakrc'"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
12
src/main.cc
12
src/main.cc
|
@ -68,6 +68,14 @@ String runtime_directory()
|
||||||
return "/usr/share/kak";
|
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()
|
void register_env_vars()
|
||||||
{
|
{
|
||||||
static const struct {
|
static const struct {
|
||||||
|
@ -112,6 +120,10 @@ void register_env_vars()
|
||||||
"runtime", false,
|
"runtime", false,
|
||||||
[](StringView name, const Context& context)
|
[](StringView name, const Context& context)
|
||||||
{ return runtime_directory(); }
|
{ return runtime_directory(); }
|
||||||
|
}, {
|
||||||
|
"config", false,
|
||||||
|
[](StringView name, const Context& context)
|
||||||
|
{ return config_directory(); }
|
||||||
}, {
|
}, {
|
||||||
"opt_", true,
|
"opt_", true,
|
||||||
[](StringView name, const Context& context)
|
[](StringView name, const Context& context)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user