2022-08-21 11:53:18 +02:00
#!/bin/sh
2022-08-24 11:07:22 +02:00
# speedwm_run
2022-08-21 11:53:18 +02:00
# External script which starts speedwm!
# https://speedie.gq/speedwm for instructions and usage!
ARGS=$1
# No second argument is supported
2022-10-27 17:41:42 +02:00
if [ "$2" != "" ]; then
2022-08-21 11:53:18 +02:00
echo "Unknown argument: $2" ; exit 1
fi
2022-08-23 15:47:37 +02:00
HAVE_GRID="true"
2022-10-28 20:26:57 +02:00
if [ -e "$HOME/.config/speedwm/globalrc" ]; then
. $HOME/.config/speedwm/globalrc
2022-08-23 15:47:37 +02:00
else
2022-10-28 20:26:57 +02:00
mkdir -p $HOME/.config/speedwm
printf "HAVE_GRID=$HAVE_GRID # Whether or not to use the Grid argument. If you do not have the dmenu grid patch, set this to false. Doing so will disable grid." > $HOME/.config/speedwm/globalrc
2022-08-23 15:47:37 +02:00
fi
if [ "$HAVE_GRID" = "true" ]; then
GRIDNUM="1"
fi
if [ "$HAVE_GRID" = "true" ]; then
GRIDARG="-g"
fi
2022-08-21 11:53:18 +02:00
# Don't make config if asked not to.
2022-09-21 20:01:59 +02:00
if [ -e "$HOME/.local/share/speedwm/do-not-mkconfig" ]; then
2022-08-21 11:53:18 +02:00
DONOTMKCONFIG=true
else
DONOTMKCONFIG=false
fi
# Load .Xresources if available
XRESOURCES() {
if [ -e "$HOME/.Xresources" ]; then
2022-10-27 17:41:42 +02:00
if command -v xrdb > /dev/null; then
2022-08-21 11:53:18 +02:00
xrdb $HOME/.Xresources
fi
elif [ -e "$HOME/.config/.Xresources" ]; then
2022-10-27 17:41:42 +02:00
if command -v xrdb > /dev/null; then
2022-08-21 11:53:18 +02:00
xrdb $HOME/.config/.Xresources
fi
fi
}
# Load speedwm config, create if it does not exist.
LOADCONFIG() {
2022-10-27 17:41:42 +02:00
mkdir -p $HOME/.config/speedwm
if command -v xrdb > /dev/null; then
2022-08-21 11:53:18 +02:00
if [ "$DONOTMKCONFIG" = "false" ]; then
2022-10-27 17:41:42 +02:00
if [ -e "$HOME/.config/speedwm/speedwmrc" ]; then
xrdb -merge -quiet $HOME/.config/speedwm/speedwmrc
2022-08-21 11:53:18 +02:00
else
2022-10-27 17:41:42 +02:00
sed "s| - ||g; s|!@||g" /usr/share/speedwm/example.Xresources > $HOME/.config/speedwm/speedwmrc && echo "Wrote example configuration file"
2022-08-21 11:53:18 +02:00
fi
fi
fi
}
2022-09-10 11:47:08 +02:00
# Load wallpaper config
2022-08-21 11:53:18 +02:00
LOADSWAL() {
if [ "$DONOTLOADCONFIG" = "true" ]; then
DONOTLOADCONFIG=true
else
2022-10-27 17:41:42 +02:00
$HOME/.config/speedwm/swal/swal_wm > /dev/null
2022-08-21 11:53:18 +02:00
echo "Loaded wallpaper and pywal colors"
fi
2022-09-10 11:47:08 +02:00
}
2022-10-03 16:49:24 +02:00
# Load colors
LOADCOLS() {
if [ "$DONOTLOADCONFIG" = "true" ]; then
DONOTLOADCONFIG=true
else
2022-10-15 02:22:19 +02:00
speedwm -s "#cmd:65" # reload colors
speedwm -s "Loading" # hide ugly signal
2022-10-03 16:49:24 +02:00
echo "Loaded colors"
fi
}
2022-09-10 11:47:08 +02:00
# Autostart
AUTOSTART() {
2022-10-27 17:41:42 +02:00
if [ -e "$HOME/.config/speedwm/autostart_once.sh" ]; then
$HOME/.config/speedwm/autostart_once.sh
2022-09-10 11:47:08 +02:00
fi
2022-08-21 11:53:18 +02:00
}
# Reset speedwm
RESET() {
if [ "$DONOTRELOAD" = "true" ]; then
DONOTRELOAD=true
else
2022-10-15 02:22:19 +02:00
speedwm -s "Loading" # To hide the ugly fsignal status
speedwm -s "#cmd:27" # Send fsignal to restart speedwm
2022-10-27 17:41:42 +02:00
speedwm -s "" # To hide the ugly fsignal status
2022-08-21 11:53:18 +02:00
fi
}
# Check for running window managers
CHECKEXISTINGWM() {
if [ "$CARG" = "force" ]; then
echo "WARNING: Bypassing all checks (due to -f argument). Use this with caution!"
else
pgrep -x speedwm > /dev/null && echo "speedwm is already running. Use $0 -r to restart it."
pgrep -x speedwm > /dev/null && exit 1
fi
}
# Start speedwm itself
2022-09-11 01:24:54 +02:00
START_SPEEDWM() {
2022-08-21 21:08:40 +02:00
if [ "$ISSFLAG" = "" ]; then
while true; do
2022-11-02 12:23:08 +01:00
pgrep -x speedwm > /dev/null || speedwm > /tmp/speedwm-log
2022-08-21 21:08:40 +02:00
done
fi
2022-08-21 11:53:18 +02:00
}
# List of arguments
HELP() {
2022-09-11 01:34:44 +02:00
printf "speedwm\nNo arguments | Start speedwm using default options\n\
-s | Start speedwm using either sx or startx. This does not require you to use a .xinitrc file. Simply install xinit/sx and run speedwm -s\n\
-f | Start speedwm bypassing all checks (such as whether or not a window manager is running)\n\
-noxrdb | Start speedwm without loading colors.\n\
-nomkconfig | Start speedwm without creating a config file (or loading it)\n\
-h | View this list of arguments\n\
-r | Restart speedwm and reload colors\n\
-loadconfig | Load and create config if it does not exist\n\
-unloadconfig | Unload the speedwm configuration\n\
-deleteconfig | Delete the speedwm configuration\n\
-rnoload | Restart speedwm without reloading colors\n\
2022-10-27 17:41:42 +02:00
-configure | Bring up a list of speedwm dotfiles in $RUNLAUNCHER and ask the user which one to open in \$EDITOR inside \$TERMINAL\n"
2022-08-21 11:53:18 +02:00
}
# Unload speedwm configuration
UNLOADCONFIG() {
2022-10-27 17:41:42 +02:00
if command -v xrdb > /dev/null; then
2022-08-21 11:53:18 +02:00
xrdb -remove speedwm* && echo "Unloaded configuration"
else
echo "Unable to unload configuration" ; exit 1
fi
}
# Delete speedwm configuration
DELETECONFIG() {
2022-10-27 17:41:42 +02:00
if [ -e "$HOME/.config/speedwm/speedwmrc" ]; then
rm -f $HOME/.config/speedwm/speedwmrc && echo "Deleted $HOME/.config/speedwm/speedwmrc."
2022-08-21 11:53:18 +02:00
else
echo "Failed to delete configuration file." ; exit 1
fi
}
case "$ARGS" in
2022-09-11 01:24:54 +02:00
"") CHECKEXISTINGWM ; XRESOURCES ; AUTOSTART ; LOADSWAL ; LOADCONFIG ; RESET ; START_SPEEDWM ; exit 0 ;;
"-s") ISSFLAG=true ; CHECKEXISTINGWM ; XRESOURCES ; AUTOSTART ; LOADSWAL ; LOADCONFIG ; RESET ; START_SPEEDWM ; exit 0 ;;
2022-08-21 11:53:18 +02:00
"-r") XRESOURCES ; LOADSWAL ; LOADCONFIG ; RESET ; echo "Restarted speedwm." ; exit 0 ;;
2022-10-03 17:39:35 +02:00
"-rcolors") XRESOURCES ; LOADSWAL ; LOADCONFIG ; LOADCOLS ; echo "Restarted speedwm." ; exit 0 ;;
2022-10-05 13:42:45 +02:00
"-rnoloadcolors") LOADCONFIG ; LOADCOLS ; echo "Restarted speedwm." ; exit 0 ;;
2022-08-21 11:53:18 +02:00
"-rnoload") RESET ; echo "Restarted speedwm." ; exit 0 ;;
"-h") HELP ; exit 0 ;;
2022-09-11 01:24:54 +02:00
"-f") CARG="force" ; XRESOURCES ; AUTOSTART ; LOADSWAL ; LOADCONFIG ; RESET ; START_SPEEDWM ; exit 0 ;;
2022-08-21 11:53:18 +02:00
"-loadconfig") LOADCONFIG ; exit 0 ;;
"-unloadconfig") UNLOADCONFIG ; RESET ; exit 0 ;;
"-deleteconfig") DELETECONFIG ; RESET ; exit 0 ;;
2022-09-11 01:24:54 +02:00
"-noxrdb") START_SPEEDWM ; exit 0 ;;
2022-10-03 16:49:24 +02:00
"-stop") pgrep -x speedwm && pkill -x speedwm && echo "speedwm has been stopped." ; exit
2022-08-21 11:53:18 +02:00
echo "speedwm is not running, cannot stop it." ; exit 1 ;;
2022-09-11 01:24:54 +02:00
"-nomkconfig") CHECKEXISTINGWM ; XRESOURCES ; AUTOSTART ; LOADSWAL ; RESET ; START_SPEEDWM ; exit 0 ;;
2022-08-21 11:53:18 +02:00
esac
exit 0