aboutsummaryrefslogtreecommitdiff
path: root/helpers/bbtargets
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2020-02-24 01:31:39 -0800
committerBruce Hill <bruce@bruce-hill.com>2020-02-24 01:31:39 -0800
commit865092c656af70bd5317513d8e0ed87fdc1c9acd (patch)
treec4311c89b75322b4bb9d7f3547ff0534b935d68f /helpers/bbtargets
parenta8fd1743191bdb0a7453a2d90055e9dcc61a5ece (diff)
Major update: instead of defining all the helper functions as static
C-strings prefixed to commands (modified by the Makefile), the helper functions are now standalone scripts in the helpers/ dir, which gets added to "$PATH" when running bb.
Diffstat (limited to 'helpers/bbtargets')
-rwxr-xr-xhelpers/bbtargets25
1 files changed, 25 insertions, 0 deletions
diff --git a/helpers/bbtargets b/helpers/bbtargets
new file mode 100755
index 0000000..1862ca0
--- /dev/null
+++ b/helpers/bbtargets
@@ -0,0 +1,25 @@
+#!/bin/sh
+# If the user is doing something ambiguous, like selecting a bunch of files,
+# moving the cursor off of those files, then doing an action, this will ask
+# what they mean to target, then output either 'cursor' or 'selected'.
+# Usage: targets "$BBCURSOR" "$@"
+cursor="$1"
+shift
+if [ $# -gt 0 ]; then
+ for f in "$@"; do
+ if [ "$f" = "$cursor" ]; then
+ intended='Selected files'
+ break
+ fi
+ done
+else
+ intended='Cursor file'
+fi
+
+[ -z "$intended" ] && intended="$(printf '%s\0' 'Cursor file' 'Selected files' 'Both' | bbpick 'Which do you want to delete? ')"
+
+case "$intended" in
+ Cursor*) echo cursor ;;
+ Selected*) echo selected ;;
+ Both) echo both ;;
+esac