From 7daa148e946d234de88c185dcf5e75000d73fdb8 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 28 Jan 2021 22:17:15 -0800 Subject: [PATCH] Renamed $BBCURSOR -> $BB for concision --- API.md | 4 ++-- bb.c | 2 +- bbcmd.1 | 2 +- scripts/bbbindkeys | 38 +++++++++++++++++++------------------- scripts/bbtargets | 2 +- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/API.md b/API.md index 71bbd1b..ea2e9f2 100644 --- a/API.md +++ b/API.md @@ -30,7 +30,7 @@ own version there. failure if the user does not press 'y'. - `bbpause`: Display a "press any key to continue" message and wait for a keypress. - `bbpick [prompt]`: Select one of `NULL`-delimited multiple inputs and print it. -- `bbtargets "$BBCMD" "$@"`: If `$BBCURSOR` is not currently among `$@` (the +- `bbtargets "$BBCMD" "$@"`: If `$BB` is not currently among `$@` (the selected files), this script prompts the user to ask whether they want to perform an action on the selected files, or on the cursor. The result is printed as `cursor` or `selected`. @@ -41,7 +41,7 @@ own version there. When `bb` runs scripts, following values are provided as environment variables: - `$@` (the list of arguments): the full paths of the selected files -- `$BBCURSOR`: the full path of the file under the cursor +- `$BB`: the full path of the file under the cursor - `$BBDEPTH`: the number of `bb` instances deep (in case you want to run a shell and have that shell print something special in the prompt) - `$BBCMD`: a file to which `bb` commands can be written (used internally) diff --git a/bb.c b/bb.c index 960fbe7..ad719ba 100644 --- a/bb.c +++ b/bb.c @@ -824,7 +824,7 @@ static int run_script(bb_t *bb, const char *cmd) for (entry_t *e = bb->selected; e; e = e->selected.next) args[--i] = e->fullname; - setenv("BBCURSOR", bb->nfiles ? bb->files[bb->cursor]->fullname : "", 1); + setenv("BB", bb->nfiles ? bb->files[bb->cursor]->fullname : "", 1); dup2(fileno(tty_out), STDOUT_FILENO); dup2(fileno(tty_in), STDIN_FILENO); diff --git a/bbcmd.1 b/bbcmd.1 index ed7249b..8824fd4 100644 --- a/bbcmd.1 +++ b/bbcmd.1 @@ -210,7 +210,7 @@ Navigate to /usr/local/ .TP .B -bbcmd select:"$BBCURSOR" move:+1 +bbcmd select:"$BB" move:+1 Select the file under the cursor, then move the cursor down one file. .TP diff --git a/scripts/bbbindkeys b/scripts/bbbindkeys index 5b3cb38..56ae454 100755 --- a/scripts/bbbindkeys +++ b/scripts/bbbindkeys @@ -36,7 +36,7 @@ bbcmd move:-1 bbcmd cd:.. ## l,Right: Enter directory -if [ -d "$BBCURSOR" ]; then bbcmd cd:"$BBCURSOR"; fi +if [ -d "$BB" ]; then bbcmd cd:"$BB"; fi ## Ctrl-f: Search for file file="$(find . -mindepth 1 -printf '%P\0' | bbpick "Find: ")" @@ -102,7 +102,7 @@ bbcmd scroll:-3 ## Section: File Selection ## v,V,Space: Toggle selection at cursor -bbcmd toggle:"$BBCURSOR" +bbcmd toggle:"$BB" ## Escape: Clear selection bbcmd deselect @@ -159,22 +159,22 @@ elif [ "$BBCLICKED" ]; then fi ## Enter,Double left click: Open file/directory -if [ -d "$BBCURSOR" ]; then bbcmd cd:"$BBCURSOR" +if [ -d "$BB" ]; then bbcmd cd:"$BB" elif [ "$(uname)" = "Darwin" ]; then - if expr "$(file -bI "$BBCURSOR")" : '\(text/\|inode/empty\)' >/dev/null; then $EDITOR "$BBCURSOR" - else open "$BBCURSOR"; fi + if expr "$(file -bI "$BB")" : '\(text/\|inode/empty\)' >/dev/null; then $EDITOR "$BB" + else open "$BB"; fi else - if expr "$(file -bi "$BBCURSOR")" : '\(text/\|inode/x-empty\)' >/dev/null; then $EDITOR "$BBCURSOR" - else xdg-open "$BBCURSOR"; fi + if expr "$(file -bi "$BB")" : '\(text/\|inode/x-empty\)' >/dev/null; then $EDITOR "$BB" + else xdg-open "$BB"; fi fi ## e: Edit file in $EDITOR -$EDITOR "$BBCURSOR" +$EDITOR "$BB" ## d,Delete: Delete -case "$(bbtargets "$BBCURSOR" "$@")" in - cursor) set -- "$BBCURSOR" ;; - both) set -- "$BBCURSOR" "$@" ;; +case "$(bbtargets "$BB" "$@")" in + cursor) set -- "$BB" ;; + both) set -- "$BB" "$@" ;; esac printf "\033[1mDeleting the following:\n\033[33m$(printf ' %s\n' "$@")\033[0m" | bbunscroll | more bbconfirm @@ -217,12 +217,12 @@ esac bbcmd goto:"$name" refresh ## p: Page through a file with `less` -less -XK "$BBCURSOR" +less -XK "$BB" ## r,F2: Rename files -case "$(bbtargets "$BBCURSOR" "$@")" in - cursor) set -- "$BBCURSOR";; - both) set -- "$BBCURSOR" "$@";; +case "$(bbtargets "$BB" "$@")" in + cursor) set -- "$BB";; + both) set -- "$BB" "$@";; esac for f; do newname="$(bbask "Rename $(printf "\033[33m%s\033[39m" "${f##*/}"): " "${f##*/}")" || break @@ -232,7 +232,7 @@ for f; do && bbconfirm && { rm -rf "$r" || { bbpause; exit; }; } mv "$f" "$r" || { bbpause; exit; } bbcmd deselect:"$f" select:"$r" - [ "$f" = "$BBCURSOR" ] && bbcmd goto:"$r" + [ "$f" = "$BB" ] && bbcmd goto:"$r" done bbcmd refresh @@ -259,21 +259,21 @@ bbcmd refresh ## |: Pipe selected files to a command cmd="$(bbask '|')" -if [ $# -eq 0 ]; then set -- "$BBCURSOR"; fi +if [ $# -eq 0 ]; then set -- "$BB"; fi printf '%s\n' "$@" | sh -c "$cmd" || true bbpause bbcmd refresh ## @: Pass selected files as args to a command cmd="$(bbask '@')" -if [ $# -eq 0 ]; then set -- "$BBCURSOR"; fi +if [ $# -eq 0 ]; then set -- "$BB"; fi sh -c "$cmd \"\$@\"" -- "$@" || true bbpause bbcmd refresh ## $: Pass the cursor as an argument to a command cmd="$(bbask '$')" -sh -c "$cmd \"\$1\"" -- "$BBCURSOR" || true +sh -c "$cmd \"\$1\"" -- "$BB" || true bbpause bbcmd refresh diff --git a/scripts/bbtargets b/scripts/bbtargets index dff50c9..3b47cc7 100755 --- a/scripts/bbtargets +++ b/scripts/bbtargets @@ -2,7 +2,7 @@ # 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" "$@" +# Usage: targets "$BB" "$@" cursor="$1" shift if [ $# -gt 0 ]; then