aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bb.c17
-rw-r--r--bterm.h2
-rwxr-xr-xscripts/bbbindkeys10
-rwxr-xr-xscripts/bbpick10
-rwxr-xr-xscripts/bbshutdown1
-rwxr-xr-xscripts/bbstartup11
-rwxr-xr-xscripts/bbtargets2
7 files changed, 33 insertions, 20 deletions
diff --git a/bb.c b/bb.c
index 8f27d6c..78c864e 100644
--- a/bb.c
+++ b/bb.c
@@ -460,12 +460,15 @@ int populate_files(bb_t *bb, const char *path)
glob(pat, GLOB_NOSORT|GLOB_APPEND, NULL, &globbuf);
free(tmpglob);
for (size_t i = 0; i < globbuf.gl_pathc; i++) {
- if ((size_t)bb->nfiles + 1 > space)
- bb->files = memcheck(realloc(bb->files, (space += 100)*sizeof(void*)));
// Don't normalize path so we can get "." and ".."
entry_t *entry = load_entry(bb, globbuf.gl_pathv[i]);
- if (!entry) err("Failed to load entry: '%s'", globbuf.gl_pathv[i]);
+ if (!entry) {
+ warn("Failed to load entry: '%s'", globbuf.gl_pathv[i]);
+ continue;
+ }
entry->index = bb->nfiles;
+ if ((size_t)bb->nfiles + 1 > space)
+ bb->files = memcheck(realloc(bb->files, (space += 100)*sizeof(void*)));
bb->files[bb->nfiles++] = entry;
}
globfree(&globbuf);
@@ -646,7 +649,13 @@ void run_bbcmd(bb_t *bb, const char *cmd)
char *lastslash = strrchr(pbuf, '/');
if (!lastslash) err("No slash found in filename: %s", pbuf);
*lastslash = '\0'; // Split in two
+ try_free_entry(e);
+ // Move to dir and reselect
populate_files(bb, pbuf);
+ e = load_entry(bb, lastslash+1);
+ if (!e) {
+ warn("Could not find file again: \"%s\"", lastslash+1);
+ }
if (IS_VIEWED(e))
set_cursor(bb, e->index);
else try_free_entry(e);
@@ -833,7 +842,7 @@ void render(bb_t *bb)
}
fputs("\033[0m", tty_out);
}
- move_cursor(tty_out, 0, MIN(bb->nfiles - bb->scroll + 2, ONSCREEN) + 2);
+ move_cursor(tty_out, 0, MIN(bb->nfiles - bb->scroll, ONSCREEN) + 2);
fputs("\033[J", tty_out);
}
diff --git a/bterm.h b/bterm.h
index 9ab9b2f..06e6d42 100644
--- a/bterm.h
+++ b/bterm.h
@@ -119,7 +119,7 @@ static keyname_t key_names[] = {
{KEY_CTRL_2, "Ctrl-2"}, {KEY_CTRL_3, "Ctrl-3"}, {KEY_CTRL_4, "Ctrl-4"},
{KEY_CTRL_5, "Ctrl-5"}, {KEY_CTRL_6, "Ctrl-6"}, {KEY_CTRL_7, "Ctrl-7"},
{KEY_CTRL_5, "Ctrl-8"}, {KEY_CTRL_6, "Ctrl-9"},
- {':', "Colon"},
+ {':', "Colon"}, {',', "Comma"},
};
int bgetkey(FILE *in, int *mouse_x, int *mouse_y);
diff --git a/scripts/bbbindkeys b/scripts/bbbindkeys
index 8ffadc0..b89bb16 100755
--- a/scripts/bbbindkeys
+++ b/scripts/bbbindkeys
@@ -39,7 +39,7 @@ bbcmd cd:..
if [ -d "$BBCURSOR" ]; then bbcmd cd:"$BBCURSOR"; fi
## Ctrl-f: Search for file
-file="$(find $BBGLOB -mindepth 1 -printf '%P\0' | bbpick "Find: ")"
+file="$(find . -mindepth 1 -printf '%P\0' | bbpick "Find: ")"
bbcmd goto:"$file"
## /: Pick a file
@@ -115,6 +115,10 @@ bbcmd select: $patt
patt="$(bbask "Unselect: ")"
bbcmd deselect: $patt
+## Comma: Save the current settings
+bbconfirm "Save the current settings? "
+echo "bbcmd glob:'$BBGLOB' sort:'$BBSORT' columns:'$BBCOLUMNS' $BBINTERLEAVE" > "$XDG_DATA_HOME"/bb/settings.sh
+
## Ctrl-s: Save the selection
[ $# -gt 0 ]
savename="$(bbask "Save selection as: ")"
@@ -187,10 +191,6 @@ bbcmd deselect refresh
for f; do bbcmd sel:"$(basename "$f")"; done
## c: Copy a file
-case "$(bbtargets "$BBCURSOR" "$@")" in
- cursor) set -- "$BBCURSOR";;
- both) set -- "$BBCURSOR" "$@";;
-esac
[ $# -gt 0 ]
printf "\033[1mCopying the following to here:\n\033[33m$(printf ' %s\n' "$@")\033[0m" | bbunscroll | more
bbconfirm
diff --git a/scripts/bbpick b/scripts/bbpick
index 3316484..8cad371 100755
--- a/scripts/bbpick
+++ b/scripts/bbpick
@@ -15,21 +15,21 @@ if [ -z "$PICKER" ]; then
fi
case "$PICKER" in
- fzf)
+ fzf*)
printf '\033[3A\033[?25h' >/dev/tty
fzf --read0 --height=4 --prompt="$(printf "$1")"
;;
- fzy)
+ fzy*)
printf '\033[3A\033[?25h' >/dev/tty
tr '\0' '\n' | fzy --lines=3 --prompt="$(printf "\033[1m$1\033[0m")"
;;
- ask)
+ ask*)
ask --read0 --prompt="$(printf "$1\033[?25h")"
;;
- dmenu)
+ dmenu*)
tr '\0' '\n' | dmenu -i -l 10 -p "$(printf "$1")"
;;
- pick)
+ pick*)
printf '\033[?25h' >/dev/tty
tr '\0' '\n' | pick
;;
diff --git a/scripts/bbshutdown b/scripts/bbshutdown
index 368fd2f..987c376 100755
--- a/scripts/bbshutdown
+++ b/scripts/bbshutdown
@@ -1,3 +1,2 @@
#!/bin/sh
# This file gets run when `bb` shuts down.
-echo "bbcmd glob:'$BBGLOB' sort:'$BBSORT' columns:'$BBCOLUMNS' $BBINTERLEAVE" > "$XDG_DATA_HOME"/bb/settings.sh
diff --git a/scripts/bbstartup b/scripts/bbstartup
index 21d04e3..93fbb43 100755
--- a/scripts/bbstartup
+++ b/scripts/bbstartup
@@ -1,11 +1,16 @@
#!/bin/sh
# This file contains the script that is run when bb launches
+# Delay running command-line commands (bb +<cmd>) until after startup:
+tmpfile="$(mktemp "${TMPDIR-/tmp}/bb-cmdline-XXXXXX")"
+trap 'cat "$tmpfile" >> "$BBCMD"; rm -f "$tmpfile"' EXIT
+mv "$BBCMD" "$tmpfile"
+
+# Create bb data dir:
[ ! -d "$XDG_DATA_HOME/bb" ] && mkdir -p "$XDG_DATA_HOME/bb"
# Load key bindings
bbbindkeys
-if [ -e "$XDG_DATA_HOME/bb/settings.sh" ]; then
- . "$XDG_DATA_HOME/bb/settings.sh"
-fi
+# Reload settings
+[ -e "$XDG_DATA_HOME/bb/settings.sh" ] && . "$XDG_DATA_HOME/bb/settings.sh"
diff --git a/scripts/bbtargets b/scripts/bbtargets
index 1862ca0..dff50c9 100755
--- a/scripts/bbtargets
+++ b/scripts/bbtargets
@@ -16,7 +16,7 @@ else
intended='Cursor file'
fi
-[ -z "$intended" ] && intended="$(printf '%s\0' 'Cursor file' 'Selected files' 'Both' | bbpick 'Which do you want to delete? ')"
+[ -z "$intended" ] && intended="$(printf '%s\0' 'Cursor file' 'Selected files' 'Both' | bbpick 'Which do you mean? ')"
case "$intended" in
Cursor*) echo cursor ;;