blob: f91665557ca0233dd1f1c277bad99d8d12adf144 (
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
37
38
39
40
41
42
|
if [[ -z ${ZSH_COLORS} ]]; then
ZSH_COLORS=${HOME}/.local/share/zsh/colors.zsh
fi
if [[ -f ${ZSH_COLORS} ]]; then
source ${ZSH_COLORS}
fi
function colo {
# Xresource file
XRESOURCE=$1
if [[ "${XRESOURCE}" == *"-dark" ]]; then
export COLORSCHEME=${XRESOURCE%-dark}
export BACKGROUND="dark"
elif [[ "${XRESOURCE}" == *"-light" ]]; then
export COLORSCHEME=${XRESOURCE%-light}
export BACKGROUND="light"
else
export COLORSCHEME=${XRESOURCE}
export BACKGROUND=""
fi
# Change colors for current session
cat ~/.Xresources/${XRESOURCE} | 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
# Load Xresources file for future sessions
xrdb -I$HOME ~/.Xresources/${XRESOURCE}
# Change default environment variable for future sessions
mkdir -p $(dirname ${ZSH_COLORS})
echo "export COLORSCHEME=${COLORSCHEME}" > ${ZSH_COLORS}
echo "export BACKGROUND=${BACKGROUND}" >> ${ZSH_COLORS}
}
# Completion for colorschemes (-M -> Case insensitive)
compctl -k "($(ls ${HOME}/.Xresources))" -M 'm:{a-z}={A-Z}' colo
|