diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2023-10-15 02:04:48 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2023-10-15 02:04:48 -0400 |
| commit | 03f0c2ad987c6971a546a4617c7d976d92e79d80 (patch) | |
| tree | 7995ea7429892282f7a11318b8f9044400966c00 /scripts/bbkeys | |
| parent | f3938061b90c0cdd2ce14f606dcc7abd04e7a457 (diff) | |
Tweaks to actions
Diffstat (limited to 'scripts/bbkeys')
| -rwxr-xr-x | scripts/bbkeys | 67 |
1 files changed, 23 insertions, 44 deletions
diff --git a/scripts/bbkeys b/scripts/bbkeys index 97bad28..644e007 100755 --- a/scripts/bbkeys +++ b/scripts/bbkeys @@ -180,16 +180,6 @@ fi ## e: Edit file in $EDITOR $EDITOR "$BB" -## d,Delete: Delete -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 -rm -rf "$@" -bbcmd deselect refresh - ## Ctrl-v: Move files here printf "\033[1mMoving the following to here:\n\033[33m$(printf ' %s\n' "$@")\033[0m" | bbunscroll | more bbconfirm @@ -225,40 +215,6 @@ case "$(printf '%s\0' File Directory | bbpick "Create new: ")" in esac bbcmd goto:"$name" refresh -## p: Page through a file with `less` -less -XK "$BB" - -## r,F2: Rename files -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 - r="$(dirname "$f")/$newname" - [ "$r" = "$f" ] && continue - [ -e "$r" ] && printf "\033[31;1m$r already exists! It will be overwritten.\033[0m " - && bbconfirm && { rm -rf "$r" || { bbpause; exit; }; } - mv "$f" "$r" || { bbpause; exit; } - bbcmd deselect:"$f" select:"$r" - [ "$f" = "$BB" ] && bbcmd goto:"$r" -done -bbcmd refresh - -## ~: Regex rename files -if ! command -v rename >/dev/null; then - printf '\033[31;1mThe `rename` command is not installed. Please install it to use this key binding.\033[0m\n' - bbpause; exit 1 -fi -if [ $# -eq 0 ]; then set -- $BBGLOB; fi -patt="$(bbask "Replace pattern: ")" -rep="$(bbask "Replacement: ")" -printf "\033[1mRenaming:\n\033[33m$(rename -nv "$patt" "$rep" "$@")\033[0m" | bbunscroll | more -bbconfirm -rename -i "$patt" "$rep" "$@" -bbcmd deselect refresh - - ## Section: Shell Commands ## Colon: Run a command cmd="$(bbask ':')" @@ -322,3 +278,26 @@ key="$(bbask -1 "Press key to bind...")" echo script="$(bbask "Bind script: ")" bbcmd bind:"$key":"{ $script; } || bbpause" + +## 1: Run action on files +missing_cursor() { + for f; do + if [ "$f" = "$BB" ]; then return 1; fi + done +} +if [ $# -gt 0 ]; then + if missing_cursor "$@"; then + intended="$(printf '%s\0' 'Cursor file' 'Selected files' 'Both' | bbpick 'Which do you mean? ')" + case "$intended" in + Cursor*) set -- "$BB";; + Selected*) ;; + Both) set -- "$BB" "$@" ;; + *) exit 1;; + esac + fi +else + set -- "$BB" +fi +picked=$(sed -n 's/^## *//p' /etc/bb/bbactions | fzf --height=1) +[ -n "$picked" ] || exit 1 +sh -c "$(bp "$picked"'\(\n braces)' /etc/bb/bbactions)" -- "$@" || bbpause |
