From a870210e77ed6eee0584824d942854e905239bcd Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Thu, 22 Feb 2018 13:35:39 +0300 Subject: [PATCH] kakrc: Allow `colorscheme` to search directories recursively --- share/kak/kakrc | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/share/kak/kakrc b/share/kak/kakrc index f8e4415c..a5d9cec3 100644 --- a/share/kak/kakrc +++ b/share/kak/kakrc @@ -1,22 +1,29 @@ def -params 1 -docstring "colorscheme : enable named colorscheme" \ - -shell-candidates %{ - for col in ${kak_runtime}/colors/*.kak ${kak_config}/colors/*.kak; do - candidate=$(basename "${col}" .kak) - case ${candidate} in - \**) ;; - *) echo ${candidate} ;; - esac - done + -shell-candidates %{ + find -L "${kak_runtime}/colors" "${kak_config}/colors" -type f -name '*\.kak' \ + | while read -r path_colorscheme; do + basename="${path_colorscheme##*/}" + printf %s\\n "${basename%.*}" + done | sort -u } \ colorscheme %{ %sh{ - if [ $# -eq 1 ]; then - if [ -f "${kak_config}/colors/$1.kak" ];then - echo "source '${kak_config}/colors/$1.kak'" - else - echo "source '${kak_runtime}/colors/$1.kak'" - fi + find_colorscheme() { + find -L "${1}" -type f -name "${2}\\.kak" | head -n 1 + } + + if [ $# -lt 1 ]; then + echo "echo -markup '{Error}Usage: colorscheme '" else - echo "echo -color Error 'Usage: colorscheme '" + path_colorscheme=$(find_colorscheme "${kak_config}/colors" "${1}") + if [ -z "${path_colorscheme}" ];then + path_colorscheme=$(find_colorscheme "${kak_runtime}/colors" "${1}") + fi + + if [ -z "${path_colorscheme}" ]; then + echo "echo -markup '{Error}No such colorscheme'" + else + printf 'source %%{%s}' "${path_colorscheme}" + fi fi }}