aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2024-03-07 20:03:03 +0100
committerlonkaars <loek@pipeframe.xyz>2024-03-07 20:03:03 +0100
commit7da4d3e228d932503f81fe03c2deb9c867405e23 (patch)
treee266246d7929393e72a0293c8a7cd57c17a48ce3
parentbb40701a55d5e23a4b0c7e5b1232802c596c083c (diff)
small fixes + optimization for khal scripts
-rwxr-xr-x.config/khal/config_gen9
-rwxr-xr-x.local/share/bin/khal6
2 files changed, 12 insertions, 3 deletions
diff --git a/.config/khal/config_gen b/.config/khal/config_gen
index 3777490..683cd17 100755
--- a/.config/khal/config_gen
+++ b/.config/khal/config_gen
@@ -17,19 +17,26 @@ TERMINAL_COLORS="$(for n in $(seq 0 15) ; do xrdb -get "color$n" ; done | _hexfm
_color_quantize() {
INPUT="$(echo $1 | grep -o '#[0-9a-fA-F]\{6\}' | _hexfmt)"
COLOR="$(printf '%s\n%s' "$INPUT" "$TERMINAL_COLORS" | awk --non-decimal-data '
+ # abs() is not built-in???
function abs(v) { return v < 0 ? -v : v }
BEGIN {
- closest = 0;
+ closest = 0; # closest ANSI color index
+ # max diff can at most be 3 * 255 (see diff calculation)
max_diff = 0xff * 3;
+ # offset line number once for input color, and another time to make color
+ # numbers start from 0 (line numbers start from 1 by default)
NR -= 2;
}
{
+ # first line of input contains input colors
if (NR == -1) {
input_r = $1;
input_g = $2;
input_b = $3;
next;
}
+ if (NR == 0) next; # do not pick background color
+ # sloppy check to nearest RGB color
diff = abs(input_r - $1) + abs(input_g - $2) + abs(input_b - $3);
if (diff < max_diff) {
max_diff = diff;
diff --git a/.local/share/bin/khal b/.local/share/bin/khal
index 23f188a..d417469 100755
--- a/.local/share/bin/khal
+++ b/.local/share/bin/khal
@@ -1,10 +1,12 @@
#!/bin/sh
CFG="$XDG_CONFIG_HOME/khal/config"
-cat - "$XDG_CONFIG_HOME/khal/base" << "EOF" > "$CFG"
+if [ "$CFG" -ot "$XDG_CONFIG_HOME/khal/config.sh" ] ; then
+ cat - "$XDG_CONFIG_HOME/khal/base" << "EOF" > "$CFG"
# THIS FILE IS AUTO-GENERATED, EDIT config_gen OR base INSTEAD!!!
EOF
-"$XDG_CONFIG_HOME/khal/config_gen" >> "$CFG"
+ "$XDG_CONFIG_HOME/khal/config_gen" >> "$CFG"
+fi
# aliases
[ "$1" == "i" ] && { shift ; set -- interactive "$@" ; }