speedwm-personal/scripts/speedwm_run
2022-08-23 15:55:28 +02:00

189 lines
6.7 KiB
Bash
Executable file

#!/bin/sh
# External script which starts speedwm!
# https://speedie.gq/speedwm for instructions and usage!
BINDIR=$(cat /usr/share/speedwm-bindir)
ARGS=$1
# No second argument is supported
if [ "$2" = "" ]; then
ARGS2=""
else
echo "Unknown argument: $2" ; exit 1
fi
HAVE_GRID="true"
if [ -e "$HOME/.config/speedwm-de/global/config" ]; then
. $HOME/.config/speedwm-de/global/config
else
mkdir -p $HOME/.config/speedwm-de/global
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-de/global/config
fi
if [ "$HAVE_GRID" = "true" ]; then
GRIDNUM="1"
fi
if [ "$HAVE_GRID" = "true" ]; then
GRIDARG="-g"
fi
# Don't make config if asked not to.
if [ -e "$HOME/.local/share/speedwm-do-not-mkconfig" ]; then
DONOTMKCONFIG=true
else
DONOTMKCONFIG=false
fi
# Load .Xresources if available
XRESOURCES() {
pgrep -x status > /dev/null && pkill status
if [ -e "$HOME/.Xresources" ]; then
if [ -e "${BINDIR}xrdb" ]; then
xrdb $HOME/.Xresources
fi
elif [ -e "$HOME/.config/.Xresources" ]; then
if [ -e "${BINDIR}xrdb" ]; then
xrdb $HOME/.config/.Xresources
fi
fi
}
# Load speedwm config, create if it does not exist.
LOADCONFIG() {
mkdir -p $HOME/.config/speedwm-de
if [ -e "${BINDIR}xrdb" ]; then
if [ "$DONOTMKCONFIG" = "false" ]; then
if [ -e "$HOME/.config/speedwm-de/speedwmrc" ]; then
xrdb -merge -quiet $HOME/.config/speedwm-de/speedwmrc
else
echo "! speedwm configuration file" > $HOME/.config/speedwm-de/speedwmrc && echo "Wrote comment 1"
echo "! This is your speedwm configuration file. It is configured in .Xresources syntax." >> $HOME/.config/speedwm-de/speedwmrc && echo "Wrote comment 2"
echo "! It is loaded on startup but you can reload it during runtime by running $0 -r.\n" >> $HOME/.config/speedwm-de/speedwmrc && echo "Wrote comment 3"
sed "s| - ||g" /usr/share/example.Xresources >> $HOME/.config/speedwm-de/speedwmrc && echo "Wrote example configuration file"
fi
fi
fi
}
LOADSWAL() {
if [ "$DONOTLOADCONFIG" = "true" ]; then
DONOTLOADCONFIG=true
else
$HOME/.config/speedwm-de/swal/swal_wm > /dev/null
echo "Loaded wallpaper and pywal colors"
fi
}
# Reset speedwm
RESET() {
if [ "$DONOTRELOAD" = "true" ]; then
DONOTRELOAD=true
else
xsetroot -name "Loading" # To hide the ugly fsignal status
xsetroot -name "fsignal:31" # Send fsignal to restart speedwm
xsetroot -name "Loading" # To hide the ugly fsignal status
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
START_DWM() {
speedwm-audioctrl -remute # Fix a weird bug
# Set starter if it's going to be used.
if [ -e "${BINDIR}sx" ]; then
starter="sx sh"
else
starter="startx"
fi
if [ "$ISSFLAG" = "" ]; then
while true; do
speedwm > /tmp/speedwm-log
done
else
$starter "speedwm_run -f > /tmp/speedwm-log-auto"
fi
}
# Config
CONFIGURE() {
test $HOME/.config/speedwm-de/speedwmrc && DOTFILE1="$HOME/.config/speedwm-de/speedwmrc"
test $HOME/.config/speedwm-de/dfmpeg/config && DOTFILE2="$HOME/.config/speedwm-de/dfmpeg/config"
test $HOME/.config/speedwm-de/powermenu/config && DOTFILE3="$HOME/.config/speedwm-de/powermenu/config"
test $HOME/.config/speedwm-de/screenshotutil/config && DOTFILE4="$HOME/.config/speedwm-de/screenshotutil/config"
test $HOME/.config/speedwm-de/status/config && DOTFILE5="$HOME/.config/speedwm-de/status/config"
test $HOME/.config/speedwm-de/swal/config && DOTFILE6="$HOME/.config/speedwm-de/swal/config"
test $HOME/.config/speedwm-de/systray/config && DOTFILE7="$HOME/.config/speedwm-de/systray/config"
test $HOME/.config/speedwm-de/winnav/config && DOTFILE8="$HOME/.config/speedwm-de/winnav/config"
test $HOME/.config/speedwm-de/global/config && DOTFILE9="$HOME/.config/speedwm-de/global/config"
case "$TERMINAL" in
"") TERMINAL="st -e"
esac
case "$EDITOR" in
"") EDITOR='vim'
esac
case "$RUNLAUNCHER" in
"") RUNLAUNCHER=dmenu
esac
$TERMINAL $EDITOR "$(printf "$DOTFILE1\n$DOTFILE2\n$DOTFILE3\n$DOTFILE4\n$DOTFILE5\n$DOTFILE6\n$DOTFILE7\n$DOTFILE8\n$DOTFILE9" | $RUNLAUNCHER -l 8 $GRIDARG $GRIDNUM -p "Edit which configuration?")"
}
# List of arguments
HELP() {
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-configure | Bring up a list of speedwm-de dotfiles in $RUNLAUNCHER and ask the user which one to open in \$EDITOR inside \$TERMINAL"
}
# Unload speedwm configuration
UNLOADCONFIG() {
if [ -e "${BINDIR}xrdb" ]; then
xrdb -remove speedwm* && echo "Unloaded configuration"
else
echo "Unable to unload configuration" ; exit 1
fi
}
# Delete speedwm configuration
DELETECONFIG() {
if [ -e "$HOME/.config/speedwm-de/speedwmrc" ]; then
rm -f $HOME/.config/speedwm-de/speedwmrc && echo "Deleted $HOME/.config/speedwm-de/speedwmrc."
else
echo "Failed to delete configuration file." ; exit 1
fi
}
case "$ARGS" in
"") CHECKEXISTINGWM ; XRESOURCES ; LOADSWAL ; LOADCONFIG ; RESET ; START_DWM ; exit 0 ;;
"-s") ISSFLAG=true ; CHECKEXISTINGWM ; XRESOURCES ; LOADSWAL ; LOADCONFIG ; RESET ; START_DWM ; exit 0 ;;
"-configure") CONFIGURE ; exit 0 ;;
"-r") XRESOURCES ; LOADSWAL ; LOADCONFIG ; RESET ; echo "Restarted speedwm." ; exit 0 ;;
"-rnoload") RESET ; echo "Restarted speedwm." ; exit 0 ;;
"-h") HELP ; exit 0 ;;
"-f") CARG="force" ; XRESOURCES ; LOADSWAL ; LOADCONFIG ; RESET ; START_DWM ; exit 0 ;;
"-loadconfig") LOADCONFIG ; exit 0 ;;
"-unloadconfig") UNLOADCONFIG ; RESET ; exit 0 ;;
"-deleteconfig") DELETECONFIG ; RESET ; exit 0 ;;
"-noxrdb") START_DWM ; exit 0 ;;
"-stop") pgrep -x speedwm && pkill speedwm ; echo "speedwm has been stopped." ; exit 0
echo "speedwm is not running, cannot stop it." ; exit 1 ;;
"-nomkconfig") CHECKEXISTINGWM ; XRESOURCES ; LOADSWAL ; RESET ; START_DWM ; exit 0 ;;
esac
exit 0