From 1c4f3534e17971ad051a4921373af8e77792d669 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 24 Feb 2018 16:43:42 +1100 Subject: [PATCH] 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) --- share/kak/kakrc | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/share/kak/kakrc b/share/kak/kakrc index a5d9cec3..fb8d16c7 100644 --- a/share/kak/kakrc +++ b/share/kak/kakrc @@ -1,29 +1,27 @@ def -params 1 -docstring "colorscheme : enable named colorscheme" \ -shell-candidates %{ find -L "${kak_runtime}/colors" "${kak_config}/colors" -type f -name '*\.kak' \ - | while read -r path_colorscheme; do - basename="${path_colorscheme##*/}" + | while read -r filename; do + basename="${filename##*/}" printf %s\\n "${basename%.*}" done | sort -u } \ colorscheme %{ %sh{ 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 - echo "echo -markup '{Error}Usage: colorscheme '" - else - path_colorscheme=$(find_colorscheme "${kak_config}/colors" "${1}") - if [ -z "${path_colorscheme}" ];then - path_colorscheme=$(find_colorscheme "${kak_runtime}/colors" "${1}") - fi + if [ -d "${kak_config}/colors" ]; then + filename=$(find_colorscheme "${kak_config}/colors" "${1}") + fi + if [ -z "${filename}" ]; then + filename=$(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 + if [ -n "${filename}" ]; then + printf 'source %%{%s}' "${filename}" + else + echo "echo -markup '{Error}No such colorscheme'" fi }}