diff options
| author | Loek Le Blansch <loek@pipeframe.xyz> | 2026-08-02 14:48:29 +0200 |
|---|---|---|
| committer | Loek Le Blansch <loek@pipeframe.xyz> | 2026-08-02 14:48:29 +0200 |
| commit | e43eb1177872f52e949fb5f0f93396ed94b0d093 (patch) | |
| tree | 78b73af6a989fa2996d71b112e161b70d35081ef /home/dot_local/share/mode/plug.d | |
| parent | 2f14a896e4b897bd747c24d7ad8e9e7bb3237d03 (diff) | |
move to chezmoi
Diffstat (limited to 'home/dot_local/share/mode/plug.d')
| -rw-r--r-- | home/dot_local/share/mode/plug.d/10_lib | 46 | ||||
| -rw-r--r-- | home/dot_local/share/mode/plug.d/20_export_colors | 17 | ||||
| -rw-r--r-- | home/dot_local/share/mode/plug.d/20_export_mode | 9 | ||||
| -rw-r--r-- | home/dot_local/share/mode/plug.d/20_export_vim_theme | 6 | ||||
| -rw-r--r-- | home/dot_local/share/mode/plug.d/50_accent | 15 |
5 files changed, 93 insertions, 0 deletions
diff --git a/home/dot_local/share/mode/plug.d/10_lib b/home/dot_local/share/mode/plug.d/10_lib new file mode 100644 index 0000000..b3a0276 --- /dev/null +++ b/home/dot_local/share/mode/plug.d/10_lib @@ -0,0 +1,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 +} + diff --git a/home/dot_local/share/mode/plug.d/20_export_colors b/home/dot_local/share/mode/plug.d/20_export_colors new file mode 100644 index 0000000..0f53d1f --- /dev/null +++ b/home/dot_local/share/mode/plug.d/20_export_colors @@ -0,0 +1,17 @@ +#!/bin/sh +# colors must be #RRGGBB +check_color() { + ( + eval "color=\"\${$1}\"" + exit "$(echo "$color" | sed -n '/^#[0-9a-fA-F]\{6\}$/p' | wc -l)" + ) + if [ $? -ne 1 ] ; then + echo "error: color $1 is not properly formatted (#RRGGBB)" + stupid && exit 1 + fi + themevar "$1" +} +for color in $(seq 0 15 | sed 's/^/color/') bg fg ; do + check_color $color +done + diff --git a/home/dot_local/share/mode/plug.d/20_export_mode b/home/dot_local/share/mode/plug.d/20_export_mode new file mode 100644 index 0000000..c82c4e1 --- /dev/null +++ b/home/dot_local/share/mode/plug.d/20_export_mode @@ -0,0 +1,9 @@ +#!/bin/sh +# $mode = "light" | "dark" +if [ "$mode" != 'dark' ] && [ "$mode" != 'light' ] ; then + pastel format hsl-lightness "$bg" | awk '{ exit($1 > 0.5) }' + [ $? -eq 0 ] && mode=dark || mode=light + echo "warn: theme $theme did not define \$mode as \"light\" or \"dark\", guessed $mode" >&2 +fi +themevar mode + diff --git a/home/dot_local/share/mode/plug.d/20_export_vim_theme b/home/dot_local/share/mode/plug.d/20_export_vim_theme new file mode 100644 index 0000000..12304f3 --- /dev/null +++ b/home/dot_local/share/mode/plug.d/20_export_vim_theme @@ -0,0 +1,6 @@ +#!/bin/sh +# warn if the vim theme is not installed +if [ "$(find "$XDG_CONFIG_HOME/nvim" -name "$vim_theme_name.vim" | wc -l)" -eq 0 ] ; then + echo "warn: vim theme $vim_theme_name does not appear to be installed" >&2 +fi +themevar vim_theme_name diff --git a/home/dot_local/share/mode/plug.d/50_accent b/home/dot_local/share/mode/plug.d/50_accent new file mode 100644 index 0000000..ceb3209 --- /dev/null +++ b/home/dot_local/share/mode/plug.d/50_accent @@ -0,0 +1,15 @@ +#!/bin/sh +# create accent color differently for dark/light mode + +# do not generate accent color if already explicitly defined by theme +[ -n "$accent" ] && return + +if [ "$mode" = "light" ] ; then + themevar accent "$color15" + themevar accent_text "$color0" +fi +if [ "$mode" = "dark" ] ; then + themevar accent "$(mix_rgb $bg $color0 0.5)" + themevar accent_text "$fg" +fi + |