diff options
| -rw-r--r-- | bb.h | 7 | ||||
| -rwxr-xr-x | bbstartup.sh | 10 | ||||
| -rw-r--r-- | bindings.bb | 16 |
3 files changed, 21 insertions, 12 deletions
@@ -264,6 +264,11 @@ static const char *bbcmdfn = "bb() {\n" " printf \"%s\\0\" \"$arg\" >> $BBCMD;\n" " done;\n" "}\n" +"butt() {\n" +" input=\"$(cat)\"\n" +" printf \"\\033[$(echo \"$input\" | wc -l)A\\033[J\" >/dev/tty\n" +" echo \"$input\"\n" +"}\n" "ask() {\n" #ifdef ASK ASK ";\n" @@ -290,7 +295,7 @@ ASK1 ";\n" #ifdef CONFIRM CONFIRM ";\n" #else -" ask1 REPLY \"\033[1mIs that okay? [y/N] \" && [ \"$REPLY\" = 'y' ];\n" +" ask1 REPLY \"$1\033[0;1mIs that okay? [y/N] \" && [ \"$REPLY\" = 'y' ];\n" #endif "}\n" "pause() {\n" diff --git a/bbstartup.sh b/bbstartup.sh index e46ef64..38bea99 100755 --- a/bbstartup.sh +++ b/bbstartup.sh @@ -18,7 +18,11 @@ mark marks "$XDG_CONFIG_HOME/bb/marks" # Load key bindings # first check ~/.config/bb/bindings.bb, then /etc/xdg/bb/bindings.bb, then ./bindings.bb -for path in "$XDG_CONFIG_HOME/bb" "$sysconfdir/xdg/bb" "."; do - cat "$path/bindings.bb" 2>/dev/null && break -done | sed -e '/^#/d' -e "s/^[^ ]/$(printf '\034')+bind:\\0/" | tr '\034' '\0' >> "$BBCMD" +if [ ! -e "$XDG_CONFIG_HOME/bb/bindings.bb" ] && [ ! -e "$sysconfdir/xdg/bb/bindings.bb" ]; then + cat "./bindings.bb" 2>/dev/null | sed -e '/^#/d' -e "s/^[^ ]/$(printf '\034')+bind:\\0/" | tr '\034' '\0' >> "$BBCMD" +else + for path in "$sysconfdir/xdg/bb" "$XDG_CONFIG_HOME/bb"; do + cat "$path/bindings.bb" 2>/dev/null + done | sed -e '/^#/d' -e "s/^[^ ]/$(printf '\034')+bind:\\0/" | tr '\034' '\0' >> "$BBCMD" +fi printf '\0' >> "$BBCMD" diff --git a/bindings.bb b/bindings.bb index 9561b5d..792d5ca 100644 --- a/bindings.bb +++ b/bindings.bb @@ -20,7 +20,7 @@ k,Up: # Previous file h,Left: # Parent directory bb +cd:.. l,Right: # Enter directory - [ -d "$BBCURSOR" ] && bb +cd:"$BBCURSOR" + if [ -d "$BBCURSOR" ]; then bb +cd:"$BBCURSOR"; fi Ctrl-f: # Search for file file="$( if [ $BBDOTFILES ]; then @@ -39,7 +39,7 @@ m: # Mark this directory mark="$(basename -az ~/.config/bb/marks/* | pick "Jump to: ")" && bb +cd:"$(readlink -f ~/.config/bb/marks/"$mark")" -,Backspace: # Go to previous directory - [ $BBPREVPATH ] && bb +cd:"$BBPREVPATH" + [ "$BBPREVPATH" ] && bb +cd:"$BBPREVPATH" ;: # Show selected files bb +cd:'<selection>' 0: # Go to intitial directory @@ -109,17 +109,17 @@ d,Delete: # Delete a file printf "\033[1mDeleting \033[33m$BBCURSOR\033[0;1m...\033[0m " && confirm && rm -rf "$BBCURSOR" && bb +deselect:"$BBCURSOR" +refresh D: # Delete all selected files - [ $# -gt 0 ] && printf "\033[1mDeleting the following:\n\033[33m$(printf ' %s\n' "$@")\033[0m" | more && + [ $# -gt 0 ] && printf "\033[1mDeleting the following:\n\033[33m$(printf ' %s\n' "$@")\033[0m" | butt | more && confirm && rm -rf "$@" && bb +deselect +refresh Ctrl-v: # Move files here - printf "\033[1mMoving the following to here:\n\033[33m$(printf ' %s\n' "$@")\033[0m" | more && + printf "\033[1mMoving the following to here:\n\033[33m$(printf ' %s\n' "$@")\033[0m" | butt | more && confirm && printf "\033[1G\033[KMoving..." && mv -i "$@" . && printf "done." && bb +deselect +refresh && for f; do bb +sel:"$(basename "$f")"; done c: # Copy a file printf "\033[1mCreating copy of \033[33m$BBCURSOR\033[0;1m...\033[0m " && confirm && cp -ri "$BBCURSOR" "$BBCURSOR.copy" && bb +refresh C: # Copy all selected files here - [ $# -gt 0 ] && printf "\033[1mCopying the following to here:\n\033[33m$(printf ' %s\n' "$@")\033[0m" | more && + [ $# -gt 0 ] && printf "\033[1mCopying the following to here:\n\033[33m$(printf ' %s\n' "$@")\033[0m" | butt | more && confirm && printf "\033[1G\033[KCopying..." && for f; do if [ "./$(basename "$f")" -ef "$f" ]; then cp -ri "$f" "$f.copy" || break; @@ -164,9 +164,9 @@ Ctrl-r: # Regex rename files command -v rename >/dev/null || { printf '\033[31;1mThe `rename` command is not installed. Please install it to use this key binding.\033[0m\n'; pause; exit; }; ask patt "Replace pattern: " && ask rep "Replacement: " && - printf "\033[1mRenaming:\n\033[33m$(if [ $# -gt 0 ]; then rename -nv "$patt" "$rep" "$@"; else rename -nv "$patt" "$rep" *; fi)\033[0m" | more && - confirm && - if [ $# -gt 0 ]; then rename -i "$patt" "$rep" "$@"; else rename -i "$patt" "$rep" *; fi; + printf "\033[1mRenaming:\n\033[33m$(if [ $# -gt 0 ]; then rename -nv "$patt" "$rep" "$@"; else rename -nv "$patt" "$rep" *; fi)\033[0m" | butt | more && + confirm || exit 1 + if [ $# -gt 0 ]; then rename -i "$patt" "$rep" "$@"; else rename -i "$patt" "$rep" *; fi bb +deselect +refresh Section: Shell Commands |
