blob: 5ea454f50a04e179004d7ce04e199644cc5c2891 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#!/bin/zsh
[[ -z ${ZSH_COLORS} ]] && ZSH_COLORS=${HOME}/.local/share/zsh/colors.zsh
[[ -f ${ZSH_COLORS} ]] && source ${ZSH_COLORS}
colorschemes=$(echo ${HOME}/.Xresources/* | sed "s#${HOME}/.Xresources/##g")
function colo {
XRESOURCE=$1
XRESOURCE_FILE=${HOME}/.Xresources/${XRESOURCE}
# Change colors for current session
/usr/bin/cpp ${XRESOURCE_FILE} | tr -d ' \t' | sed -n \
-e 's/.*background:/\x1b]11;/p' \
-e 's/.*foreground:/\x1b]10;/p' \
-e 's/.*borderColor:/\x1b]708;/p' \
-e 's/.*color\([0-9][^:]*\):/\x1b]4;\1;/p' | tr \\n \\a
# Change color for future sessions
xrdb ${XRESOURCE_FILE}
# Change default environment variable for future sessions
mkdir -p $(dirname ${ZSH_COLORS})
COLORSCHEME=$(echo ${XRESOURCE} | sed 's/\([^.]\+\)\..\+$/\1/g')
BACKGROUND=$(echo ${XRESOURCE} | sed 's/^.\+\(dark\|light\)/\1/')
echo "export COLORSCHEME=${COLORSCHEME}" > ${ZSH_COLORS}
echo "export BACKGROUND=${BACKGROUND}" >> ${ZSH_COLORS}
echo "export XRESOURCE=${XRESOURCE}" >> ${ZSH_COLORS}
source ${ZSH_COLORS}
}
# Completion for colorschemes (-M -> Case insensitive)
compctl -k "(${colorschemes})" -M 'm:{a-z}={A-Z}' colo
|