giving the home PC config a bit of TLC
This commit is contained in:
@ -1,7 +1,56 @@
|
||||
#!/bin/zsh
|
||||
use desktop/colorscheme --group dotwryn
|
||||
use desktop/xorg/i3 --group dotwryn
|
||||
#####################################################################
|
||||
|
||||
USAGE__options+="
|
||||
-t, --theme one of the available color themes
|
||||
-l, --list-themes show available color themes and exit
|
||||
|
||||
--only only set the theme for a specific terminal/application
|
||||
($COLORSCHEME__SUPPORTED_CONFIG_TYPES)
|
||||
"
|
||||
|
||||
USAGE__args+='
|
||||
\$1 shorthand for "--theme \$1"
|
||||
'
|
||||
|
||||
USAGE__description+='
|
||||
Generates source-controlled config files for the selected theme.
|
||||
By default, generates all possible config types to provide a
|
||||
consistent, system-wide theme.
|
||||
|
||||
Due to complexities with i3wm colorscheme management, it is not
|
||||
possible to update i3wm colorscheme files when using the "--only"
|
||||
flag.
|
||||
'
|
||||
|
||||
|
||||
#####################################################################
|
||||
|
||||
MAIN() {
|
||||
SET_THEME $@
|
||||
local ARGS=() UPDATE_I3_CONFIG=true
|
||||
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
case $1 in
|
||||
--only )
|
||||
ARGS+=($1)
|
||||
UPDATE_I3_CONFIG=false
|
||||
;;
|
||||
|
||||
* ) ARGS+=($1) ;;
|
||||
esac
|
||||
shift 1
|
||||
done
|
||||
|
||||
SET_THEME ${ARGS[@]} \
|
||||
|| ERROR 'failed to set theme (see above)' \
|
||||
|| return 1
|
||||
|
||||
[[ $UPDATE_I3_CONFIG =~ true ]] || return 0
|
||||
|
||||
I3__GENERATE_CUSTOM_CONFIG \
|
||||
|| ERROR 'failed to update i3 config (see above)' \
|
||||
|| return 1
|
||||
}
|
||||
|
12
scwrypts/dotwryn/desktop/xorg/i3/generate-config
Executable file
12
scwrypts/dotwryn/desktop/xorg/i3/generate-config
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/zsh
|
||||
use desktop/xorg/i3 --group dotwryn
|
||||
|
||||
#####################################################################
|
||||
|
||||
I3__GENERATE_CUSTOM_CONFIG__USAGE
|
||||
|
||||
MAIN() {
|
||||
I3__GENERATE_CUSTOM_CONFIG
|
||||
}
|
||||
|
||||
#####################################################################
|
@ -1,5 +1,5 @@
|
||||
#!/bin/zsh
|
||||
use desktop/xrandr --group dotwryn
|
||||
use desktop/xorg/xrandr --group dotwryn
|
||||
#####################################################################
|
||||
|
||||
MAIN() {
|
@ -1,291 +0,0 @@
|
||||
#####################################################################
|
||||
|
||||
DEPENDENCIES+=(awk sed tr)
|
||||
REQUIRED_ENV+=()
|
||||
|
||||
#####################################################################
|
||||
|
||||
_COLORSCHEME_DIR="$DOTWRYN/colorschemes"
|
||||
|
||||
ACTIVE_THEME_NAME='main'
|
||||
ACTIVE_THEME="$_COLORSCHEME_DIR/active.$ACTIVE_THEME_NAME"
|
||||
|
||||
GET_COLORSCHEME_HEX() {
|
||||
[ ! $USAGE ] && USAGE="
|
||||
usage: ...args... [...options...]
|
||||
|
||||
options:
|
||||
-h, --help show this dialogue and exit
|
||||
|
||||
args:
|
||||
\$1 [0-15] gets the indicated color by ANSI color number
|
||||
background gets the background color
|
||||
foreground gets the foreground color
|
||||
cursor gets the cursor color
|
||||
all sets all theme variables (returns nothing)
|
||||
"
|
||||
|
||||
local ARGS=()
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
case $1 in
|
||||
-h | --help ) USAGE; return 0;;
|
||||
|
||||
all ) ARGS=(all); break ;;
|
||||
|
||||
* ) ARGS+=($1) ;;
|
||||
esac
|
||||
shift 1
|
||||
done
|
||||
|
||||
[[ ${#ARGS[@]} -gt 0 ]] || ERROR 'must provide at least one color lookup'
|
||||
|
||||
CHECK_ERRORS || return 1
|
||||
|
||||
##########################################
|
||||
|
||||
local PATTERN
|
||||
|
||||
for A in ${ARGS[@]}
|
||||
do
|
||||
case $A in
|
||||
all )
|
||||
FOREGROUND=$(GET_COLORSCHEME_HEX foreground)
|
||||
BACKGROUND=$(GET_COLORSCHEME_HEX background)
|
||||
|
||||
CURSOR=$(GET_COLORSCHEME_HEX cursor)
|
||||
|
||||
BLACK=$(GET_COLORSCHEME_HEX 0)
|
||||
RED=$(GET_COLORSCHEME_HEX 1)
|
||||
GREEN=$(GET_COLORSCHEME_HEX 2)
|
||||
YELLOW=$(GET_COLORSCHEME_HEX 3)
|
||||
BLUE=$(GET_COLORSCHEME_HEX 4)
|
||||
MAGENTA=$(GET_COLORSCHEME_HEX 5)
|
||||
CYAN=$(GET_COLORSCHEME_HEX 6)
|
||||
WHITE=$(GET_COLORSCHEME_HEX 7)
|
||||
|
||||
BRIGHT_BLACK=$(GET_COLORSCHEME_HEX 8 )
|
||||
BRIGHT_RED=$(GET_COLORSCHEME_HEX 9 )
|
||||
BRIGHT_GREEN=$(GET_COLORSCHEME_HEX 10)
|
||||
BRIGHT_YELLOW=$(GET_COLORSCHEME_HEX 11)
|
||||
BRIGHT_BLUE=$(GET_COLORSCHEME_HEX 12)
|
||||
BRIGHT_MAGENTA=$(GET_COLORSCHEME_HEX 13)
|
||||
BRIGHT_CYAN=$(GET_COLORSCHEME_HEX 14)
|
||||
BRIGHT_WHITE=$(GET_COLORSCHEME_HEX 15)
|
||||
|
||||
return 0
|
||||
;;
|
||||
|
||||
foreground | background | cursor ) PATTERN="^$A " ;;
|
||||
|
||||
* ) : \
|
||||
&& [ $A ] && [[ $A -le 15 ]] && [[ $A -ge 0 ]] \
|
||||
|| { ERROR 'must provide ANSI color number 0-15'; return 1; }
|
||||
|
||||
PATTERN="^color$A "
|
||||
;;
|
||||
esac
|
||||
|
||||
grep "$PATTERN" "$ACTIVE_THEME" \
|
||||
| awk '{print $2}' \
|
||||
| sed 's/ //g; s/#//g' \
|
||||
| tr '[:lower:]' '[:upper:]' \
|
||||
;
|
||||
done
|
||||
}
|
||||
|
||||
SET_THEME() {
|
||||
[ ! $USAGE ] && USAGE="
|
||||
usage: [...options...]
|
||||
|
||||
options:
|
||||
-t, --theme one of the available color themes
|
||||
-l, --list-themes show available color themes and exit
|
||||
|
||||
--only only set the theme for a specific terminal (alacritty kitty tty)
|
||||
|
||||
-h, --help show this dialogue and exit
|
||||
|
||||
generate all source-controlled theme files then link them to the
|
||||
appropriate local theme file to immediately update terminal themes
|
||||
"
|
||||
local SOURCE_THEME EMULATOR
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
case $1 in
|
||||
-t | --theme ) THEME_NAME=$2; shift 1 ;;
|
||||
|
||||
-l | --list-themes ) _LIST_THEMES; return 0 ;;
|
||||
|
||||
--only )
|
||||
EMULATOR=$2; shift 1
|
||||
command -v _SET_THEME__$EMULATOR >/dev/null 2>&1 \
|
||||
|| ERROR "terminal emulator '$EMULATOR' not supported"
|
||||
;;
|
||||
|
||||
-h | --help ) USAGE; return 0 ;;
|
||||
|
||||
* ) ERROR "unknown argument '$1'"
|
||||
esac
|
||||
shift 1
|
||||
done
|
||||
|
||||
CHECK_ERRORS || return 1
|
||||
|
||||
##########################################
|
||||
|
||||
[ $THEME_NAME ] || THEME_NAME=$(_LIST_THEMES | FZF 'select a theme')
|
||||
[ $THEME_NAME ] || ABORT
|
||||
|
||||
local THEME="$_COLORSCHEME_DIR/$THEME_NAME.conf"
|
||||
[ -f "$THEME" ] || FAIL 1 "no such theme '$THEME_NAME'"
|
||||
|
||||
|
||||
##########################################
|
||||
|
||||
STATUS "updating theme $ACTIVE_THEME_NAME" \
|
||||
&& ln -sf "$THEME" "$ACTIVE_THEME" \
|
||||
&& SUCCESS "theme $ACTIVE_THEME_NAME set to '$THEME_NAME'" \
|
||||
|| FAIL 2 "unable to set theme $ACTIVE_THEME_NAME to '$THEME_NAME'"
|
||||
|
||||
local EMULATORS=(alacritty kitty getty)
|
||||
[ $EMULATOR ] && EMULATORS=($EMULATOR)
|
||||
|
||||
GET_COLORSCHEME_HEX all
|
||||
for EMULATOR in ${EMULATORS[@]}
|
||||
do
|
||||
STATUS "updating $EMULATOR theme to use $ACTIVE_THEME_NAME" \
|
||||
&& _GENERATE_THEME__$EMULATOR \
|
||||
&& _SET_THEME__$EMULATOR \
|
||||
&& SUCCESS "emulator $EMULATOR successfully set to $ACTIVE_THEME_NAME" \
|
||||
|| ERROR "error setting theme $ACTIVE_THEME_NAME for $EMULATOR"
|
||||
|
||||
[[ $EMULATOR =~ ^getty$ ]] && [[ $TERM =~ ^linux$ ]] && {
|
||||
STATUS 'loading getty theme now' \
|
||||
&& NO_CLEAR=1 source "$ACTIVE_THEME.getty" \
|
||||
&& SUCCESS 'getty theme loaded' \
|
||||
|| ERROR 'getty theme loading error (see above)'
|
||||
}
|
||||
done
|
||||
|
||||
CHECK_ERRORS --no-usage
|
||||
}
|
||||
|
||||
#####################################################################
|
||||
|
||||
_LIST_THEMES() {
|
||||
ls "$_COLORSCHEME_DIR" | grep '.conf$' | sed 's/.conf$//'
|
||||
}
|
||||
|
||||
#####################################################################
|
||||
|
||||
_GENERATE_THEME__alacritty() {
|
||||
STATUS "generating $ACTIVE_THEME_NAME.alacritty"
|
||||
echo "# do not edit; generated by scwrypts
|
||||
[colors.cursor]
|
||||
cursor = '0x$CURSOR'
|
||||
|
||||
[colors.primary]
|
||||
background = '0x$BACKGROUND'
|
||||
foreground = '0x$FOREGROUND'
|
||||
|
||||
[colors.normal]
|
||||
black = '0x$BLACK'
|
||||
red = '0x$RED'
|
||||
green = '0x$GREEN'
|
||||
yellow = '0x$YELLOW'
|
||||
blue = '0x$BLUE'
|
||||
magenta = '0x$MAGENTA'
|
||||
cyan = '0x$CYAN'
|
||||
white = '0x$WHITE'
|
||||
|
||||
[colors.bright]
|
||||
black = '0x$BRIGHT_BLACK'
|
||||
red = '0x$BRIGHT_RED'
|
||||
green = '0x$BRIGHT_GREEN'
|
||||
yellow = '0x$BRIGHT_YELLOW'
|
||||
blue = '0x$BRIGHT_BLUE'
|
||||
magenta = '0x$BRIGHT_MAGENTA'
|
||||
cyan = '0x$BRIGHT_CYAN'
|
||||
white = '0x$BRIGHT_WHITE'
|
||||
" | sed '$d' > "$ACTIVE_THEME.alacritty"
|
||||
|
||||
# backwards yaml compatibility
|
||||
echo "--- # yamllint disable rule:colons
|
||||
# do not edit; generated by scwrypts
|
||||
colors:
|
||||
primary:
|
||||
background: '0x$BACKGROUND'
|
||||
foreground: '0x$FOREGROUND'
|
||||
cursor:
|
||||
cursor: '0x$CURSOR'
|
||||
normal:
|
||||
black: '0x$BLACK'
|
||||
red: '0x$RED'
|
||||
green: '0x$GREEN'
|
||||
yellow: '0x$YELLOW'
|
||||
blue: '0x$BLUE'
|
||||
magenta: '0x$MAGENTA'
|
||||
cyan: '0x$CYAN'
|
||||
white: '0x$WHITE'
|
||||
bright:
|
||||
black: '0x$BRIGHT_BLACK'
|
||||
red: '0x$BRIGHT_RED'
|
||||
green: '0x$BRIGHT_GREEN'
|
||||
yellow: '0x$BRIGHT_YELLOW'
|
||||
blue: '0x$BRIGHT_BLUE'
|
||||
magenta: '0x$BRIGHT_MAGENTA'
|
||||
cyan: '0x$BRIGHT_CYAN'
|
||||
white: '0x$BRIGHT_WHITE'
|
||||
" | sed '$d' > "$ACTIVE_THEME.alacritty.yml"
|
||||
}
|
||||
|
||||
_SET_THEME__alacritty() {
|
||||
ln -sf "$ACTIVE_THEME.alacritty" "$HOME/.config/alacritty/theme.toml"
|
||||
ln -sf "$ACTIVE_THEME.alacritty.yml" "$HOME/.config/alacritty/theme.yml" # backwards yaml compatibility
|
||||
}
|
||||
|
||||
#####################################################################
|
||||
|
||||
_GENERATE_THEME__kitty() {
|
||||
return 0 # existing theme is compatible with kitty
|
||||
}
|
||||
|
||||
_SET_THEME__kitty() {
|
||||
local LOCAL_THEME="$HOME/.config/kitty/theme.conf"
|
||||
ln -sf "$ACTIVE_THEME" "$LOCAL_THEME"
|
||||
}
|
||||
|
||||
#####################################################################
|
||||
|
||||
_GENERATE_THEME__getty() {
|
||||
echo "#!/bin/sh
|
||||
# source this file to apply colorscheme to linux getty
|
||||
[[ \"\$TERM\" =~ ^linux$ ]] || return 0
|
||||
|
||||
/bin/echo -e \" \
|
||||
\\e]P0$BACKGROUND \
|
||||
\\e]P1$RED \
|
||||
\\e]P2$GREEN \
|
||||
\\e]P3$YELLOW \
|
||||
\\e]P4$BLUE \
|
||||
\\e]P5$MAGENTA \
|
||||
\\e]P6$CYAN \
|
||||
\\e]P7$FOREGROUND \
|
||||
\\e]P8$BRIGHT_RED \
|
||||
\\e]P9$BRIGHT_GREEN \
|
||||
\\e]PA$BRIGHT_YELLOW \
|
||||
\\e]PB$BRIGHT_BLUE \
|
||||
\\e]PC$BRIGHT_MAGENTA \
|
||||
\\e]PD$BRIGHT_CYAN \
|
||||
\\e]PE$WHITE \
|
||||
\\e]PF$BRIGHT_WHITE \
|
||||
\"
|
||||
[ ! \$NO_CLEAR ] && clear
|
||||
return 0" > "$ACTIVE_THEME.getty"
|
||||
}
|
||||
|
||||
_SET_THEME__getty() {
|
||||
local LOCAL_THEME="$HOME/.config/wryn/tty-colorscheme"
|
||||
ln -sf "$ACTIVE_THEME.getty" "$LOCAL_THEME"
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
_COLORSCHEME_FILE__alacritty_toml="$ACTIVE_THEME_PATH/alacritty.toml"
|
||||
_COLORSCHEME_FILE__alacritty_yaml="$ACTIVE_THEME_PATH/alacritty.yaml"
|
||||
|
||||
_GENERATE_THEME__alacritty() {
|
||||
echo "# do not edit; generated by scwrypts
|
||||
# theme : $THEME_NAME
|
||||
[colors.cursor]
|
||||
cursor = '0x$CURSOR'
|
||||
|
||||
[colors.primary]
|
||||
background = '0x$BACKGROUND'
|
||||
foreground = '0x$FOREGROUND'
|
||||
|
||||
[colors.normal]
|
||||
black = '0x$BLACK'
|
||||
red = '0x$RED'
|
||||
green = '0x$GREEN'
|
||||
yellow = '0x$YELLOW'
|
||||
blue = '0x$BLUE'
|
||||
magenta = '0x$MAGENTA'
|
||||
cyan = '0x$CYAN'
|
||||
white = '0x$WHITE'
|
||||
|
||||
[colors.bright]
|
||||
black = '0x$BRIGHT_BLACK'
|
||||
red = '0x$BRIGHT_RED'
|
||||
green = '0x$BRIGHT_GREEN'
|
||||
yellow = '0x$BRIGHT_YELLOW'
|
||||
blue = '0x$BRIGHT_BLUE'
|
||||
magenta = '0x$BRIGHT_MAGENTA'
|
||||
cyan = '0x$BRIGHT_CYAN'
|
||||
white = '0x$BRIGHT_WHITE'
|
||||
" | sed '$d' > "$_COLORSCHEME_FILE__alacritty_toml"
|
||||
|
||||
# backwards yaml compatibility
|
||||
echo "--- # yamllint disable rule:colons
|
||||
# do not edit; generated by scwrypts
|
||||
# theme : $THEME_NAME
|
||||
colors:
|
||||
primary:
|
||||
background: '0x$BACKGROUND'
|
||||
foreground: '0x$FOREGROUND'
|
||||
cursor:
|
||||
cursor: '0x$CURSOR'
|
||||
normal:
|
||||
black: '0x$BLACK'
|
||||
red: '0x$RED'
|
||||
green: '0x$GREEN'
|
||||
yellow: '0x$YELLOW'
|
||||
blue: '0x$BLUE'
|
||||
magenta: '0x$MAGENTA'
|
||||
cyan: '0x$CYAN'
|
||||
white: '0x$WHITE'
|
||||
bright:
|
||||
black: '0x$BRIGHT_BLACK'
|
||||
red: '0x$BRIGHT_RED'
|
||||
green: '0x$BRIGHT_GREEN'
|
||||
yellow: '0x$BRIGHT_YELLOW'
|
||||
blue: '0x$BRIGHT_BLUE'
|
||||
magenta: '0x$BRIGHT_MAGENTA'
|
||||
cyan: '0x$BRIGHT_CYAN'
|
||||
white: '0x$BRIGHT_WHITE'
|
||||
" | sed '$d' > "$_COLORSCHEME_FILE__alacritty_yaml"
|
||||
}
|
||||
|
||||
_SET_THEME__alacritty() {
|
||||
ln -sf "$_COLORSCHEME_FILE__alacritty_toml" "$HOME/.config/alacritty/theme.toml"
|
||||
ln -sf "$_COLORSCHEME_FILE__alacritty_yaml" "$HOME/.config/alacritty/theme.yml"
|
||||
}
|
257
scwrypts/dotwryn/lib/desktop/colorscheme/colorscheme.module.zsh
Normal file
257
scwrypts/dotwryn/lib/desktop/colorscheme/colorscheme.module.zsh
Normal file
@ -0,0 +1,257 @@
|
||||
#####################################################################
|
||||
|
||||
_COLORSCHEME_DIR="$DOTWRYN/colorschemes"
|
||||
|
||||
ACTIVE_THEME_PATH="$_COLORSCHEME_DIR/active"
|
||||
ACTIVE_THEME_SOURCE="$ACTIVE_THEME_PATH/source.yaml"
|
||||
|
||||
use desktop/colorscheme/alacritty --group dotwryn
|
||||
use desktop/colorscheme/getty --group dotwryn
|
||||
use desktop/colorscheme/kitty --group dotwryn
|
||||
use desktop/colorscheme/polybar --group dotwryn
|
||||
use desktop/colorscheme/rofi --group dotwryn
|
||||
|
||||
COLORSCHEME__SUPPORTED_CONFIG_TYPES=($(typeset -f + | sed -n 's/^_GENERATE_THEME__//p'))
|
||||
|
||||
DEFAULT_MATERIAL_REFERENCES="$ACTIVE_THEME_PATH/default.yaml"
|
||||
|
||||
DEPENDENCIES+=(sed yq)
|
||||
|
||||
#####################################################################
|
||||
|
||||
MAX_LOOKUP_RECURSION=10
|
||||
GET_COLORSCHEME_HEX() {
|
||||
[ ! $USAGE ] && USAGE="
|
||||
usage: ...args... [...options...]
|
||||
|
||||
options:
|
||||
-t, --theme get the colorscheme value for the indicated theme source
|
||||
-l, --list-themes show available color themes and exit
|
||||
|
||||
args:
|
||||
An ordered list of colorscheme lookup terms. The first term is preferred, and
|
||||
subsequent lookup terms are used as fallback.
|
||||
|
||||
Some special terms are allowed (typically for compatibility); however,
|
||||
these should be simple yq queries from the 'colorscheme/\$THEME_NAME.yaml'
|
||||
(e.g. '.ansi.red.bright')
|
||||
|
||||
Special terms:
|
||||
[0-15] : lookup by ANSI color number
|
||||
compatibility : foreground | background | cursor | selection_foreground | selection_background
|
||||
"
|
||||
|
||||
local THEME_NAME='current active theme'
|
||||
local THEME_SOURCE="$ACTIVE_THEME_SOURCE"
|
||||
local ARGS=()
|
||||
local LOOKUPS=()
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
case $1 in
|
||||
-t | --theme )
|
||||
THEME_NAME=$2; shift 1
|
||||
THEME_SOURCE="$_COLORSCHEME_DIR/$THEME_NAME.yaml"
|
||||
[ -f "$THEME_SOURCE" ] \
|
||||
|| ERROR "no such theme '$THEME_NAME' exists"
|
||||
;;
|
||||
|
||||
-l | --list-themes ) _LIST_THEMES; return 0 ;;
|
||||
|
||||
[0-9] | 1[0-5] ) LOOKUPS+=($(_GET_YAML_LOOKUP_FOR_ANSI_COLOR $1)) ;;
|
||||
|
||||
foreground ) LOOKUPS+=(.foreground .ansi.gray.black) ;;
|
||||
background ) LOOKUPS+=(.background .ansi.gray.white) ;;
|
||||
cursor ) LOOKUPS+=(.cursor .ansi.gray.white) ;;
|
||||
selection_foreground ) LOOKUPS+=(.selection.foreground .background ) ;;
|
||||
selection_background ) LOOKUPS+=(.selection.background .foreground ) ;;
|
||||
|
||||
* ) LOOKUPS+=("$1") ;;
|
||||
esac
|
||||
shift 1
|
||||
done
|
||||
|
||||
[[ ${#LOOKUPS[@]} -gt 0 ]] \
|
||||
|| ERROR 'must provide at least one color lookup'
|
||||
|
||||
CHECK_ERRORS --no-fail || return 1
|
||||
|
||||
##########################################
|
||||
|
||||
local LOOKUP VALUE
|
||||
local I INIT
|
||||
for LOOKUP in ${LOOKUPS[@]}
|
||||
do
|
||||
I=0 INIT=$LOOKUP
|
||||
while true
|
||||
do
|
||||
((I+=1))
|
||||
VALUE=$(YQ eval-all '. as $item ireduce ({}; . * $item)' "$DEFAULT_MATERIAL_REFERENCES" "$THEME_SOURCE" | YQ -r $LOOKUP)
|
||||
DEBUG "looking up $LOOKUP : $VALUE"
|
||||
case $VALUE in
|
||||
.* ) LOOKUP=$VALUE ;;
|
||||
* ) break ;;
|
||||
esac
|
||||
[[ $I -ge $MAX_LOOKUP_RECURSION ]] && {
|
||||
VALUE=null
|
||||
WARNING "max recursive depth reached for '$INIT'"
|
||||
break
|
||||
}
|
||||
done
|
||||
|
||||
[[ $VALUE =~ null ]] && continue
|
||||
[[ $VALUE =~ ^$ ]] && continue
|
||||
break
|
||||
done
|
||||
|
||||
[[ $VALUE =~ null ]] && {
|
||||
ERROR "color lookup error for '$LOOKUPS'"
|
||||
return 1
|
||||
}
|
||||
|
||||
echo $VALUE | sed 's/^#//'
|
||||
}
|
||||
|
||||
SET_THEME() {
|
||||
[ ! $USAGE ] && USAGE="
|
||||
usage: [...options...]
|
||||
|
||||
options:
|
||||
-t, --theme one of the available color themes
|
||||
-l, --list-themes show available color themes and exit
|
||||
|
||||
--only only set the theme for a specific terminal/application
|
||||
($COLORSCHEME__SUPPORTED_CONFIG_TYPES)
|
||||
|
||||
-h, --help show this dialogue and exit
|
||||
|
||||
args:
|
||||
\$1 shorthand for '--theme \$1'
|
||||
|
||||
generate all source-controlled theme files then link them to the
|
||||
appropriate local theme file to immediately update terminal themes
|
||||
|
||||
Note : 'i3wm colorscheme' configuration is supported but must be performed
|
||||
through the 'desktop/xorg/i3 --group dotwryn' module due to
|
||||
some odd complexity
|
||||
"
|
||||
local THEME_NAME CONFIG_TYPE
|
||||
local UPDATE_ACTIVE_THEME=true
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
case $1 in
|
||||
-t | --theme ) THEME_NAME=$2; shift 1 ;;
|
||||
-l | --list-themes ) _LIST_THEMES; return 0 ;;
|
||||
|
||||
--only )
|
||||
UPDATE_ACTIVE_THEME=false
|
||||
CONFIG_TYPE=$2; shift 1
|
||||
command -v _SET_THEME__$CONFIG_TYPE >/dev/null 2>&1 \
|
||||
|| ERROR "configuration for '$CONFIG_TYPE' not supported"
|
||||
;;
|
||||
|
||||
-h | --help ) USAGE; return 0 ;;
|
||||
|
||||
* ) [ ! $THEME_NAME ] \
|
||||
&& THEME_NAME=$1 \
|
||||
|| ERROR "unknown argument '$1'" \
|
||||
;
|
||||
esac
|
||||
shift 1
|
||||
done
|
||||
|
||||
CHECK_ERRORS --no-fail || return 1
|
||||
|
||||
##########################################
|
||||
|
||||
[ $THEME_NAME ] || THEME_NAME=$(_LIST_THEMES | FZF 'select a theme')
|
||||
[ $THEME_NAME ] || ABORT
|
||||
|
||||
local SOURCE_THEME="$_COLORSCHEME_DIR/$THEME_NAME.yaml"
|
||||
[ -f "$SOURCE_THEME" ] \
|
||||
|| ERROR "no such theme '$THEME_NAME'" \
|
||||
|| return 1
|
||||
|
||||
##########################################
|
||||
|
||||
[[ $UPDATE_ACTIVE_THEME =~ true ]] && {
|
||||
mkdir -p "$ACTIVE_THEME_PATH" &>/dev/null
|
||||
STATUS "updating active theme" \
|
||||
&& ln -sf "$SOURCE_THEME" "$ACTIVE_THEME_SOURCE" \
|
||||
&& SUCCESS "active theme set to '$THEME_NAME'" \
|
||||
|| ERROR "unable to set active theme to '$THEME_NAME'" \
|
||||
|| return 2
|
||||
}
|
||||
|
||||
local CONFIG_TYPES=()
|
||||
[ $CONFIG_TYPE ] \
|
||||
&& CONFIG_TYPES=($CONFIG_TYPE) \
|
||||
|| CONFIG_TYPES=($COLORSCHEME__SUPPORTED_CONFIG_TYPES) \
|
||||
;
|
||||
|
||||
_GET_HEX() { GET_COLORSCHEME_HEX --theme $THEME_NAME $@; }
|
||||
# allow simple ANSI-color reference
|
||||
local BLACK=$(_GET_HEX .ansi.gray.black )
|
||||
local BRIGHT_BLACK=$(_GET_HEX .ansi.gray.regular )
|
||||
local RED=$(_GET_HEX .ansi.red.regular )
|
||||
local BRIGHT_RED=$(_GET_HEX .ansi.red.bright )
|
||||
local GREEN=$(_GET_HEX .ansi.green.regular )
|
||||
local BRIGHT_GREEN=$(_GET_HEX .ansi.green.bright )
|
||||
local YELLOW=$(_GET_HEX .ansi.yellow.regular )
|
||||
local BRIGHT_YELLOW=$(_GET_HEX .ansi.yellow.bright )
|
||||
local BLUE=$(_GET_HEX .ansi.blue.regular )
|
||||
local BRIGHT_BLUE=$(_GET_HEX .ansi.blue.bright )
|
||||
local MAGENTA=$(_GET_HEX .ansi.magenta.regular)
|
||||
local BRIGHT_MAGENTA=$(_GET_HEX .ansi.magenta.bright )
|
||||
local CYAN=$(_GET_HEX .ansi.cyan.regular )
|
||||
local BRIGHT_CYAN=$(_GET_HEX .ansi.cyan.bright )
|
||||
local WHITE=$(_GET_HEX .ansi.gray.white )
|
||||
local BRIGHT_WHITE=$(_GET_HEX .ansi.gray.bright )
|
||||
local FOREGROUND=$(_GET_HEX .foreground )
|
||||
local BACKGROUND=$(_GET_HEX .background )
|
||||
local CURSOR=$(_GET_HEX .cursor )
|
||||
|
||||
for CONFIG_TYPE in ${CONFIG_TYPES[@]}
|
||||
do
|
||||
STATUS "updating $CONFIG_TYPE theme" \
|
||||
&& _GENERATE_THEME__$CONFIG_TYPE \
|
||||
&& _SET_THEME__$CONFIG_TYPE \
|
||||
&& SUCCESS "emulator $CONFIG_TYPE successfully updated to $THEME_NAME" \
|
||||
|| ERROR "error setting theme $THEME_NAME for $CONFIG_TYPE"
|
||||
|
||||
[[ $CONFIG_TYPE =~ ^getty$ ]] && [[ $TERM =~ ^linux$ ]] && {
|
||||
STATUS 'loading getty theme now' \
|
||||
&& NO_CLEAR=1 source "$ACTIVE_THEME_PATH/getty.sh" \
|
||||
&& SUCCESS 'getty theme loaded' \
|
||||
|| ERROR 'getty theme loading error (see above)'
|
||||
}
|
||||
done
|
||||
|
||||
CHECK_ERRORS --no-usage
|
||||
}
|
||||
|
||||
#####################################################################
|
||||
|
||||
_LIST_THEMES() {
|
||||
ls "$_COLORSCHEME_DIR" | sed -n 's/.yaml$//p'
|
||||
}
|
||||
|
||||
_GET_YAML_LOOKUP_FOR_ANSI_COLOR() {
|
||||
echo "
|
||||
0: .ansi.gray.black
|
||||
1: .ansi.red.regular
|
||||
2: .ansi.green.regular
|
||||
3: .ansi.yellow.regular
|
||||
4: .ansi.blue.regular
|
||||
5: .ansi.magenta.regular
|
||||
6: .ansi.cyan.regular
|
||||
7: .ansi.gray.white
|
||||
8: .ansi.gray.regular
|
||||
9: .ansi.red.bright
|
||||
10: .ansi.green.bright
|
||||
11: .ansi.yellow.bright
|
||||
12: .ansi.blue.bright
|
||||
13: .ansi.magenta.bright
|
||||
14: .ansi.cyan.bright
|
||||
15: .ansi.gray.bright
|
||||
" | YQ -r ".$1"
|
||||
}
|
36
scwrypts/dotwryn/lib/desktop/colorscheme/getty.module.zsh
Normal file
36
scwrypts/dotwryn/lib/desktop/colorscheme/getty.module.zsh
Normal file
@ -0,0 +1,36 @@
|
||||
_COLORSCHEME_FILE__getty="$ACTIVE_THEME_PATH/getty.sh"
|
||||
|
||||
_GENERATE_THEME__getty() {
|
||||
echo "#!/bin/sh
|
||||
# do not edit; generated by scwrypts
|
||||
# theme : $THEME_NAME
|
||||
#
|
||||
# source this file to apply colorscheme to linux getty
|
||||
#
|
||||
[[ \"\$TERM\" =~ ^linux$ ]] || return 0
|
||||
/bin/echo -e \" \
|
||||
\\e]P0$BACKGROUND \
|
||||
\\e]P1$RED \
|
||||
\\e]P2$GREEN \
|
||||
\\e]P3$YELLOW \
|
||||
\\e]P4$BLUE \
|
||||
\\e]P5$MAGENTA \
|
||||
\\e]P6$CYAN \
|
||||
\\e]P7$FOREGROUND \
|
||||
\\e]P8$BRIGHT_RED \
|
||||
\\e]P9$BRIGHT_GREEN \
|
||||
\\e]PA$BRIGHT_YELLOW \
|
||||
\\e]PB$BRIGHT_BLUE \
|
||||
\\e]PC$BRIGHT_MAGENTA \
|
||||
\\e]PD$BRIGHT_CYAN \
|
||||
\\e]PE$WHITE \
|
||||
\\e]PF$BRIGHT_WHITE \
|
||||
\"
|
||||
[ ! \$NO_CLEAR ] && clear
|
||||
return 0
|
||||
" sed '$d' > "$_COLORSCHEME_FILE__getty"
|
||||
}
|
||||
|
||||
_SET_THEME__getty() {
|
||||
ln -sf "$_COLORSCHEME_FILE__getty" "$HOME/.config/wryn/tty-colorscheme"
|
||||
}
|
32
scwrypts/dotwryn/lib/desktop/colorscheme/kitty.module.zsh
Normal file
32
scwrypts/dotwryn/lib/desktop/colorscheme/kitty.module.zsh
Normal file
@ -0,0 +1,32 @@
|
||||
_COLORSCHEME_FILE__kitty="$ACTIVE_THEME_PATH/kitty.conf"
|
||||
|
||||
_GENERATE_THEME__kitty() {
|
||||
echo "# do not edit; generated by scwrypts
|
||||
# theme : $THEME_NAME
|
||||
color0 #$BLACK
|
||||
color1 #$RED
|
||||
color2 #$GREEN
|
||||
color3 #$YELLOW
|
||||
color4 #$BLUE
|
||||
color5 #$MAGENTA
|
||||
color6 #$CYAN
|
||||
color7 #$WHITE
|
||||
color8 #$BRIGHT_BLACK
|
||||
color9 #$BRIGHT_RED
|
||||
color10 #$BRIGHT_GREEN
|
||||
color11 #$BRIGHT_YELLOW
|
||||
color12 #$BRIGHT_BLUE
|
||||
color13 #$BRIGHT_MAGENTA
|
||||
color14 #$BRIGHT_CYAN
|
||||
color15 #$BRIGHT_WHITE
|
||||
cursor #$CURSOR
|
||||
background #$BACKGROUND
|
||||
foreground #$FOREGROUND
|
||||
selection_background #$SELECTION_BACKGROUND
|
||||
selection_foreground #$SELECTION_FOREGROUND
|
||||
" | sed '$d' > "$_COLORSCHEME_FILE__kitty"
|
||||
}
|
||||
|
||||
_SET_THEME__kitty() {
|
||||
ln -sf "$_COLORSCHEME_FILE__kitty" "$HOME/.config/kitty/theme.conf"
|
||||
}
|
19
scwrypts/dotwryn/lib/desktop/colorscheme/polybar.module.zsh
Normal file
19
scwrypts/dotwryn/lib/desktop/colorscheme/polybar.module.zsh
Normal file
@ -0,0 +1,19 @@
|
||||
_COLORSCHEME_FILE__polybar="$ACTIVE_THEME_PATH/polybar.ini"
|
||||
|
||||
_GENERATE_THEME__polybar() {
|
||||
echo "# do not edit; generated by scwrypts
|
||||
# theme : $THEME_NAME
|
||||
[colors]
|
||||
background = #$(_GET_HEX .polybar.background .background)
|
||||
background-alt = #$(_GET_HEX .polybar.background-alt .selection.background)
|
||||
foreground = #$(_GET_HEX .polybar.foreground .foreground)
|
||||
primary = #$(_GET_HEX .polybar.primary .material.base.primary .ansi.green.regular)
|
||||
secondary = #$(_GET_HEX .polybar.secondary .material.base.secondary .ansi.blue.regular)
|
||||
alert = #$(_GET_HEX .polybar.alert .material.base.error .ansi.red.regular)
|
||||
disabled = #$(_GET_HEX .polybar.disabled .ansi.gray.regular)
|
||||
" | sed '$d' > "$_COLORSCHEME_FILE__polybar"
|
||||
}
|
||||
|
||||
_SET_THEME__polybar() {
|
||||
return 0 # theme is referenced explicitly after generation
|
||||
}
|
22
scwrypts/dotwryn/lib/desktop/colorscheme/rofi.module.zsh
Normal file
22
scwrypts/dotwryn/lib/desktop/colorscheme/rofi.module.zsh
Normal file
@ -0,0 +1,22 @@
|
||||
_COLORSCHEME_FILE__rofi="$ACTIVE_THEME_PATH/rofi.rasi"
|
||||
|
||||
_GENERATE_THEME__rofi() {
|
||||
echo "/**
|
||||
* do not edit; generated by scwrypts
|
||||
* theme : $THEME_NAME
|
||||
**/
|
||||
|
||||
*{
|
||||
background: #$(_GET_HEX .rofi.background .background);
|
||||
foreground: #$(_GET_HEX .rofi.foreground .foreground);
|
||||
background-alt: #$(_GET_HEX .rofi.background-alt .material.primary.300 .selection.background);
|
||||
selected: #$(_GET_HEX .rofi.selected .material.foreground.primary.300 .selection.foreground);
|
||||
active: #$(_GET_HEX .rofi.active .material.base.primary .ansi.green.regular);
|
||||
urgent: #$(_GET_HEX .rofi.urgent .material.base.error .ansi.red.regular );
|
||||
}
|
||||
" | sed '$d' > "$_COLORSCHEME_FILE__rofi"
|
||||
}
|
||||
|
||||
_SET_THEME__rofi() {
|
||||
return 0 # theme is referenced explicitly after generation
|
||||
}
|
149
scwrypts/dotwryn/lib/desktop/xorg/i3.module.zsh
Normal file
149
scwrypts/dotwryn/lib/desktop/xorg/i3.module.zsh
Normal file
@ -0,0 +1,149 @@
|
||||
#####################################################################
|
||||
|
||||
use desktop/colorscheme --group dotwryn
|
||||
|
||||
DEPENDENCIES+=(basename readlink sed yq)
|
||||
|
||||
#####################################################################
|
||||
|
||||
I3__GENERATE_CUSTOM_CONFIG__USAGE() {
|
||||
USAGE__options+="
|
||||
--safe preserve old config (or fail if old conf does not exist)
|
||||
--override-file fully qualified path to the override yaml file (default ~/.config/i3/local.yaml)
|
||||
"
|
||||
|
||||
USAGE__description+="
|
||||
Since i3wm does not provide a way to load config values dynamically,
|
||||
I run this script to generate colorscheme values and other per-machine
|
||||
overrides.
|
||||
|
||||
Uses the current, active colorscheme and local overrides specified in
|
||||
~/.config/i3/local.yaml
|
||||
"
|
||||
}
|
||||
|
||||
#####################################################################
|
||||
|
||||
I3__GENERATE_CUSTOM_CONFIG() {
|
||||
local SAFE=false
|
||||
local CONFIG_DEFAULT_FILE="$DOTWRYN/config/i3.config.yaml"
|
||||
local CONFIG_OVERRIDE_FILE="$HOME/.config/i3/local.yaml"
|
||||
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
case $1 in
|
||||
--safe ) SAFE=true ;;
|
||||
--override-file )
|
||||
[ -f "$2" ] || ERROR "no file '$2' can be found"
|
||||
CONFIG_OVERRIDE_FILE="$2"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
CHECK_ERRORS
|
||||
|
||||
[ -f "$CONFIG_OVERRIDE_FILE" ] || {
|
||||
mkdir -p "$(dirname $CONFIG_OVERRIDE_FILE)"
|
||||
echo '---' > "$CONFIG_OVERRIDE_FILE"
|
||||
}
|
||||
|
||||
local CONFIG="$(YQ eval-all '. as $item ireduce ({}; . * $item)' "$CONFIG_DEFAULT_FILE" "$CONFIG_OVERRIDE_FILE")"
|
||||
[ $CONFIG ] \
|
||||
|| ERROR "unable to retrieve i3 config yaml (see above)" \
|
||||
|| return 1 \
|
||||
;
|
||||
|
||||
GET() { echo "$CONFIG" | YQ -r $@; }
|
||||
COLOR() { GET_COLORSCHEME_HEX $@; }
|
||||
|
||||
local I3_CONFIG="$HOME/.config/i3/config"
|
||||
: \
|
||||
&& STATUS "generating configuration" \
|
||||
&& {
|
||||
echo "# i3 config file (v4)"
|
||||
echo "# generated by 'scwrypts generate i3 config' (do not edit directly)"
|
||||
echo "# sources: "
|
||||
echo "# - i3 config base : $DOTWRYN/config/i3.conf"
|
||||
echo "# - custom values : $CONFIG_DEFAULT_FILE"
|
||||
echo "# - override values : $CONFIG_OVERRIDE_FILE"
|
||||
} > "$I3_CONFIG.temp" \
|
||||
&& sed "
|
||||
/Legacy Defaults/,\$d
|
||||
/^#/d
|
||||
/^\s*$/d
|
||||
s/\s\+/ /g
|
||||
|
||||
s/^\(font\) .*[0-9]\+$/\1 $(GET .font.family) $(GET .font.size)/
|
||||
|
||||
s^\(bindsym \$mod+space exec --no-startup-id\).*$\1 $(GET .application-launcher)
|
||||
|
||||
s^\([ ]\+status_command\) .*$\1 $(GET .bar.status)
|
||||
s^\(set \$refresh_statusbar\) .*$\1 $(GET .bar.refresh)
|
||||
|
||||
s/^\(gaps inner\) .*$/\1 $(GET .gaps.inner)/
|
||||
s/^\(gaps outer\) .*$/\1 $(GET .gaps.outer)/
|
||||
|
||||
s/^\(# color settings\).*$/\1 (theme '$(basename $(readlink -f "$DOTWRYN/colorschemes/active/main.conf") | sed 's/\.conf//')')/
|
||||
|
||||
s/\(^set \$FOCUSED_\(BORDER\|BACKGROUND\|CHILD_BORDER\).*#\).*/\1$(COLOR .material.secondary.500 .ansi.green.bright)/
|
||||
s/\(^set \$FOCUSED_INDICATOR.*#\).*/\1$(COLOR .material.secondary.700 .ansi.green.regular)/
|
||||
s/\(^set \$FOCUSED_TEXT.*#\).*/\1$(COLOR .material.foreground.secondary.500 .foreground)/
|
||||
|
||||
s/\(^set \$INACTIVE_\(BORDER\|BACKGROUND\|CHILD_BORDER\).*#\).*/\1$(COLOR .material.primary.500 .ansi.blue.bright)/
|
||||
s/\(^set \$INACTIVE_INDICATOR.*#\).*/\1$(COLOR .material.primary.600 .ansi.blue.regular)/
|
||||
s/\(^set \$INACTIVE_TEXT.*#\).*/\1$(COLOR .material.foreground.primary.500 .foreground)/
|
||||
|
||||
s/\(^set \$UNFOCUSED_\(BORDER\|BACKGROUND\|CHILD_BORDER\).*#\).*/\1$(COLOR .material.primary.700 .ansi.yellow.bright)/
|
||||
s/\(^set \$UNFOCUSED_INDICATOR.*#\).*/\1$(COLOR .material.primary.900 .ansi.yellow.regular)/
|
||||
s/\(^set \$UNFOCUSED_TEXT.*#\).*/\1$(COLOR .material.foreground.primary.700 .foreground)/
|
||||
|
||||
s/\(^set \$URGENT_\(BORDER\|BACKGROUND\|CHILD_BORDER\).*#\).*/\1$(COLOR .material.error.500 .ansi.red.bright)/
|
||||
s/\(^set \$URGENT_INDICATOR.*#\).*/\1$(COLOR .material.error.700 .ansi.red.regular)/
|
||||
s/\(^set \$URGENT_TEXT.*#\).*/\1$(COLOR .material.foreground.error.500 .foreground)/
|
||||
|
||||
s/\(^set \$PLACEHOLDER_\(BORDER\|BACKGROUND\|CHILD_BORDER\).*#\).*/\1$(COLOR .material.primary.300 .ansi.cyan.bright)/
|
||||
s/\(^set \$PLACEHOLDER_INDICATOR.*#\).*/\1$(COLOR .material.primary.100 .ansi.cyan.regular)/
|
||||
s/\(^set \$PLACEHOLDER_TEXT.*#\).*/\1$(COLOR .material.foreground.primary.300 .foreground)/
|
||||
" "$DOTWRYN/config/i3.conf" > "$I3_CONFIG.temp2" \
|
||||
&& grep "^font " "$I3_CONFIG.temp2" >> "$I3_CONFIG.temp" \
|
||||
&& grep "^set " "$I3_CONFIG.temp2" >> "$I3_CONFIG.temp" \
|
||||
&& grep "^bindsym " "$I3_CONFIG.temp2" | sort -u >> "$I3_CONFIG.temp" \
|
||||
&& grep -v "^\(bindsym\|set\|font\) " "$I3_CONFIG.temp2" >> "$I3_CONFIG.temp" \
|
||||
&& { GET '.i3configs[]' 2>/dev/null >> "$I3_CONFIG.temp"; true }\
|
||||
&& rm "$I3_CONFIG.temp2" \
|
||||
&& STATUS "validating config" \
|
||||
&& i3 -C -c "$I3_CONFIG.temp" \
|
||||
|| ERROR "unable to produce config, or produced an invalid config (see above or '$I3_CONFIG.temp')" \
|
||||
|| return 1
|
||||
|
||||
[[ $SAFE =~ true ]] && [ -f "$I3_CONFIG" ] && {
|
||||
local BACKUP_FILE BACKUP_FILE_BASE="$I3_CONFIG.bak"
|
||||
for x in {0..99}
|
||||
do
|
||||
BACKUP_FILE="$BACKUP_FILE_BASE.$x"
|
||||
[ ! -f "$BACKUP_FILE" ] && break
|
||||
done
|
||||
|
||||
mv "$I3_CONFIG" "$BACKUP_FILE" && {
|
||||
SUCCESS "saved old config to '$BACKUP_FILE'"
|
||||
} || {
|
||||
WARNING 'failed to preserve old config'
|
||||
yN 'any existing config will be overwritten; continue?'
|
||||
}
|
||||
}
|
||||
|
||||
: \
|
||||
&& mv "$I3_CONFIG.temp" "$I3_CONFIG" \
|
||||
&& SUCCESS "successfully generated i3 config" \
|
||||
|| ERROR "something went wrong when moving config (check '$(dirname $I3_CONFIG)')" \
|
||||
|| return 1 \
|
||||
;
|
||||
|
||||
: \
|
||||
&& pgrep i3 &>/dev/null \
|
||||
&& i3-msg restart &>/dev/null \
|
||||
&& STATUS 'reloaded config for current session' \
|
||||
;
|
||||
|
||||
return 0
|
||||
}
|
@ -1,12 +1,10 @@
|
||||
#####################################################################
|
||||
|
||||
DEPENDENCIES+=(
|
||||
canberra-gtk-play
|
||||
)
|
||||
REQUIRED_ENV+=()
|
||||
|
||||
use desktop/notify --group dotwryn
|
||||
|
||||
DEPENDENCIES+=(canberra-gtk-play)
|
||||
REQUIRED_ENV+=()
|
||||
|
||||
#####################################################################
|
||||
|
||||
MEDIA__PLAY_SFX() {
|
||||
|
Reference in New Issue
Block a user