Skip to content
Permalink
master
Go to file
 
 
Cannot retrieve contributors at this time
executable file 504 lines (392 sloc) 13 KB
#!/usr/bin/env bash
# Load themes for programs from current theme
# todo: this script should also handle font checking against fc-list
# setup:
# relative calling
cd $(dirname $([ -L $0 ] && readlink -f $0 || echo $0))
export PATH="$PATH:$(pwd)"
# default template targets
# this allows themes to replace template files with different targets, by defining ${target}_template
for template in $(ls $HOME/.dotfiles/templates); do
eval ${template}_template="$HOME/.dotfiles/templates/${template}"
done
# todo: should this used the cached theme? then you wouldn't depend
# on emacs running for eg, panel startup/refresh theme there
eval "$(theme get)"
set -a
# adjust pIcon to theme (rel for panel, acyl, qutebrowser.)
if [ "$p_icon" = "unset" ]; then
colort -c "$p_bg_active" && intensity=40 || intensity=60
p_icon=$(colort -c "$p_fg_inactive" && \
colort -l -$intensity "$p_fg_inactive" || \
colort -l $intensity "$p_fg_inactive")
[ $? -ne 0 ] && p_icon=$(colort -c "$p_fg_inactive" && \
colort -l $intensity "$p_fg_inactive" || \
colort -l -$intensity "$p_fg_inactive")
p_icon="$(colort -t $p_icon)"
fi
# util:
# mustache args, cache.
# usage: margs <template name> <destination>
# <destination> is relative to $HOME
margs() {
cache=false
template=$(eval echo \$${1}_template)
if [ ! -f "$template" ]; then
template=$1
fi
target="$HOME/$2"
mkdir -p "${target%/*}"
if $cache; then
cachefile="/tmp/template/$THEME_NAME/$2"
if [ ! -f "$cachefile" ]; then
mkdir -p "${cachefile%/*}"
templum -o "$cachefile" "$template"
cp "$cachefile" "$target"
return 1
fi
cp "$cachefile" "$target"
return 0
fi
templum -o "$target" "$template"
return 1
}
git_ensure() {
gitdir="$HOME/git"
case "$1" in
acyl) gittarget="https://github.com/neeasade/acyl"
gitdir="$HOME/.icons/"
;;
oomox) gittarget="https://github.com/actionless/oomox-gtk-theme/" ;;
css) gittarget="https://github.com/neeasade/solarized-everything-css" ;;
pywal) gittarget="https://github.com/dylanaraps/pywal/" ;;
wal_steam) gittarget="https://github.com/Tardog/wal_steam/" ;;
esac
mkdir -p "$gitdir"
gitdest="$gitdir/$(basename "$gittarget")"
# echo git clone "$gittarget" "$gitdest"
if [ ! -d "$gitdest" ]; then
git clone "$gittarget" "$gitdest"
if [ "$1" = "wal_steam" ]; then
cd "$gitdest"
git fetch --all
git checkout -b support-new-library-view
fi
fi
}
trim_alphas() {
for target in active inactive normal; do
eval p_fg_$target=$(eval colort -t "\$p_fg_$target")
eval p_bg_$target=$(eval colort -t "\$p_bg_$target")
done
p_icon=$(colort -t "$p_icon")
}
# loaders:
load_tmux() {
margs tmux .tmux.conf
pgrep tmux && tmux source-file "$HOME/.tmux.conf"
}
load_picom() {
margs picom .config/picom.conf
systemctl --user restart picom
}
load_bg() {
$BG_COMMAND
}
# also loads xst, emacs
load_xresources() {
trim_alphas
if ! margs Xresources .Xresources; then
# handle any color definitions through 255
(
IFS=$'\n'
for i in $(seq 0 255); do
eval "[ ! -z \$color$i ] && echo \*.color$i: \#\$color$i >> $HOME/.Xresources"
done
)
if [ ! -z "$cachefile" ]; then
cp "$HOME/.Xresources" "$cachefile"
fi
fi
xrdb $HOME/.Xresources
load_xst
}
load_emacs() {
elisp '(ns/style)'
}
load_xst() {
pkill -x --signal USR1 xst
}
load_bspwm() {
if [ "${p_launch_cmd##*/}" = "lemonade" ]; then
load_lemonade
fi
bspwmrc=".config/bspwm/bspwmrc"
margs bspwm "$bspwmrc"
chmod +x "$HOME/$bspwmrc"
wait
setsid "$HOME/$bspwmrc"
}
load_lemonade() {
rm $HOME/.config/i3blocks/config
IFS=$'\n'
juicer_target=".config/i3blocks/config"
# note all lemons, generate them.
lemons=$(echo $p_format | tr ':|' ' ');
if ! margs juicer "$juicer_target"; then
. ripen
IFS=' '
parallel -P 0 "squeeze {}" ::: $lemons >> $HOME/$juicer_target
IFS=
[ ! -z "$cachefile" ] && cp "$HOME/$juicer_target" "$cachefile"
fi
if systemctl --user status panel >/dev/null; then
systemctl --user restart panel
fi
}
# GTK (make theme if it does not exist, then reload)
load_gtk() {
trim_alphas
if ! margs gtkrc .gtkrc-2.0; then
target="$HOME/.themes/${THEME_NAME}_template"
# mustache < $HOME/.dotfiles/templates/oomox > $target
templum -o "$target" "$HOME/.dotfiles/templates/oomox"
git_ensure oomox
cd "$gitdest"
"./change_color.sh" -o "$THEME_NAME" "$target"
fi
# icon color (ACYL)
git_ensure acyl
$HOME/.icons/acyl/icon.sh "#$p_icon"
# reload
gtkrc-reload
# set a place to reference active theme for newly launched GTK3 programs.
echo "$THEME_NAME" > $HOME/.themes/ACTIVE_THEME
}
# qutebrowser
load_qutebrowser() {
trim_alphas
git_ensure css
(
# can't use gitdest here, margs is relative to home
margs css "git/solarized-everything-css/styl/my.styl"
cd "${gitdest}"
# stylus --include styl --import styl/my.styl -p sites/all-sites.styl > css/all.css
)
q_tab_bold="$(iif "echo $p_font_main | grep -q Bold")"
q_tab_bold="${q_tab_bold^}" # bashism, make first letter capital
q_tab_fontsize="$(echo $p_font_main | grep -Eo '[0-9]+')"
q_tab_fontsize_small="$(($q_tab_fontsize - 1))"
q_tab_font=$(echo "$p_font_main" | sed 's/-.*//')
# next stable qutebrowser version:
q_tab_font=$(echo "$q_tab_font" | sed 's# #\\\\ #g')
margs qutebrowser .config/qutebrowser/colors.py
current_conf=$(bspc config ignore_ewmh_focus)
bspc config ignore_ewmh_focus true
qb_command ':config-source'
# qb_command ':reload' # reload current page w/ css
bspc config ignore_ewmh_focus $current_conf
}
# dunst
load_dunst() {
trim_alphas
# geometry will hail from settings at the time this is called re: gap, panel
pgrep lemonbar || p_height=0
# still want it a _little_ in if we are not gapped
[ $b_window_gap -le 0 ] && b_window_gap=$x_padding
[ $b_border_width -gt 4 ] && b_border_width=$(( $b_border_width/2 ))
export b_border_width=1
export b_focused_border_color=#777777
# [ $x_padding -gt 12 ] && x_padding=$(( $x_padding/2 ))
# WIDTHxHEIGHT+XOFF+YOFF
# height is the number of notifications that can be open
mon_width=$(bspc query -T -m | jq .rectangle.width)
d_width=$(echo .24 \* $mon_width | bc | sed 's/\..*//')
# todo: make this a theme option
# top center
mon_width=$(bspc query -T -m | jq -r .rectangle.width)
d_x_middle=$(( (mon_width / 2) - (d_width/2) ))
p_geometry="${d_width}x6+${d_x_middle}+$((b_window_gap + p_height))"
# top right
# WIDTHxHEIGHT+XOFF+YOFF
# p_geometry="${d_width}x6-${b_window_gap}+$((b_window_gap + p_height))"
margs dunstrc .config/dunst/dunstrc
# pkill dunst
# dunst will auto-launch on notify-send call
systemctl --user stop dunst
pkill dunst
systemctl --user start dunst
}
load_mpd() {
mkdir -p "$HOME/.config/mpd/playlists"
if mount | grep "${HOME}/usb"; then
music_dir="${HOME}/usb/Music"
mpd_dir="$HOME/.config/mpd_portable"
mkdir -p "$mpd_dir"
fi
margs mpd .config/mpd/mpd.conf
systemctl --user restart mpd
}
load_mpd_windows() {
margs mpd_windows .config/mpd/mpd.conf
}
load_zathura() {
trim_alphas
margs zathura .config/zathura/zathurarc
}
load_zeal() {
margs zeal .config/Zeal/Zeal.conf
}
load_mintty() {
trim_alphas
st_font=$(echo $st_font | sed 's/-.*//')
st_font_size=$(echo $st_font | tr -dc '0-9')
# limitation: ttf fonts
list_windows_fonts() {
powershell '
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$objFonts = New-Object System.Drawing.Text.InstalledFontCollection
$objFonts.Families
'
}
if ! list_windows_fonts | grep -q "$st_font"; then
st_font=Consolas
fi
margs mintty .minttyrc
}
# steal pywal templates
# mostly interested in css template for load_steam
load_pywal() {
# note: this is not comprehensive, does not cover the 'color1.rgb' case and whatever else there might be
# usually pywal expects colors to have the #
for c in color{0..15} background foreground; do
echo "$c=\#\$$c"
eval export $c=\#\$$c
done
export cursor="#${cursorColor}"
mkdir -p "${HOME}/.cache/wal/"
git_ensure pywal
IFS=$'\n'
for f in $(fd . -t f "${gitdest}/pywal/templates/"); do
# turn all singles into doubles
dest=".cache/wal/$(basename "$f")"
template="${HOME}/${dest}.template"
cp "$f" "$template"
# account for template differences
sed -i 's/{/{{/g' "$template"
sed -i 's/}/}}/g' "$template"
sed -i 's/{{{{/{/g' "$template"
sed -i 's/}}}}/}/g' "$template"
margs "$template" "$dest"
done
# todo: consider cleaning up the oomox template here (color.strip) and using that
}
# note -- not sure if this just didn't work or what but it is ugly
load_steam() {
load_pywal
git_ensure wal_steam
cd "$gitdest"
# todo: -f font
./wal_steam.py -w
}
load_services() {
# clean
find ${HOME}/.config/systemd/user/ -type f -delete
# running_services=$(systemctl --user list-units | awk '{print $1}' | grep '\.service' | sort)
running_services=$(systemctl --user list-units | grep -oE '[a-zA-Z_]+.service' | tr '\n' ' ')
installed_services=$(systemctl --user list-unit-files | awk '{print $1}' | grep '\.service' | sort)
# stop the in memory services that have no service files associated
for s in $running_services; do
if ! grep -q $s <<< "$installed_services"; then
echo systemctl --user stop $s
systemctl --user stop $s
fi
done
made_services=
# note: service PATH is set to whatever PATH is when you call this script
# todo: some sort of validation -- don't make service files for executables you don't have maybe
make_service() {
export service_name=$1
export ExecStart=${2:-$1}
export Description=${3:-$1}
# fully qualify executable:
args=$(awk '{$1=""; print $0}' <<< "$ExecStart")
target=$(awk '{print $1}' <<< "$ExecStart")
export ExecStart="$(which $target) ${args}"
margs systemd_service .config/systemd/user/${service_name}.service
made_services="${made_services} $service_name"
}
make_periodic_service() {
# todo: consider making this a systemd timer
interval=$1
shift
make_service "$1" "periodically $interval $2" "$3"
}
make_periodic_service 60 temp_check "sensor_alert cpu_temp" "Notify when the cpu temp is high"
make_periodic_service 30 memory_check "sensor_alert memory" "Notify when the memory pressure is high"
make_periodic_service $((60 * 60 * 24)) update_adblock update_adblock
if [ "$(hostname)" = "geloof" ]; then
make_periodic_service 10 refresh_mpd refresh_mpd
make_periodic_service 10 display_sync "laptop_monitor_sync" "Update displays on connection changes"
make_periodic_service 90 battery_check "sensor_alert battery" "Notify when the battery is low"
fi
if [ "$(hostname)" = "erasmus" ]; then
make_periodic_service 10 vps_connect "periodically -p 10 ssh -tt -R 22222:localhost:22 neeasade@vps.neeasade.net"
# ssh -t vps.neeasade.net 'ssh localhost -p 22222'
make_periodic_service 120 sync_org_schedule sync_org_schedule
fi
make_service unclutter 'unclutter -idle 1'
make_service dunst
make_service picom
# tray stuff
make_service nm-applet
make_service pasystray
make_service stalonetray
make_service blueman-applet
make_service panel "$HOME/.wm/panel/lemonade"
# todo: correct lemon mpd naming conflict
make_service mpd "/run/current-system/sw/bin/mpd --no-daemon $HOME/.config/mpd/mpd.conf"
# reload units
systemctl --user daemon-reload
# start and enable our units
for s in $made_services; do
systemctl --user start $s
systemctl --user enable $s
done
# just kidding
systemctl --user disable panel
systemctl --user disable stalonetray
}
load_jgmenu() {
p_font_main=$(echo "$p_font_main" | sed 's/-.*//')
margs jgmenu .config/jgmenu/jgmenurc
}
load_btag_borders() {
elisp '(->> (list :accent1_ :accent2_ :accent2 :foreground_)
(ht-with-context ns/theme)
(-map
(lambda (c)
(ct/transform-lch c
(lambda (L C H) (list (* 1.7 L) (* 1.3 C) H)))))
(-map (fn (substring <> 1)))
(-map-indexed (fn (ns/shell-exec (format "btags set ^%s color %s" (+ 1 <1>) <2>)))))'
}
if uname | grep -q MINGW; then
# windows
targets=${*:-mintty mpd_windows tmux}
else
targets=${*:-picom tmux xresources bspwm bg gtk dunst qutebrowser zathura jgmenu zeal btag_borders}
fi
IFS=" "
for conf in $targets; do
(
#time="$((time load_$conf) 2>&1 1>/dev/null | tail -n 3 | head -n 1)"
#echo $conf : $time >> theme_perf.txt
load_$conf
echo $conf done
) &
done
IFS=
theme cache_env
# leave our children to fate.
disown
You can’t perform that action at this time.