From 1dc2461e2c7e2adfd4cbc6eda586b58ac5b7aae6 Mon Sep 17 00:00:00 2001 From: speedie Date: Thu, 1 Sep 2022 20:05:10 +0200 Subject: [PATCH] better comments, remove useless arguments --- scripts/speedwm-swal | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/scripts/speedwm-swal b/scripts/speedwm-swal index f349112..7e28769 100755 --- a/scripts/speedwm-swal +++ b/scripts/speedwm-swal @@ -20,6 +20,7 @@ SWAL_DEFAULT_CONFIG() SWAL_RANDOMIZE=false # Select a random wallpaper on login } +# By default, assume we have grid. HAVE_GRID="true" if [ -e "$HOME/.config/speedwm-de/global/config" ]; then . $HOME/.config/speedwm-de/global/config @@ -28,15 +29,18 @@ else 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 +# Grid number is one if [ "$HAVE_GRID" = "true" ]; then GRIDNUM="1" fi +# Grid argument if [ "$HAVE_GRID" = "true" ]; then GRIDARG="-g" fi +# Create the configuration SWAL_MKCONFIG() { mkdir -p $SWAL_EXPORTDIR touch $SWAL_EXPORTDIR/config @@ -111,6 +115,7 @@ SOLIDCOLOR() { exit 0 } +# Binary directory BINDIR=$(cat /usr/share/speedwm-bindir) SWAL_OLDWALLPAPERDIR=$SWAL_WALLPAPERDIR @@ -121,6 +126,7 @@ SWAL_SOURCE() . "$SWAL_EXPORTDIR/config" || rm -f "$SWAL_EXPORTDIR/config" } +# Set image viewer if none is specified. SWAL_CHECK() { if [ "$SWAL_IMAGE_VIEWER" = "" ]; then @@ -131,18 +137,19 @@ SWAL_CHECK() ls "$SWAL_BINDIR/xwallpaper" || SWAL_DIE } +# Die SWAL_DIE() { SWAL_EXIT=1 && exit 1 } +# Print help SWAL_HELP() { - echo "swal is a minimal xwallpaper frontend for dmenu/rofi." - echo "-w /path/to/wallpaper.png | Set the wallpaper specified." + echo "swal is a minimal xwallpaper frontend for $RUNLAUNCHER." echo "-h | View this help screen." - echo "-f X | fsignal signum to reload .Xresources (with reloadxresources, fsignal and .Xresources speedwm patches)" } +# Print usage. SWAL_USAGE() { echo "To set a wallpaper, you must create a configuration. To do this, select 'Options' in the menu and set all the options to your liking." echo "The image viewer must be set to an image viewer that supports printing the filename to stdout. If you use sxiv, set the image viewer to 'sxiv -o'." @@ -152,28 +159,16 @@ SWAL_USAGE() { echo "For more information, see speedwm-help -a." } +# Select wallpaper SWAL_SELWALLPAPER() { case "$NEW1" in "") ls /tmp/swal_cpath || SWAL_SELWALLPAPER="$(printf "$(ls "$SWAL_WALLPAPERDIR")\n------\n..\nPreview\nPrevious\nSolid Color\nRandom\nFavorites\nAdd used wallpaper to favorites\nOptions\nHelp\nExit" | $RUNLAUNCHER $GRIDARG $GRIDNUM -l 100 -p "What wallpaper would you like to set?")" ;; - "-w") SWAL_SELWALLPAPER="$(basename "$NEW2")" && touch /tmp/swal_cpath ;; "-h") SWAL_HELP | $RUNLAUNCHER $GRIDARG $GRIDNUM 1 -l 90 ;; - "-f") SWAL_FSIGNAL_RELOAD_XRESOURCES="$NEW2" ;; - esac - - case "$NEW3" in - "-w") SWAL_SELWALLPAPER="$(basename "$NEW4")" && touch /tmp/swal_cpath ;; - "-h") SWAL_HELP | $RUNLAUNCHER $GRIDARG $GRIDNUM -l 90 ;; - "-f") SWAL_FSIGNAL_RELOAD_XRESOURCES="$NEW4" ;; - esac - - case "$NEW5" in - "-w") SWAL_SELWALLPAPER="$(basename "$NEW6")" && touch /tmp/swal_cpath ;; - "-h") SWAL_HELP | $RUNLAUNCHER $GRIDARG $GRIDNUM -l 90 ;; - "-f") SWAL_FSIGNAL_RELOAD_XRESOURCES="$NEW6" ;; esac } +# Set the type/check what was selected. SWAL_SETTYPE() { case "$SWAL_SELWALLPAPER" in @@ -191,6 +186,7 @@ SWAL_SETTYPE() "------") $0 && exit 0 ;; esac + # Favorites feature if [ "$FAVORITES" = "true" ]; then case "$SWAL_SELWALLPAPER" in "") $0 && exit 0 ;; @@ -216,6 +212,7 @@ SWAL_SETTYPE() cd "$SWAL_WALLPAPERDIR/$SWAL_SELWALLPAPER" && SWAL_WALLPAPERDIR="$SWAL_WALLPAPERDIR/$SWAL_SELWALLPAPER" && SWAL_SELWALLPAPER && SET && exit 0 fi + # Fail if the wallpaper is not a proper wallpaper. FAIL_NOT_REAL() { test ${BINDIR}notify-send && notify-send "The selected wallpaper is not valid/does not exist." $0 ; exit 1 @@ -235,9 +232,11 @@ SWAL_SETTYPE() "") $0 && exit 0 ;; esac + # Set variables so that we can use them with xwallpaper directly. SWAL_TYPE="--$SWAL_TYPE" SWAL_WAL_STATUS="0" + # Check whether or not to ask based on configuration file. case "$SWAL_ASK_WAL" in "true") command -v wal > /dev/null && SWAL_USE_WAL=$(printf "Yes\nNo" | $RUNLAUNCHER $GRIDARG $GRIDNUM -l 90 -p "Do you want to use Pywal?" -l 2) && SWAL_WAL_STATUS="1" ;; "false") command -v wal > /dev/null && SWAL_USE_WAL="Yes" && SWAL_WAL_STATUS="1" ;; @@ -249,6 +248,7 @@ SWAL_SETTYPE() fi } +# Set the wallpaper. SWAL_SETWALLPAPER() { $SWAL_OPT $SWAL_TYPE "$SWAL_WALLPAPERDIR/$SWAL_SELWALLPAPER" || FAIL_NOT_REAL