aboutsummaryrefslogtreecommitdiff
path: root/.local/share/mode/plug.d/10_lib
blob: b3a02769720d465f41988037136686810b8b4fd7 (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
43
44
45
46
#!/bin/sh
# utility library functions
hex_to_rgb_array() { pastel format rgb "$1" | cut -c4- | tr '()' '[]' ; }

mix_rgb() { pastel mix --colorspace=RGB --fraction="$3" "$1" "$2" | pastel format hex ; }

getvar() {
	key="$1"
	eval "printf '%s' \"\$$key\""
}

setvar() {
	key="$1"
	value="$2"
	eval "$key='$(printf '%s' "$value")'"
}

themevar() {
	key="$1"
	if [ $# -eq 1 ] ; then
		value="$(getvar "$key")"
	else
		value="$2"
		setvar "$key" "$value"
	fi

	vars="$vars
$(printf "export %s='%s'" "$key" "$value")"
	eval "export $key"
}

mkcd() {
	mkdir -p "$1"
	cd "$1"
}

respawn_daemon() {
	killall -q "$1" && fork "$@"
}

silent_fail_if_no_commmand() {
	for name in "$@" ; do
		[ -z "$(command -v "$name")" ] && exit
	done
}