(303 lines)
1 #!/bin/sh2 # This file defines the key bindings for bb. It works by a very hacky script on3 # the line below that prints out the rest of this file, converted into `bbcmd4 # bind:` commands. Thanks to the hackiness, the code below is also valid shell5 # code, so syntax highlighting should work normally.6 #7 # The format is: ## <key>(,<key>)*:[ ]+<description>(\n script)+8 #9 # May God have mercy on my soul for creating this abomination:10 awk 'NR<='$LINENO'{next} /^##/{sub(/: /, ":# "); sub(/^## /,"\0bind:")} /./{print}' "$0" | bbcmd; exit12 ## Section: BB Commands13 ## ?,F1: Show Help menu16 ## q,Q: Quit19 ## Ctrl-c: Send interrupt signal22 ## Ctrl-z: Suspend25 ## Ctrl-\: Quit and generate core dump28 ## +: Run a bb command32 ## Section: File Navigation33 ## j,Down: Next file36 ## k,Up: Previous file39 ## h,Left: Parent directory42 ## l,Right: Enter directory46 ## Ctrl-f: Search for file50 ## /: Pick a file54 ## *: Set the glob58 ## Ctrl-g: Go to directory62 ## m: Mark this directory68 ## ': Go to a marked directory70 mark="$(find "$XDG_CONFIG_HOME"/bb/marks/ -mindepth 1 -type l -printf '%P\0' | bbpick "Jump to: ")"74 ## [,Backspace: Go to previous directory77 ## ]: Go to next directory80 ## ;: Show selected files83 ## g,Home: Go to first file86 ## G,End: Go to last file89 ## PgDn: Page down92 ## PgUp: Page up95 ## Ctrl-d: Half page down98 ## Ctrl-u: Half page up101 ## Mouse wheel down: Scroll down104 ## Mouse wheel up: Scroll up108 ## Section: File Selection109 ## v,V,Space: Toggle selection at cursor112 ## Escape: Clear selection115 ## S: Select pattern119 ## U: Unselect pattern123 ## Comma: Save the current settings125 echo "bbcmd glob:'$BBGLOB' sort:'$BBSORT' columns:'$BBCOLUMNS' $BBINTERLEAVE" > "$XDG_DATA_HOME"/bb/settings.sh127 ## Ctrl-s: Save the selection135 bbpause137 ## Ctrl-o: Open a saved selection140 loadpath="$(find "$XDG_DATA_HOME"/bb/ -mindepth 1 -maxdepth 1 -name '*.sel' -printf '%P\0' | bbpick "Load selection: ")"141 find "$XDG_DATA_HOME/bb/$loadpath" -mindepth 1 -maxdepth 1 -printf '%l\0' | bbcmd deselect select:144 ## J: Spread selection down147 ## K: Spread selection up150 ## Shift-Home: Spread the selection to the top153 ## Shift-End: Spread the selection to the bottom156 ## Ctrl-a: Select all files here160 ## Section: File Actions161 ## Left click: Move cursor to file168 fi170 ## Enter,Double left click: Open file/directory175 else178 fi180 ## e: Edit file in $EDITOR183 ## Ctrl-v: Move files here184 printf "\033[1mMoving the following to here:\n\033[33m$(printf ' %s\n' "$@")\033[0m" | bbunscroll | more185 bbconfirm192 ## c: Copy a file194 printf "\033[1mCopying the following to here:\n\033[33m$(printf ' %s\n' "$@")\033[0m" | bbunscroll | more195 bbconfirm201 done205 ## Ctrl-n: New file/directory209 ;;212 ;;214 ;;215 esac218 ## Section: Shell Commands219 ## Colon: Run a command222 bbpause225 ## |: Pipe selected files to a command229 bbpause232 ## @: Pass selected files as args to a command236 bbpause239 ## $: Pass the cursor as an argument to a command242 bbpause245 ## >: Open a shell250 ## f: Resume suspended process254 ## Section: Viewing Options255 ## s: Sort by...256 new_sort="$(bbask -1 "Sort (n)ame (s)ize (m)odification (c)reation (a)ccess (r)andom (p)ermissions: ")"259 ## ---,#: Set columns260 columns="$(bbask "Set columns (*)selected (a)ccessed (c)reated (m)odified (n)ame (p)ermissions (r)andom (s)ize: ")"263 ## .: Toggle dotfile visibility266 else268 fi270 ## i: Toggle interleaving files and directories273 ## F5,Ctrl-l,Ctrl-r: Refresh view276 ## Ctrl-b: Bind a key to a script278 echo282 ## 1: Run action on files287 }290 intended="$(printf '%s\0' 'Cursor file' 'Selected files' 'Both' | bbpick 'Which do you mean? ')"298 else300 fi