aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2020-02-24 03:39:44 -0800
committerBruce Hill <bruce@bruce-hill.com>2020-02-24 03:39:44 -0800
commit88fd9c416be0f5fe1e5fd48ba7c27d4d1e25261c (patch)
treecfe311fb81c1d12e46b08de175a6296f0aed7a0d /scripts
parent304cbddf730b86dec2b3d7c414fd0b9a38c69d76 (diff)
Moved bbstartup into a script, renamed helper/ -> scripts/, and added
bbshutdown script. Also tweaked some of the precedence.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/bbask31
-rwxr-xr-xscripts/bbcmd11
-rwxr-xr-xscripts/bbconfirm9
-rwxr-xr-xscripts/bbpause4
-rwxr-xr-xscripts/bbpick39
-rwxr-xr-xscripts/bbshutdown3
-rwxr-xr-xscripts/bbstartup15
-rwxr-xr-xscripts/bbtargets25
-rwxr-xr-xscripts/bbunscroll5
9 files changed, 142 insertions, 0 deletions
diff --git a/scripts/bbask b/scripts/bbask
new file mode 100755
index 0000000..ad446ec
--- /dev/null
+++ b/scripts/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/scripts/bbcmd b/scripts/bbcmd
new file mode 100755
index 0000000..fdc4e78
--- /dev/null
+++ b/scripts/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/scripts/bbconfirm b/scripts/bbconfirm
new file mode 100755
index 0000000..cae1153
--- /dev/null
+++ b/scripts/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/scripts/bbpause b/scripts/bbpause
new file mode 100755
index 0000000..6604fbd
--- /dev/null
+++ b/scripts/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/scripts/bbpick b/scripts/bbpick
new file mode 100755
index 0000000..3316484
--- /dev/null
+++ b/scripts/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/scripts/bbshutdown b/scripts/bbshutdown
new file mode 100755
index 0000000..368fd2f
--- /dev/null
+++ b/scripts/bbshutdown
@@ -0,0 +1,3 @@
+#!/bin/sh
+# This file gets run when `bb` shuts down.
+echo "bbcmd glob:'$BBGLOB' sort:'$BBSORT' columns:'$BBCOLUMNS' $BBINTERLEAVE" > "$XDG_DATA_HOME"/bb/settings.sh
diff --git a/scripts/bbstartup b/scripts/bbstartup
new file mode 100755
index 0000000..40de50b
--- /dev/null
+++ b/scripts/bbstartup
@@ -0,0 +1,15 @@
+#!/bin/sh
+# This file contains the script that is run when bb launches
+
+[ ! -d "$XDG_DATA_HOME/bb" ] && mkdir -p "$XDG_DATA_HOME/bb"
+
+# Load key bindings
+if [ "$BBPATH" ]; then
+ cat "$BBPATH/bindings.bb" "$XDG_CONFIG_HOME/bb/bindings.bb"
+else
+ cat "$sysconfdir/xdg/bb/bindings.bb" "$XDG_CONFIG_HOME/bb/bindings.bb"
+fi 2>/dev/null | awk '/^#/ {next} /^[^ ]/ {printf "\0bind:"} {print $0} END {printf "\0"}' >> "$BBCMD"
+
+if [ -e "$XDG_DATA_HOME/bb/settings.sh" ]; then
+ . "$XDG_DATA_HOME/bb/settings.sh"
+fi
diff --git a/scripts/bbtargets b/scripts/bbtargets
new file mode 100755
index 0000000..1862ca0
--- /dev/null
+++ b/scripts/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/scripts/bbunscroll b/scripts/bbunscroll
new file mode 100755
index 0000000..15102c4
--- /dev/null
+++ b/scripts/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"