aboutsummaryrefslogtreecommitdiff
path: root/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'helpers')
-rwxr-xr-xhelpers/bbask31
-rwxr-xr-xhelpers/bbcmd11
-rwxr-xr-xhelpers/bbconfirm9
-rwxr-xr-xhelpers/bbpause4
-rwxr-xr-xhelpers/bbpick39
-rwxr-xr-xhelpers/bbtargets25
-rwxr-xr-xhelpers/bbunscroll5
7 files changed, 124 insertions, 0 deletions
diff --git a/helpers/bbask b/helpers/bbask
new file mode 100755
index 0000000..ad446ec
--- /dev/null
+++ b/helpers/bbask
@@ -0,0 +1,31 @@
+#!/bin/sh
+# A simple user-input asker. Result is output to stdout.
+# Usage: ask [-1] [prompt [initial query]]
+if [ "$1" = '-1' ]; then
+ # Get one character of input
+ tput civis >/dev/tty;
+ printf '\033[1m%s\033[0m' "$2" >/dev/tty;
+ stty -icanon -echo >/dev/tty 2>/dev/tty;
+ if [ "$(uname)" = "Darwin" ]; then
+ read -n 1 REPLY </dev/tty >/dev/tty;
+ echo $REPLY
+ else
+ dd bs=1 count=1 2>/dev/null </dev/tty
+ fi
+ stty icanon echo >/dev/tty 2>/dev/tty
+ tput cvvis >/dev/tty
+else
+ # Get a line of input
+ if command -v ask >/dev/null; then
+ ask --history=bb.hist --prompt="$(printf '%s\033[?25h' "$1")" --query="$2"
+ else
+ printf "\033[1m%s\033[0m" "$1" >/dev/tty
+ tput cvvis >/dev/tty
+ if [ "$(uname)" = "Darwin" ]; then
+ read -e REPLY </dev/tty >/dev/tty
+ else
+ read REPLY </dev/tty >/dev/tty
+ fi
+ echo $REPLY
+ fi
+fi
diff --git a/helpers/bbcmd b/helpers/bbcmd
new file mode 100755
index 0000000..fdc4e78
--- /dev/null
+++ b/helpers/bbcmd
@@ -0,0 +1,11 @@
+#!/bin/sh
+if [ $# -eq 0 ]; then cat >> $BBCMD; exit; fi
+for arg; do
+ shift
+ if expr "$arg" : '^[^:]*:$' >/dev/null; then
+ if [ $# -gt 0 ]; then printf "$arg%s\\0" "$@" >> $BBCMD
+ else sed "s/\([^\\x00]\+\)/$arg\1/g" >> $BBCMD; fi
+ exit
+ fi
+ printf "%s\\0" "$arg" >> $BBCMD
+done
diff --git a/helpers/bbconfirm b/helpers/bbconfirm
new file mode 100755
index 0000000..cae1153
--- /dev/null
+++ b/helpers/bbconfirm
@@ -0,0 +1,9 @@
+#!/bin/sh
+# Ask for user confirmation
+set -e
+if command -v ask >/dev/null; then
+ ask -n "$(printf "$1Is that okay?\033[?25h")"
+else
+ reply="$(bbask -1 "$(printf "$1\033[0;1mIs that okay? [y/N] ")")"
+ [ "$reply" != 'y' ]
+fi
diff --git a/helpers/bbpause b/helpers/bbpause
new file mode 100755
index 0000000..6604fbd
--- /dev/null
+++ b/helpers/bbpause
@@ -0,0 +1,4 @@
+#!/bin/sh
+# Pause before continuing
+printf '\033[0;2m Press any key to continue...\033[0m' >/dev/tty
+bbask -1 >/dev/null
diff --git a/helpers/bbpick b/helpers/bbpick
new file mode 100755
index 0000000..3316484
--- /dev/null
+++ b/helpers/bbpick
@@ -0,0 +1,39 @@
+#!/bin/sh
+# Pick from the provided input
+if [ -z "$PICKER" ]; then
+ if command -v fzf >/dev/null; then
+ PICKER=fzf
+ elif command -v fzy >/dev/null; then
+ PICKER=fzy
+ elif command -v ask >/dev/null; then
+ PICKER=ask
+ elif command -v dmenu >/dev/null; then
+ PICKER=dmenu
+ elif command -v pick >/dev/null; then
+ PICKER=pick
+ fi
+fi
+
+case "$PICKER" in
+ fzf)
+ printf '\033[3A\033[?25h' >/dev/tty
+ fzf --read0 --height=4 --prompt="$(printf "$1")"
+ ;;
+ fzy)
+ printf '\033[3A\033[?25h' >/dev/tty
+ tr '\0' '\n' | fzy --lines=3 --prompt="$(printf "\033[1m$1\033[0m")"
+ ;;
+ ask)
+ ask --read0 --prompt="$(printf "$1\033[?25h")"
+ ;;
+ dmenu)
+ tr '\0' '\n' | dmenu -i -l 10 -p "$(printf "$1")"
+ ;;
+ pick)
+ printf '\033[?25h' >/dev/tty
+ tr '\0' '\n' | pick
+ ;;
+ *)
+ query="$(bbask "$1")" && grep -i -m1 "$(echo "$query" | sed 's;.;[^/&]*[&];g')"
+ ;;
+esac
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
diff --git a/helpers/bbunscroll b/helpers/bbunscroll
new file mode 100755
index 0000000..15102c4
--- /dev/null
+++ b/helpers/bbunscroll
@@ -0,0 +1,5 @@
+#!/bin/sh
+# Display text from the current line upward (instead of downward)
+input="$(cat)"
+printf "\\033[$(echo "$input" | wc -l)A\\033[J" >/dev/tty
+echo "$input"