diff --git a/docs/example.Xresources b/docs/example.Xresources index d57a56a..c0caf30 100644 --- a/docs/example.Xresources +++ b/docs/example.Xresources @@ -224,7 +224,7 @@ speedwm.layout.monocle.count: 0 ! Enable focused client and number of t speedwm.layout.monocle.format: [%d/%d] !! Custom layout -speedwm.layout.custom.cmd: printf '' | spmenu -i -l 10 -p 'Enter S expression:' +speedwm.layout.custom.cmd: speedwm-sxp !! mfact options speedwm.mfact: 0.50 ! Default mfact (0-1) diff --git a/options.h b/options.h index c207ed4..0b58f03 100755 --- a/options.h +++ b/options.h @@ -153,7 +153,7 @@ static int deckcount = 0; /* Display deck count in the deck layout */ static char deckformat[] = "[%d]"; /* Format of the deck count. deckcount must be set to 1 for this to be used. */ /* Custom layout */ -static char *custom_cmd = "printf '' | spmenu -i -l 10 -p 'Enter S expression:'"; /* Command to run when setting S expression */ +static char *custom_cmd = "speedwm-sxp"; /* Command to run when setting S expression */ /* Resetting */ static int resetlayout = 0; /* Reset layout when there is only one client visible */ diff --git a/scripts/speedwm-sxp b/scripts/speedwm-sxp new file mode 100755 index 0000000..56f8df3 --- /dev/null +++ b/scripts/speedwm-sxp @@ -0,0 +1,24 @@ +#!/bin/sh +# speedwm-sxp + +# function which returns history +MENU_DATA() { cat "$CUSTOM_HISTFILE"; printf "%s\nClear\nExit\n" "------"; } + +# basic variables +[ -z "$CUSTOM_HISTFILE" ] && CUSTOM_HISTFILE="$HOME/.config/speedwm/.custom_history" +[ -z "$RUNLAUNCHER" ] && RUNLAUNCHER="spmenu" + +# make sure $CUSTOM_HISTFILE exists +mkdir -p "$(dirname "$CUSTOM_HISTFILE")"; touch "$CUSTOM_HISTFILE" + +# prompt the user +OP="$(MENU_DATA | "$RUNLAUNCHER" -g 1 -l 40 -p 'Enter an S expression:')" + +# parse current expression +[ "$OP" = "Clear" ] && printf "" > "$CUSTOM_HISTFILE" && exit +[ "$OP" = "Exit" ] && exit 0 +[ "$OP" = "------" ] && exit 0 +[ -z "$OP" ] && exit 0 + +# write expression +printf "%s\n" "$OP" >> "$CUSTOM_HISTFILE"