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:
parent
af21d4ca1e
commit
1c4f3534e1
|
@ -1,29 +1,27 @@
|
|||
def -params 1 -docstring "colorscheme <name>: 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 <scheme name>'"
|
||||
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
|
||||
}}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user