kakrc: Allow colorscheme to search directories recursively

This commit is contained in:
Frank LENORMAND 2018-02-22 13:35:39 +03:00
parent 35d68d2f82
commit a870210e77

View File

@ -1,22 +1,29 @@
def -params 1 -docstring "colorscheme <name>: enable named colorscheme" \ def -params 1 -docstring "colorscheme <name>: enable named colorscheme" \
-shell-candidates %{ -shell-candidates %{
for col in ${kak_runtime}/colors/*.kak ${kak_config}/colors/*.kak; do find -L "${kak_runtime}/colors" "${kak_config}/colors" -type f -name '*\.kak' \
candidate=$(basename "${col}" .kak) | while read -r path_colorscheme; do
case ${candidate} in basename="${path_colorscheme##*/}"
\**) ;; printf %s\\n "${basename%.*}"
*) echo ${candidate} ;; done | sort -u
esac
done
} \ } \
colorscheme %{ %sh{ colorscheme %{ %sh{
if [ $# -eq 1 ]; then find_colorscheme() {
if [ -f "${kak_config}/colors/$1.kak" ];then find -L "${1}" -type f -name "${2}\\.kak" | head -n 1
echo "source '${kak_config}/colors/$1.kak'" }
if [ $# -lt 1 ]; then
echo "echo -markup '{Error}Usage: colorscheme <scheme name>'"
else else
echo "source '${kak_runtime}/colors/$1.kak'" path_colorscheme=$(find_colorscheme "${kak_config}/colors" "${1}")
if [ -z "${path_colorscheme}" ];then
path_colorscheme=$(find_colorscheme "${kak_runtime}/colors" "${1}")
fi fi
if [ -z "${path_colorscheme}" ]; then
echo "echo -markup '{Error}No such colorscheme'"
else else
echo "echo -color Error 'Usage: colorscheme <scheme name>'" printf 'source %%{%s}' "${path_colorscheme}"
fi
fi fi
}} }}