aboutsummaryrefslogtreecommitdiff
path: root/bindings.bb
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-09-30 15:46:24 -0700
committerBruce Hill <bruce@bruce-hill.com>2019-09-30 15:46:24 -0700
commit7a666d519556e9c7bf510d71565793978e7beba0 (patch)
treede0fdab0d45729219e7ba40c0c325df050bd2e83 /bindings.bb
parente341f51dc62af41494a8618ad8e8c31632e93053 (diff)
Overhaul of how binding commands works. It's now all handled through
bbstartup.sh, which loads bindings.bb and parses it to +bind:<keys>:<script> commands.
Diffstat (limited to 'bindings.bb')
-rw-r--r--bindings.bb165
1 files changed, 165 insertions, 0 deletions
diff --git a/bindings.bb b/bindings.bb
new file mode 100644
index 0000000..0ef25f8
--- /dev/null
+++ b/bindings.bb
@@ -0,0 +1,165 @@
+# This file defines the key bindings for bb
+# The format is: <key>(,<key>)*:[ ]*#<description>(\n[ ]+script)+
+Section: BB Commands
+?,F1: # Show Help menu
+ bb +help
+q,Q: # Quit
+ bb +quit
+
+Section: File Navigation
+j,Down: # Next file
+ bb +move:+1
+k,Up: # Previous file
+ bb +move:-1
+h,Left: # Parent directory
+ bb +cd:..
+l,Right: # Enter directory
+ [ -d "$BBCURSOR" ] && bb +cd:"$BBCURSOR"
+Ctrl-f: # Search for file
+ bb +goto:"$(
+ if [ $BBDOTFILES ]; then
+ find -mindepth 1;
+ else find -mindepth 1 ! -path '*/.*';
+ fi | pick "Find: "
+ )"
+/: # Pick a file
+ bb +goto:"$(
+ if [ $BBDOTFILES ]; then find -mindepth 1 -maxdepth 1;
+ else find -mindepth 1 -maxdepth 1 ! -path '*/.*'; fi | pick "Pick: "
+ )"
+Ctrl-g: # Go to directory
+ ask goto "Go to directory: " && bb +cd:"$goto"
+m: # Mark this directory
+ ask mark "Mark: " && ln -s "$PWD" ~/.config/bb/marks/"$mark"
+': # Go to a marked directory
+ mark="$(ls ~/.config/bb/marks | pick "Jump to: ")" &&
+ bb +cd:"$(readlink -f ~/.config/bb/marks/"$mark")"
+-,Backspace: # Go to previous directory
+ [ $BBPREVPATH ] && bb +cd:"$BBPREVPATH"
+;: # Show selected files
+ bb +cd:'<selection>'
+0: # Go to intitial directory
+ bb +cd:"$BBINITIALPATH"
+g,Home: # Go to first file
+ bb +move:0
+G,End: # Go to last file
+ bb +move:100%n
+PgDn: # Page down
+ bb +scroll:+100%
+PgUp: # Page up
+ bb +scroll:-100%
+Ctrl-d: # Half page down
+ bb +scroll:+50%
+Ctrl-u: # Half page up
+ bb +scroll:-50%
+Mouse wheel down: # Scroll down
+ bb +scroll:+3
+Mouse wheel up: # Scroll up
+ bb +scroll:-3
+
+Section: File Selection
+v,V,Space: # Toggle selection at cursor
+ bb +toggle
+Escape: # Clear selection
+ bb +deselect: "$@"
+Ctrl-s: # Save the selection
+ [ $# -gt 0 ] && ask savename "Save selection as: " && printf '%s\0' "$@" > ~/.config/bb/"$savename"
+Ctrl-o: # Open a saved selection
+ loadpath="$(find ~/.config/bb -maxdepth 1 -type f | pick "Load selection: ")" &&
+ [ -e "$loadpath" ] && bb +deselect: "$@" &&
+ while IFS= read -r -d $'\0'; do bb +select:"$REPLY"; done < "$loadpath"
+J: # Spread selection down
+ bb +spread:+1
+K: # Spread selection up
+ bb +spread:-1
+Ctrl-a: # Select all files here
+ if [ $BBDOTFILES ]; then find -mindepth 1 -maxdepth 1 -print0;
+ else find -mindepth 1 -maxdepth 1 ! -path '*/.*' -print0; fi | bb +sel:
+
+Section: File Actions
+Enter: # Open file/directory
+ if [ -d "$BBCURSOR ]; then bb +cd:"$BBCURSOR";
+ elif file -bi "$BBCURSOR" | grep -q '^\(text/\|inode/empty\)'; then $EDITOR "$BBCURSOR";
+ else open "$BBCURSOR"; fi
+e: # Edit file in $EDITOR
+ $EDITOR "$BBCURSOR" || pause
+d: # Delete a file
+ printf "\033[1mDeleting \033[33m$BBCURSOR\033[0;1m...\033[0m " && confirm &&
+ rm -rf "$BBCURSOR" && bb +refresh && bb +deselect:"$BBCURSOR"
+D: # Delete all selected files
+ [ $# -gt 0 ] && printf "\033[1mDeleting the following:\n \033[33m$(printf ' %s\n' "$@")\033[0m" | more &&
+ confirm && rm -rf "$@" && bb +refresh && bb +deselect: "$@"
+Ctrl-v: # Move files here
+ printf "\033[1mMoving the following to here:\n \033[33m$(printf ' %s\n' "$@")\033[0m" | more &&
+ confirm && spin mv -i "$@" . && bb +refresh && bb +deselect "$@" &&
+ for f; do bb +sel:"$(basename "$f")"; done ||
+ pause
+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 &&
+ confirm &&
+ for f; do if [ "./$(basename "$f")" -ef "$f" ]; then
+ spin cp -ri "$f" "$f.copy";
+ else spin cp -ri "$f" .; fi; done; bb +refresh
+Ctrl-n: # New file/directory
+ case "$(printf '%s\n' File Directory | pick "Create new: ")" in
+ File)
+ ask name "New File: " || exit
+ touch "$name"
+ ;;
+ Directory)
+ ask name "New Directory: " || exit
+ mkdir "$name"
+ ;;
+ *) exit
+ ;;
+ esac && bb +goto:"$name" +refresh || pause
+p: # Page through a file with $PAGER
+ $PAGER "$BBCURSOR"
+|: # Pipe selected files to a command
+ ask cmd '|' && printf '%s\n' "$@" | sh -c "$BBSHELLFUNC$cmd"; bb +r; pause
+:: # Run a command
+ ask cmd ':' && sh -c "$BBSHELLFUNC$cmd" -- "$@"; bb +r; pause
+>: # Open a shell
+ tput rmcup >/dev/tty; $SHELL; bb +r
+r,F2: # Rename a file
+ ask newname "Rename \033[33m$(basename "$BBCURSOR")\033[39m: " "$(basename "$BBCURSOR")" || exit
+ r="$(dirname "$BBCURSOR")/$newname" || exit
+ [ "$r" != "$BBCURSOR" ] && mv -i "$BBCURSOR" "$r" && bb +refresh &&
+ while [ $# -gt 0 ]; do "$1" = "$BBCURSOR" && bb +deselect:"$BBCURSOR" +select:"$r"; shift; done &&
+ bb +goto:"$r"
+R: # Rename all selected files
+ bb +refresh;
+ for f; do
+ ask newname "Rename \033[33m$(basename "$f")\033[39m: " "$(basename "$f")" || break;
+ r="$(dirname "$f")/$newname";
+ [ "$r" != "$f" ] && mv -i "$f" "$r" && bb "+deselect:$f" "+select:$r";
+ [ "$f" = "$BBCURSOR" ] && bb +goto:"$r";
+ done
+Ctrl-r: # Regex rename files
+ command -v rename >/dev/null || { echo 'The `rename` command is not installed. Please install it to use this key binding.'; 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;
+ bb +deselect: "$@";
+ bb +refresh
+
+Section: Viewing Options
+s: # Sort by...
+ ask1 sort "Sort (n)ame (s)ize (m)odification (c)reation (a)ccess (r)andom (p)ermissions: " &&
+ bb +sort:"~$sort" +refresh
+#: # Set columns
+ ask columns "Set columns (*)selected (a)ccessed (c)reated (m)odified (n)ame (p)ermissions (r)andom (s)ize: " &&
+ bb +col:"$columns"
+.: # Toggle dotfile visibility
+ bb +dotfiles
+i: # Toggle interleaving files and directories
+ bb +interleave
+F5: # Refresh view
+ bb +refresh
+Ctrl-b: # Bind a key to a script
+ ask1 key "Press key to bind..." && echo && ask script "Bind script: " && bb +bind:"$(printf "$key:$script")"
+
+Section: User Bindings