diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2019-06-15 14:14:05 -0700 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2019-06-15 14:14:05 -0700 |
| commit | b91dbdd3d076752478ca68a2d7b8c36c2a5a3549 (patch) | |
| tree | deb2c478a73933a2e9f14c1d139003379dcf8caf | |
| parent | 45a08afbbd4e3bc6b8ab3dfa4735a182f559624f (diff) | |
Added $BBDOTFILES, and updated bindings to use it properly. Removed the
`+select:*` and `+deselect:*` in favor of just using shell commands for
those functions.
| -rw-r--r-- | bb.c | 36 | ||||
| -rw-r--r-- | config.def.h | 19 |
2 files changed, 24 insertions, 31 deletions
@@ -286,6 +286,7 @@ int run_script(bb_t *bb, const char *cmd) args[i] = NULL; setenv("BBSELECTED", bb->firstselected ? "1" : "", 1); + setenv("BBDOTFILES", bb->show_dotfiles ? "1" : "", 1); setenv("BBCURSOR", bb->nfiles ? bb->files[bb->cursor]->fullname : "", 1); execvp("sh", args); @@ -1025,24 +1026,19 @@ bb_result_t process_cmd(bb_t *bb, const char *cmd) case 'e': { // +deselect: if (!value && !bb->nfiles) return BB_INVALID; if (!value) value = bb->files[bb->cursor]->fullname; - if (strcmp(value, "*") == 0) { - clear_selection(bb); + entry_t *e = load_entry(bb, value); + if (e) { + deselect_entry(bb, e); return BB_OK; - } else { - entry_t *e = load_entry(bb, value); - if (e) { + } + // Filename may no longer exist: + for (e = bb->firstselected; e; e = e->selected.next) { + if (strcmp(e->fullname, value) == 0) { deselect_entry(bb, e); - return BB_OK; + break; } - // Filename may no longer exist: - for (e = bb->firstselected; e; e = e->selected.next) { - if (strcmp(e->fullname, value) == 0) { - deselect_entry(bb, e); - break; - } - } - return BB_OK; } + return BB_OK; } case 'o': { // +dotfiles: set_bool(bb->show_dotfiles); @@ -1153,16 +1149,8 @@ bb_result_t process_cmd(bb_t *bb, const char *cmd) case '\0': case 'e': // +select: if (!value && !bb->nfiles) return BB_INVALID; if (!value) value = bb->files[bb->cursor]->fullname; - if (strcmp(value, "*") == 0) { - for (int i = 0; i < bb->nfiles; i++) { - if (strcmp(bb->files[i]->name, ".") - && strcmp(bb->files[i]->name, "..")) - select_entry(bb, bb->files[i]); - } - } else { - entry_t *e = load_entry(bb, value); - if (e) select_entry(bb, e); - } + entry_t *e = load_entry(bb, value); + if (e) select_entry(bb, e); return BB_OK; case 'o': // +sort: diff --git a/config.def.h b/config.def.h index a388410..09b23fe 100644 --- a/config.def.h +++ b/config.def.h @@ -17,6 +17,7 @@ no files are selected, the full path of the file under the cursor $BBCURSOR: the full path of the file under the cursor $BBSELECTED: "1" if any files are selected, otherwise "" + $BBDOTFILES: "1" if files beginning with "." are visible in bb, otherwise "" $BB_DEPTH: 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) @@ -28,7 +29,7 @@ ..:[01] Whether to show ".." in each directory cd:<path> Navigate to <path> columns:<columns> Change which columns are visible, and in what order - deselect:<filename>|* Deselect <filename> or all ("*") + deselect:<filename> Deselect <filename> dotfiles:[01] Whether dotfiles are visible goto:<filename> Move the cursor to <filename> (changing directory if needed) interleave:[01] Whether or not directories should be interleaved with files in the display @@ -38,8 +39,8 @@ quit Quit bb refresh Refresh the file listing scroll:<num*> Scroll the view a numeric amount - select:<filename>|* Select <filename> or all visible files in current directory ("*") - sort:([+-]method)+ List of sortings (if equal on one, move to the next) + select:<filename> Select <filename> + sort:([+-]method)+ Set sorting method (+: normal, -: reverse), additional methods act as tiebreaker spread:<num*> Spread the selection state at the cursor toggle:<filename> Toggle the selection status of <filename> @@ -186,10 +187,12 @@ binding_t bindings[] = { #endif B("Open")" file/directory"}, {{' ','v','V'}, "+toggle", B("Toggle")" selection"}, - {{KEY_ESC}, "+deselect:*", B("Clear")" selection"}, + {{KEY_ESC}, "bb +deselect: \"$@\"", B("Clear")" selection"}, {{'e'}, "$EDITOR \"$@\" || "PAUSE, B("Edit")" file in $EDITOR"}, - {{KEY_CTRL_F}, "bb \"+goto:$(find | "PICK("Find: ", "")")\"", B("Search")" for file"}, - {{'/'}, "bb \"+goto:$(ls -A | "PICK("Pick: ", "")")\"", B("Pick")" file"}, + {{KEY_CTRL_F}, "bb \"+goto:$(if test $BBDOTFILES; then find -mindepth 1; else find -mindepth 1 ! -path '*/.*'; fi " + "| "PICK("Find: ", "")")\"", B("Search")" for file"}, + {{'/'}, "bb \"+goto:$(if test $BBDOTFILES; then find -mindepth 1 -maxdepth 1; else find -mindepth 1 -maxdepth 1 ! -path '*/.*'; fi " + "| "PICK("Pick: ", "")")\"", B("Pick")" file"}, {{'d', KEY_DELETE}, "rm -rfi \"$@\" && bb '+deselect:*' +r ||" PAUSE, B("Delete")" files"}, {{'D'}, SPIN("rm -rf \"$@\"")" && bb '+deselect:*' +r ||" PAUSE, B("Delete")" files (without confirmation)"}, {{'M'}, SPIN("mv -i \"$@\" . && bb '+deselect:*' +r && for f; do bb \"+sel:$(basename \"$f\")\"; done")" || "PAUSE, @@ -243,7 +246,9 @@ binding_t bindings[] = { {{'g', KEY_HOME}, "+move:0", "Go to "B("first")" file"}, {{'G', KEY_END}, "+move:100%n", "Go to "B("last")" file"}, {{KEY_F5, KEY_CTRL_R}, "+refresh", B("Refresh")}, - {{KEY_CTRL_A}, "+select:*", B("Select all")" files in current directory"}, + {{KEY_CTRL_A}, "if test $BBDOTFILES; then find -mindepth 1 -maxdepth 1 -print0; else find -mindepth 1 -maxdepth 1 ! -path '*/.*' -print0; fi " + "| xargs -0 bb +sel:", + B("Select all")" files in current directory"}, {{KEY_PGDN}, "+scroll:+100%", B("Page down")}, {{KEY_PGUP}, "+scroll:-100%", B("Page up")}, {{KEY_CTRL_D}, "+scroll:+50%", B("Half page down")}, |
