diff options
Diffstat (limited to '.local/share/bin/mode')
l---------[-rwxr-xr-x] | .local/share/bin/mode | 128 |
1 files changed, 1 insertions, 127 deletions
diff --git a/.local/share/bin/mode b/.local/share/bin/mode index 6589b32..8b72998 100755..120000 --- a/.local/share/bin/mode +++ b/.local/share/bin/mode @@ -1,127 +1 @@ -#!/bin/sh -progname="$(basename "$0")" -stupid() { - echo "run \`$progname --help\` for options" >&2 -} -usage() { - cat << EOF -$progname -- switch between dark / light theme - -usage: - $progname [-chr] action - -options: - -c, --no-cfggen disable updating of configuration files - -h, --help display this help text - -r, --no-reload disable reloading of applications after applying theme - -actions: - dark switch to dark mode - light switch to light mode - restore switch to last set mode ($XDG_DATA_HOME/mode/active) - reload only reload applications, do not update configuration files - help same as --help option - -examples: - mode dark switch to dark mode and reload applications - mode restore --no-reload make sure all configuration files are up-to-date - mode reload only reload applications - -EOF -} - -get_color() { xrdb -get "$1" | tr -d '\n'; } -hex_to_rgb_array() { pastel format rgb "$1" | cut -c4- | tr '()' '[]' ; } -mix_rgb() { pastel mix --colorspace=RGB --fraction="$3" "$1" "$2" | pastel format hex ; } - -switch_xrdb() { - xrdb -override "$XDG_CONFIG_HOME/X11/$mode" - bg="$(get_color background)" - fg="$(get_color foreground)" - color0="$(get_color color0)" - color1="$(get_color color1)" - color2="$(get_color color2)" - color3="$(get_color color3)" - color4="$(get_color color4)" - color5="$(get_color color5)" - color6="$(get_color color6)" - color7="$(get_color color7)" - color8="$(get_color color8)" - color9="$(get_color color9)" - color10="$(get_color color10)" - color11="$(get_color color11)" - color12="$(get_color color12)" - color13="$(get_color color13)" - color14="$(get_color color14)" - color15="$(get_color color15)" - [ "$mode" == "light" ] && { - accent="$color15" - accent_text="$color0" - } - [ "$mode" == "dark" ] && { - accent="$(mix_rgb $bg $color0 0.5)" - accent_text="$fg" - } -} - -switch() { - echo "updating configuration files to $mode mode..." - - # xrdb needs to complete first, as the rest of the color schemes are derived - # from querying xrdb for colors - switch_xrdb $mode - - for switch_function in "$XDG_CONFIG_HOME"/mode/switch.d/* ; do - ! [ -x "$switch_function" ] && continue - . "$switch_function" & - done - - wait $(jobs -rp) -} - -reload() { - echo "reloading programs..." - - for reload_function in "$XDG_CONFIG_HOME"/mode/reload.d/* ; do - ! [ -x "$reload_function" ] && continue - . "$reload_function" & - done - - wait $(jobs -rp) -} - -run_cfggen=1 -run_reload=1 -mode="" - -for arg in "$@" ; do - case "$arg" in - --) break ;; - -h|--help|help) usage ; exit 0 ;; - dark|light) mode="$arg" ;; - restore) mode="$(cat "$XDG_DATA_HOME/mode/active")" ;; - reload) run_reload=1 run_cfggen=0 ;; - -r|--no-reload) run_reload=0 ;; - -c|--no-cfggen) run_cfggen=0 ;; - *) - echo "error: unknown argument: $arg" >&2 - stupid && exit 1 - ;; - esac -done - -if [ $run_cfggen -eq 1 ] && [ -z "$mode" ] ; then - echo "error: no action provided" >&2 - stupid && exit 1 -fi -case "$mode" in - dark|light) break ;; - *) - echo "error: $mode is not a valid mode" >&2 - stupid && exit 1 - ;; -esac - -[ $run_cfggen -eq 1 ] && switch $mode -[ $run_reload -eq 1 ] && reload - +../mode/bin/mode
\ No newline at end of file |