diff options
l--------- | .local/share/bin/mode | 2 | ||||
-rw-r--r-- | .local/share/mode/lib/accent.sh | 10 | ||||
-rwxr-xr-x | .local/share/mode/mode (renamed from .local/share/mode/bin/mode) | 41 | ||||
-rw-r--r-- | .local/share/mode/plug.d/10_lib (renamed from .local/share/mode/lib/functions.sh) | 1 | ||||
-rw-r--r-- | .local/share/mode/plug.d/20_export_colors | 17 | ||||
-rw-r--r-- | .local/share/mode/plug.d/20_export_mode | 9 | ||||
-rw-r--r-- | .local/share/mode/plug.d/20_export_vim_theme | 6 | ||||
-rw-r--r-- | .local/share/mode/plug.d/50_accent | 16 | ||||
-rwxr-xr-x | .local/share/mode/switch.d/chromium | 2 | ||||
-rwxr-xr-x | .local/share/mode/switch.d/discord | 2 | ||||
-rw-r--r-- | .local/share/mode/themes/github-dark | 41 | ||||
-rw-r--r-- | .local/share/mode/themes/github-light | 41 |
12 files changed, 115 insertions, 73 deletions
diff --git a/.local/share/bin/mode b/.local/share/bin/mode index 8b72998..5a5c6d9 120000 --- a/.local/share/bin/mode +++ b/.local/share/bin/mode @@ -1 +1 @@ -../mode/bin/mode
\ No newline at end of file +../mode/mode
\ No newline at end of file diff --git a/.local/share/mode/lib/accent.sh b/.local/share/mode/lib/accent.sh deleted file mode 100644 index 45643eb..0000000 --- a/.local/share/mode/lib/accent.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -[ "$mode" == "light" ] && { - export accent="$color15" - export accent_text="$color0" -} -[ "$mode" == "dark" ] && { - export accent="$(mix_rgb $bg $color0 0.5)" - export accent_text="$fg" -} - diff --git a/.local/share/mode/bin/mode b/.local/share/mode/mode index a4e6947..06ec7dd 100755 --- a/.local/share/mode/bin/mode +++ b/.local/share/mode/mode @@ -1,6 +1,6 @@ #!/bin/sh progname="$(basename "$0")" -data="$(readlink -f "$(dirname "$(readlink -f "$0")")/..")" +data="$(dirname "$(readlink -f "$0")")" export data stupid() { @@ -22,9 +22,7 @@ actions: restore switch to last set theme ($XDG_CACHE_HOME/mode/state/theme) reload do not update configuration files, only reload applications help same as --help option - -themes: - $(ls "$data/themes" | tr '\n' ' ' | fold -sw 60) + list list all themes examples: mode dark switch to dark mode and reload applications @@ -34,32 +32,31 @@ examples: EOF } -. "$data/lib/functions.sh" - switch() { theme_path="$(readlink -f "$data/themes/$theme")" theme="$(basename "$theme_path")" echo "setting theme to $theme..." + # load theme colors + aux variables . "$theme_path" - case "$mode" in - dark|light) break ;; - *) - echo "error: theme $theme does not define a valid \$mode" >&2 - stupid && exit 1 - ;; - esac - export mode + # load plugins (available to switch.d scripts only) + for plugin in "$data"/plug.d/* ; do . "$plugin" ; done - # create accent color differently for dark/light mode - . "$data/lib/accent.sh" - + # generate new config files / snippets (in parallel) for switch_function in "$data"/switch.d/* ; do ! [ -x "$switch_function" ] && continue - "$switch_function" & + interpreter="$(basename "$(command -v $(head -n1 "$switch_function" | sed -n 's/^#!\(.*\)/\1/p'))")" + if [ "$interpreter" = "sh" ] ; then + # source scripts if they are POSIX sh (makes plugin functions available) + . "$switch_function" & + else + # else, just run them + "$switch_function" & + fi done + # join all processes started above wait $(jobs -rp) } @@ -84,6 +81,14 @@ for arg in "$@" ; do -h|--help|help) usage ; exit 0 ;; restore) theme="$(cat "$XDG_CACHE_HOME/mode/state/theme")" ;; reload) run_reload=1 run_cfggen=0 ;; + list) + find "$data/themes" -type f,l | while read -r theme ; do + printf '%s' "$(basename "$theme")" + link="$(readlink "$theme")" && printf ' (%s)' "$link" + printf '\n' + done + exit 0 + ;; -r|--no-reload) run_reload=0 ;; -c|--no-cfggen) run_cfggen=0 ;; *) diff --git a/.local/share/mode/lib/functions.sh b/.local/share/mode/plug.d/10_lib index c7212e4..61817bc 100644 --- a/.local/share/mode/lib/functions.sh +++ b/.local/share/mode/plug.d/10_lib @@ -1,4 +1,5 @@ #!/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 ; } diff --git a/.local/share/mode/plug.d/20_export_colors b/.local/share/mode/plug.d/20_export_colors new file mode 100644 index 0000000..017446d --- /dev/null +++ b/.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 + eval "export $1" +} +for color in $(seq 0 15 | sed 's/^/color/') bg fg ; do + check_color $color +done + diff --git a/.local/share/mode/plug.d/20_export_mode b/.local/share/mode/plug.d/20_export_mode new file mode 100644 index 0000000..78432b6 --- /dev/null +++ b/.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 +export mode + diff --git a/.local/share/mode/plug.d/20_export_vim_theme b/.local/share/mode/plug.d/20_export_vim_theme new file mode 100644 index 0000000..be76b8b --- /dev/null +++ b/.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 +export vim_theme_name diff --git a/.local/share/mode/plug.d/50_accent b/.local/share/mode/plug.d/50_accent new file mode 100644 index 0000000..6e0aa73 --- /dev/null +++ b/.local/share/mode/plug.d/50_accent @@ -0,0 +1,16 @@ +#!/bin/sh +# create accent color differently for dark/light mode + +# do not generate accent color if already explicitly defined by theme +[ -n "$accent" ] && return + +[ "$mode" == "light" ] && { + accent="$color15" + accent_text="$color0" +} +[ "$mode" == "dark" ] && { + accent="$(mix_rgb $bg $color0 0.5)" + accent_text="$fg" +} + +export accent accent_text diff --git a/.local/share/mode/switch.d/chromium b/.local/share/mode/switch.d/chromium index 5f4f342..6ccfca6 100755 --- a/.local/share/mode/switch.d/chromium +++ b/.local/share/mode/switch.d/chromium @@ -1,6 +1,4 @@ #!/bin/sh -. "$XDG_DATA_HOME/mode/lib/functions.sh" - PREFIX="$XDG_CACHE_HOME/mode/chromium" mkdir -p "$PREFIX" diff --git a/.local/share/mode/switch.d/discord b/.local/share/mode/switch.d/discord index 2a08662..f656783 100755 --- a/.local/share/mode/switch.d/discord +++ b/.local/share/mode/switch.d/discord @@ -1,6 +1,4 @@ #!/bin/sh -. "$data/lib/functions.sh" - cat << EOF > "$XDG_CONFIG_HOME/BetterDiscord/themes/mode.theme.css" /** * @name mode diff --git a/.local/share/mode/themes/github-dark b/.local/share/mode/themes/github-dark index f2113a8..577106c 100644 --- a/.local/share/mode/themes/github-dark +++ b/.local/share/mode/themes/github-dark @@ -1,24 +1,25 @@ #!/bin/sh -export mode='dark' +mode=dark -export color0='#484f58' -export color1='#ffa198' -export color2='#56d364' -export color3='#e3b341' -export color4='#79c0ff' -export color5='#d2a8ff' -export color6='#56d4dd' -export color7='#b1bac4' -export color8='#6e7681' -export color9='#ff7b72' -export color10='#3fb950' -export color11='#d29922' -export color12='#58a6ff' -export color13='#bc8cff' -export color14='#39c5cf' -export color15='#ffffff' +color0='#484f58' +color1='#ffa198' +color2='#56d364' +color3='#e3b341' +color4='#79c0ff' +color5='#d2a8ff' +color6='#56d4dd' +color7='#b1bac4' +color8='#6e7681' +color9='#ff7b72' +color10='#3fb950' +color11='#d29922' +color12='#58a6ff' +color13='#bc8cff' +color14='#39c5cf' +color15='#ffffff' -export bg='#0d1117' -export fg='#e6edf3' +bg='#0d1117' +fg='#e6edf3' + +vim_theme_name='ghdark' -export vim_theme_name='ghdark' diff --git a/.local/share/mode/themes/github-light b/.local/share/mode/themes/github-light index d4a5c28..d0162f8 100644 --- a/.local/share/mode/themes/github-light +++ b/.local/share/mode/themes/github-light @@ -1,24 +1,25 @@ #!/bin/sh -export mode='light' +mode=light -export color0='#d1d5da' -export color1='#cb2431' -export color2='#22863a' -export color3='#b08800' -export color4='#005cc5' -export color5='#5a32a3' -export color6='#3192aa' -export color7='#6a737d' -export color8='#959da5' -export color9='#d73a49' -export color10='#28a745' -export color11='#dbab09' -export color12='#0366d6' -export color13='#5a32a3' -export color14='#1b7c83' -export color15='#24292e' +color0='#d1d5da' +color1='#cb2431' +color2='#22863a' +color3='#b08800' +color4='#005cc5' +color5='#5a32a3' +color6='#3192aa' +color7='#6a737d' +color8='#959da5' +color9='#d73a49' +color10='#28a745' +color11='#dbab09' +color12='#0366d6' +color13='#5a32a3' +color14='#1b7c83' +color15='#24292e' -export bg='#ffffff' -export fg='#24292e' +bg='#ffffff' +fg='#24292e' + +vim_theme_name='github-light' -export vim_theme_name='github-light' |