#!/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 # 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 "! dynamic window manager 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 while true; do speedwm > /tmp/speedwm-log done } # 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" 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 -g 1 -p "Edit which configuration?")" } # List of arguments HELP() { printf "dynamic window manager\nNo arguments | Start speedwm using default options\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 ;; "-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