speedwm-personal/scripts/speedwm-core

192 lines
6.8 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# speedwm-core
# This script handles the systray and other things necessary for keybinds.
# Set binary directory if not set already.
2022-09-21 19:49:54 +02:00
if [ -e "/usr/share/speedwm/bindir" ]; then
BINDIR=$(cat /usr/share/speedwm/bindir) # Set binary directory to the contents of this variable.
else
BINDIR="/usr/bin/"
fi
TINT="#222222" # Default tint
EDGE="top" # Part of the screen where your systray will be placed
GET_EDGE_AUTO="true" # Get edge automatically (true/false)
SYSTRAY_COL=1 # When using pywal, set color to background (1) or backgroundmid (0)
USE_SRG=false # Use $SYSTRAY-srg (available in Gentoo repos and AUR as $SYSTRAY-srg-git) instead of $SYSTRAY adding more features (true/false)
USE_DEFAULT_TINT=false # Use default $TINT or use $SYSTRAY_COL
ALPHA=0 # Opacity of the systray (0 is opaque, 255 is fully transparent)
2022-08-22 12:34:02 +02:00
HIDE_BAR_WHEN_SYSTRAY_SHOW=false # Hide the speedwm bar when the systray is running.
ALPHA_BARHIDDEN=255 # Opacity of the systray when the speedwm bar is hidden (0 is opaque, 255 is fully transparent)
TRANSPARENT=true # Transparent or not (true/false)
2022-08-22 12:34:02 +02:00
EXPORTDIR=$HOME/.config/speedwm-de/systray # Config directory
HEIGHT=18 # Height of the systray
WIDTH=30 # Width of the systray
2022-08-22 12:34:02 +02:00
SHOW_SYSTRAY_WHEN_BARPADDING=true # Show systray if vertical barpadding is enabled
mkdir -p $EXPORTDIR
# Load config if available and override settings
if [ -e "$EXPORTDIR/config" ]; then
. $EXPORTDIR/config
else
printf "TINT=$TINT # Tint when pywal is not used." > $EXPORTDIR/config
printf "\nEDGE=$EDGE # Part of the screen where your systray will be placed" >> $EXPORTDIR/config
printf "\nGET_EDGE_AUTO=$GET_EDGE_AUTO # Get edge automatically (true/false)" >> $EXPORTDIR/config
printf "\nSYSTRAY_COL=$SYSTRAY_COL # When using pywal, set color to background (1) or backgroundmid (0)" >> $EXPORTDIR/config
printf "\nALPHA=$ALPHA # Opacity of the systray (0 is opaque, 255 is fully transparent)" >> $EXPORTDIR/config
2022-08-22 12:34:02 +02:00
printf "\nALPHA_BARHIDDEN=$ALPHA_BARHIDDEN # Opacity of the systray when the speedwm bar is hidden (0 is opaque, 255 is fully transparent)" >> $EXPORTDIR/config
printf "\nTRANSPARENT=true # Transparent or not (true/false)" >> $EXPORTDIR/config
2022-08-22 12:34:02 +02:00
printf "\nHIDE_BAR_WHEN_SYSTRAY_SHOW=$HIDE_BAR_WHEN_SYSTRAY_SHOW # Hide the speedwm bar when the systray is running." >> $EXPORTDIR/config
printf "\nUSE_SRG=$USE_SRG # Use $SYSTRAY-srg (available in Gentoo repos and AUR as $SYSTRAY-srg-git) instead of $SYSTRAY adding more features (true/false)" >> $EXPORTDIR/config
printf "\nUSE_DEFAULT_TINT=$USE_DEFAULT_TINT # Use default $TINT or use $SYSTRAY_COL" >> $EXPORTDIR/config
2022-08-22 12:34:02 +02:00
printf "\nSHOW_SYSTRAY_WHEN_BARPADDING=$SHOW_SYSTRAY_WHEN_BARPADDING # Show systray if vertical barpadding is enabled" >> $EXPORTDIR/config
printf "\nHEIGHT=$HEIGHT # Height of the systray" >> $EXPORTDIR/config
printf "\nWIDTH=$WIDTH # Width of the systray\n" >> $EXPORTDIR/config
fi
TINT="$(echo $TINT | sed "s|#||g")"
OPT=$1
# Pywal tint
PYWAL_TINT() {
# Pywal tint
if [ "$USE_DEFAULT_TINT" = "false" ]; then
if [ -e "$HOME/.cache/wal/colors" ]; then
if [ "$SYSTRAY_COL" = "1" ]; then
TINT=$(sed -n 1,1p $HOME/.cache/wal/colors | sed "s|#||g")
elif [ "$SYSTRAY_COL" = "0" ]; then
TINT=$(sed -n 13,13p $HOME/.cache/wal/colors | sed "s|#||g")
fi
fi
fi
}
# Set edge
SETEDGE() {
if [ "$GET_EDGE_AUTO" = "true" ]; then
2022-09-21 20:01:59 +02:00
if [ -e "/usr/share/speedwm/topbar" ]; then
EDGE="top"
else
EDGE="bottom"
fi
fi
}
# Set alpha
SETALPHA() {
if [ "$HIDE_BAR_WHEN_SYSTRAY_SHOW" = "true" ]; then
ALPHA=$ALPHA_BARHIDDEN
else
ALPHA=$ALPHA
fi
}
PYWAL_TINT
SETEDGE
SETALPHA
# Set systray
if [ "$USE_SRG" = "true" ]; then
SYSTRAY=trayer-srg
else
SYSTRAY=trayer
fi
2022-09-02 01:11:02 +02:00
USE() {
echo USE
# Toggle
TOGGLE() {
if [ -e "/tmp/systray-started" ]; then
OPT="-stop"
else
OPT="-start"
fi
}
2022-08-22 12:34:02 +02:00
# Update speedwm
UPDATE() {
FAIL_SOURCEDOESNOTEXIST() {
2022-08-22 12:34:02 +02:00
echo "The speedwm source code directory could not be located. This means an automatic update cannot be performed. Clone a new build (instructions on https://speedie.gq/speedwm) and update manually."
exit 1
}
FAIL_NOT_INSTALLED_USING_GIT() {
2022-08-22 12:34:02 +02:00
echo "Your build of speedwm was likely not installed through Git (maybe installed using a tarball?) so therefore the update cannot continue. Clone a new build (instructions on https://speedie.gq/speedwm) and update manually."
exit 1
}
FAIL_NO_AUTH() {
echo "Failed to authenticate."
exit 1
}
2022-09-21 20:01:59 +02:00
SOURCEDIR=$(cat /usr/share/speedwm/sourcedir)
test $SOURCEDIR || FAIL_SOURCEDOESNOTEXIST
# Check if Git is available
if [ -e "${BINDIR}git" ]; then
echo "Git found!"
else
2022-08-22 12:34:02 +02:00
echo "Git was not found, therefore the speedwm update cannot continue." ; exit 1
fi
cd $SOURCEDIR
2022-09-11 17:43:17 +02:00
make patch_remove
git stash
git pull || FAIL_NOT_INSTALLED_USING_GIT
2022-09-11 17:43:17 +02:00
make patch_install
clear
2022-09-11 17:43:17 +02:00
printf "speedwm requires root permissions briefly to run the following command:\nmake clean install\nEnter your password to allow this.\n"
su -c "make clean install" || FAIL_NO_AUTH
2022-08-22 12:34:02 +02:00
echo 'speedwm has been updated!'
exit 0
}
case "$OPT" in
"-toggle") TOGGLE ;;
2022-08-22 12:34:02 +02:00
"-update-speedwm") UPDATE ;;
esac
case "$OPT" in
"-start") $SYSTRAY --edge $EDGE --align right --SetDockType true --SetPartialStrut true --expand true --width $WIDTH --transparent $TRANSPARENT --alpha $ALPHA --tint 0x${TINT} --height $HEIGHT &
touch /tmp/systray-started ; pgrep -x status && pkill status ; status &
if [ "$HIDE_BAR_WHEN_SYSTRAY_SHOW" = "true" ]; then
xsetroot -name "fsignal:23"
fi ;;
"-stop") rm -f /tmp/systray-started ; pkill $SYSTRAY ; pgrep -x status && pkill status ; status &
if [ "$HIDE_BAR_WHEN_SYSTRAY_SHOW" = "true" ]; then
xsetroot -name "fsignal:23"
fi ;;
2022-08-22 12:34:02 +02:00
"") echo "speedwm-core\n-start | Start the systray and restart status\n-stop | Stop the systray and restart status\n-toggle | Toggle systray and restart status\n-update-speedwm | Update speedwm using git\n-curl-weather | Curl wttr.in in a readable format\n-curl-cheatsheet | Ask the user what cheatsheet they want and then curl it." ;;
esac
}
case "$OPT" in
"-curl-weather") clear ; curl -s wttr.in | head -n 38 | tail -n 37 && sleep 60 ;;
"-curl-cheatsheet") clear ; echo -n "What cheatsheet do you want to view?\nExample: vim\n > " ; read CHEATSHEET ; curl -s cheat.sh/$(echo $CHEATSHEET | tr '[:upper:]' '[:lower:]') > /tmp/cheatsheet
grep "Unknown topic." /tmp/cheatsheet && $0 -curl-cheatsheet && exit 0
less /tmp/cheatsheet ;;
esac
2022-09-02 01:11:02 +02:00
OPT=$1
# Start systray
if [ -e "${BINDIR}$SYSTRAY" ]; then
2022-09-02 01:11:02 +02:00
if [ -e "$HOME/.config/speedwm-de/speedwmrc" ]; then
2022-08-22 12:34:02 +02:00
if [ "$SHOW_SYSTRAY_WHEN_BARPADDING" = "true" ]; then
USE
else
grep "barpaddingv" $HOME/.config/speedwm-de/speedwmrc > /tmp/out
2022-09-02 01:11:02 +02:00
grep -q "0" /tmp/out > /dev/null && USE
2022-08-22 12:34:02 +02:00
fi
else
USE
fi
else
2022-09-02 01:11:02 +02:00
echo "Trayer not installed." && USE
fi