bb/helpers/bbtargets
Bruce Hill 865092c656 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.
2020-02-24 01:31:39 -08:00

26 lines
722 B
Bash
Executable File

#!/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