archcraft-openbox/files/pipemenus/ac-change-fonts

165 lines
5.7 KiB
Plaintext
Raw Permalink Normal View History

2023-10-05 10:09:04 +00:00
#!/usr/bin/env bash
## Copyright (C) 2020-2024 Aditya Shakya <adi1090x@gmail.com>
2023-10-05 10:09:04 +00:00
##
## Openbox Pipemenu to change fonts for various applications
# Variables and functions
MENUS_LIBDIR='/usr/share/archcraft/openbox/menulib'
if ! . "$MENUS_LIBDIR/archcraft.cfg" 2> /dev/null; then
echo "Error: Failed to locate archcraft.cfg in $MENUS_LIBDIR" >&2
exit 1
fi
# Theme
themedir="$HOME/.config/openbox/themes"
ctheme="`cat $themedir/.current`"
# Dir
confdir="$HOME/.config"
termdir="$confdir/alacritty"
dunstdir="$confdir/dunst"
oboxdir="$confdir/openbox"
polydir="$themedir/$ctheme/polybar"
rofidir="$themedir/$ctheme/rofi"
# Font
getfonts () {
FONT=$(yad --title='Select A Font' --font --separate-output --button=Cancel:1 --button=Select:0)
FNAME=$(echo $FONT | cut -d'|' -f1)
FSTYLE=$(echo $FONT | cut -d'|' -f2)
FSIZE=$(echo $FONT | cut -d'|' -f3)
}
font_bar () {
if [[ "$FONT" ]]; then
sed -i -e "s/font-0 = .*/font-0 = $FNAME:$FSTYLE:size=$FSIZE;2/g" ${polydir}/config.ini
polybar-msg cmd restart
else
exit 0
fi
}
font_rofi () {
if [[ "$FONT" ]]; then
sed -i -e "s/font:.*/font: \"$FNAME $FSTYLE $FSIZE\";/g" ${rofidir}/shared/fonts.rasi
else
exit 0
fi
}
font_term () {
if [[ "$FONT" ]]; then
sed -i -e "s/family: .*/family: \"$FNAME\"/g" ${termdir}/fonts.yml
sed -i -e "s/size: .*/size: $FSIZE/g" ${termdir}/fonts.yml
else
exit 0
fi
}
font_ob () {
if [[ "$FONT" ]]; then
namespace="http://openbox.org/3.4/rc"
config="$oboxdir/rc.xml"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="ActiveWindow"]/a:name' -v "$FNAME" "$config"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="ActiveWindow"]/a:size' -v "$FSIZE" "$config"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="ActiveWindow"]/a:weight' -v Bold "$config"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="ActiveWindow"]/a:slant' -v Normal "$config"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="InactiveWindow"]/a:name' -v "$FNAME" "$config"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="InactiveWindow"]/a:size' -v "$FSIZE" "$config"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="InactiveWindow"]/a:weight' -v Normal "$config"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="InactiveWindow"]/a:slant' -v Normal "$config"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="MenuHeader"]/a:name' -v "$FNAME" "$config"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="MenuHeader"]/a:size' -v "$FSIZE" "$config"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="MenuHeader"]/a:weight' -v Bold "$config"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="MenuHeader"]/a:slant' -v Normal "$config"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="MenuItem"]/a:name' -v "$FNAME" "$config"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="MenuItem"]/a:size' -v "$FSIZE" "$config"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="MenuItem"]/a:weight' -v Normal "$config"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="MenuItem"]/a:slant' -v Normal "$config"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="ActiveOnScreenDisplay"]/a:name' -v "$FNAME" "$config"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="ActiveOnScreenDisplay"]/a:size' -v "$FSIZE" "$config"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="ActiveOnScreenDisplay"]/a:weight' -v Bold "$config"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="ActiveOnScreenDisplay"]/a:slant' -v Normal "$config"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="InactiveOnScreenDisplay"]/a:name' -v "$FNAME" "$config"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="InactiveOnScreenDisplay"]/a:size' -v "$FSIZE" "$config"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="InactiveOnScreenDisplay"]/a:weight' -v Normal "$config"
xmlstarlet ed -L -N a="$namespace" -u '/a:openbox_config/a:theme/a:font[@place="InactiveOnScreenDisplay"]/a:slant' -v Normal "$config"
openbox --reconfigure
else
exit 0
fi
}
font_dunst () {
if [[ "$FONT" ]]; then
sed -i -e "s/font = .*/font = $FNAME $FSTYLE $FSIZE/g" ${dunstdir}/dunstrc
pkill dunst && dunst &
else
exit 0
fi
}
font_gtk () {
if [[ "$FONT" ]]; then
xfconf-query -c xsettings -p /Gtk/FontName -s "$FNAME $FSTYLE $FSIZE"
else
exit 0
fi
}
if [[ "$1" == "--bar" ]]; then
getfonts
font_bar
elif [[ "$1" == "--rofi" ]]; then
getfonts
font_rofi
elif [[ "$1" == "--terminal" ]]; then
getfonts
font_term
elif [[ "$1" == "--openbox" ]]; then
getfonts
font_ob
elif [[ "$1" == "--dunst" ]]; then
getfonts
font_dunst
elif [[ "$1" == "--gtk" ]]; then
getfonts
font_gtk
elif [[ "$1" == "--all" ]]; then
getfonts
font_bar
font_rofi
font_term
font_ob
font_dunst
font_gtk
else
menuStart
menuItem 'Status Bar (polybar)' "$0 --bar"
menuItem 'Launchers (rofi)' "$0 --rofi"
menuItem 'Terminal (alacritty)' "$0 --terminal"
menuItem 'Desktop (openbox)' "$0 --openbox"
menuItem 'Notifications (dunst)' "$0 --dunst"
menuItem 'Applications (gtk)' "$0 --gtk"
menuSeparator
menuItem 'Change Globally' "$0 --all"
menuEnd
fi
exit 0