Recently Written · git

sh

Small shell and Python scripts

git clone https://github.com/equwal/sh

Log | Files | Refs


commit 0058aae9a138e2ab5a37ac9eb25d6d9bd182ae9d
equwal <13551856+equwal@users.noreply.github.com>
2026-10-04 23:46:25 -0700

dsad: add the dmenu front end for sad; match menu entries exactly, run sad-add and sad-menu as commands

 dsad | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
diff --git a/dsad b/dsad
new file mode 100755
index 0000000..e2c0594
--- /dev/null
+++ b/dsad
@@ -0,0 +1,52 @@
+#!/bin/sh
+# dmenu script for sad
+# - requires BSD-style netcat with -N (it is in gentoo and arch packagers, at least)
+# - requires sadcmd
+PROMPT="sad? "
+
+# hint: order the following however you want.
+
+CUSTOMCMDS="sad-menu
+sad-start
+sad-toggle-play"
+
+ZEROCMDS="next
+prev
+stop
+kill
+random
+repeat
+clear
+playlist
+close
+ping
+uptime
+version"
+
+ARGCMDS="sad-add file/dir
+sad-add-playlist playlist.ply
+add path
+volume 0-100
+pause [0|1]
+play [ID]
+remove [ID]
+enable output
+disable output"
+
+# Echo, fixed so only the first argument can be flags.
+cmd=$(printf "%s\\n%s\\n%s"  "$CUSTOMCMDS" "$ZEROCMDS" "$ARGCMDS" \
+      | dmenu -i -l "$(printf "%s\\n%s\\n%s"  "$CUSTOMCMDS" "$ZEROCMDS" "$ARGCMDS" | wc -l -)" -p "$PROMPT" \
+      | cut -f1 -d ' ')
+
+printf "%s" "$CUSTOMCMDS" | grep -qxF -- "$cmd" \
+    && "$cmd"  && exit 0
+printf "%s" "$ZEROCMDS"   | grep -qxF -- "$cmd" \
+    && sad-cmd "$cmd" && exit 0
+hint=$(printf "%s\n" "$ARGCMDS" | awk -v c="$cmd" '$1 == c {print $2}')
+case $cmd in sad-*) run=$cmd ;; *) run="sad-cmd $cmd" ;; esac
+[ -n "$hint" ] \
+    && $run "$(printf "" | dmenu -i -l 0 -p "arg $hint? ")" \
+    && exit 0
+
+# not an arg
+exit 1