kakrc: refactor colorscheme implementation

Style tweaks, and remove check for parameter count as this is already
done by Kakoune itself (the command is specified to take 1 parameter)
This commit is contained in:
Maxime Coste 2018-02-24 16:43:42 +11:00
parent af21d4ca1e
commit 1c4f3534e1

View File

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