kakoune/share/kak/kakrc
Maxime Coste 79562a614e Fix colorscheme completion that triggered a shell syntax error
When the user colors dir was missing, expr was failing, with
the error ending up in the *debug* buffer
2015-07-20 13:14:08 +01:00

62 lines
1.6 KiB
Plaintext

def -shell-params runtime %{ %sh{
while [ $# -gt 0 ]; do
echo "source '${kak_runtime}/$1'"
shift
done
}}
def -shell-params -docstring "colorscheme <name>: enable named colorscheme" \
-shell-completion %{
prefix=${1:0:${kak_pos_in_token}}
(
localconfdir=${XDG_CONFIG_HOME:-${HOME}/.config}/kak
for col in ${kak_runtime}/colors/*.kak ${localconfdir}/colors/*.kak; do
candidate=$(basename "${col}" .kak)
case ${candidate} in
\**) ;;
${prefix}*) echo ${candidate} ;;
esac
done
) | sort -u
} \
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'"
else
echo "source '${kak_runtime}/colors/$1.kak'"
fi
else
echo -color Error 'Usage: colorscheme <scheme name>'
fi
}}
%sh{
autoload() {
dir=$1
for rcfile in ${dir}/*.kak; do
echo "try %{ source '${rcfile}' } catch %{ }";
done
for subdir in ${dir}/*; do
if [ -d "$subdir" ]; then
autoload $subdir
fi
done
}
localconfdir=${XDG_CONFIG_HOME:-${HOME}/.config}/kak
echo "colorscheme default"
if [ -d "${localconfdir}/autoload" ]; then
autoload ${localconfdir}/autoload
elif [ -d "${kak_runtime}/autoload" ]; then
autoload ${kak_runtime}/autoload
fi
if [ -f "${localconfdir}/kakrc" ]; then
echo "source '${localconfdir}/kakrc'"
fi
}