speedwm-personal/scripts/speedwm_run
speediegq a7ef306ac0 Fix lots and lots of bugs and remove old layouts that do not have gaps.
Add new "custom" layout that allows you to create your own layouts.
2022-10-11 17:11:31 +02:00

215 lines
6.8 KiB
Bash
Executable file

#!/bin/sh
# speedwm_run
# External script which starts speedwm!
# https://speedie.gq/speedwm for instructions and usage!
BINDIR="$(dirname $(command -v status))/"
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 -x 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
sed "s| - ||g" /usr/share/example.Xresources > $HOME/.config/speedwm-de/speedwmrc && echo "Wrote example configuration file"
fi
fi
fi
}
# Load wallpaper config
LOADSWAL() {
if [ "$DONOTLOADCONFIG" = "true" ]; then
DONOTLOADCONFIG=true
else
$HOME/.config/speedwm-de/swal/swal_wm > /dev/null
echo "Loaded wallpaper and pywal colors"
fi
}
# Load colors
LOADCOLS() {
if [ "$DONOTLOADCONFIG" = "true" ]; then
DONOTLOADCONFIG=true
else
xsetroot -name "fsignal:66" # reload colors
xsetroot -name "Loading" # hide the ugly fsignal
echo "Loaded colors"
fi
}
# Autostart
AUTOSTART() {
if [ -e "$HOME/.config/speedwm-de/autostart_once.sh" ]; then
$HOME/.config/speedwm-de/autostart_once.sh
fi
}
# Reset speedwm
RESET() {
if [ "$DONOTRELOAD" = "true" ]; then
DONOTRELOAD=true
else
xsetroot -name "Loading" # To hide the ugly fsignal status
xsetroot -name "fsignal:27" # 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_SPEEDWM() {
# 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/winnav/config && DOTFILE7="$HOME/.config/speedwm-de/winnav/config"
test $HOME/.config/speedwm-de/global/config && DOTFILE8="$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" | $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\n"
}
# 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 ; AUTOSTART ; LOADSWAL ; LOADCONFIG ; RESET ; START_SPEEDWM ; exit 0 ;;
"-s") ISSFLAG=true ; CHECKEXISTINGWM ; XRESOURCES ; AUTOSTART ; LOADSWAL ; LOADCONFIG ; RESET ; START_SPEEDWM ; exit 0 ;;
"-configure") CONFIGURE ; exit 0 ;;
"-r") XRESOURCES ; LOADSWAL ; LOADCONFIG ; RESET ; echo "Restarted speedwm." ; exit 0 ;;
"-rcolors") XRESOURCES ; LOADSWAL ; LOADCONFIG ; LOADCOLS ; echo "Restarted speedwm." ; exit 0 ;;
"-rnoloadcolors") LOADCONFIG ; LOADCOLS ; echo "Restarted speedwm." ; exit 0 ;;
"-rnoload") RESET ; echo "Restarted speedwm." ; exit 0 ;;
"-h") HELP ; exit 0 ;;
"-f") CARG="force" ; XRESOURCES ; AUTOSTART ; LOADSWAL ; LOADCONFIG ; RESET ; START_SPEEDWM ; exit 0 ;;
"-loadconfig") LOADCONFIG ; exit 0 ;;
"-unloadconfig") UNLOADCONFIG ; RESET ; exit 0 ;;
"-deleteconfig") DELETECONFIG ; RESET ; exit 0 ;;
"-noxrdb") START_SPEEDWM ; exit 0 ;;
"-stop") pgrep -x speedwm && pkill -x speedwm && echo "speedwm has been stopped." ; exit
echo "speedwm is not running, cannot stop it." ; exit 1 ;;
"-nomkconfig") CHECKEXISTINGWM ; XRESOURCES ; AUTOSTART ; LOADSWAL ; RESET ; START_SPEEDWM ; exit 0 ;;
esac
exit 0