aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2020-02-24 03:39:44 -0800
committerBruce Hill <bruce@bruce-hill.com>2020-02-24 03:39:44 -0800
commit88fd9c416be0f5fe1e5fd48ba7c27d4d1e25261c (patch)
treecfe311fb81c1d12e46b08de175a6296f0aed7a0d
parent304cbddf730b86dec2b3d7c414fd0b9a38c69d76 (diff)
Moved bbstartup into a script, renamed helper/ -> scripts/, and added
bbshutdown script. Also tweaked some of the precedence.
-rw-r--r--Makefile4
-rw-r--r--bb.12
-rw-r--r--bb.c70
-rw-r--r--bb.h15
-rw-r--r--bbcmd.12
-rwxr-xr-xscripts/bbask (renamed from helpers/bbask)0
-rwxr-xr-xscripts/bbcmd (renamed from helpers/bbcmd)0
-rwxr-xr-xscripts/bbconfirm (renamed from helpers/bbconfirm)0
-rwxr-xr-xscripts/bbpause (renamed from helpers/bbpause)0
-rwxr-xr-xscripts/bbpick (renamed from helpers/bbpick)0
-rwxr-xr-xscripts/bbshutdown3
-rwxr-xr-xscripts/bbstartup (renamed from bbstartup.sh)5
-rwxr-xr-xscripts/bbtargets (renamed from helpers/bbtargets)0
-rwxr-xr-xscripts/bbunscroll (renamed from helpers/bbunscroll)0
14 files changed, 52 insertions, 49 deletions
diff --git a/Makefile b/Makefile
index 93f5cfb..7eb39b5 100644
--- a/Makefile
+++ b/Makefile
@@ -24,8 +24,8 @@ install: $(NAME)
fi; \
[ ! "$$prefix" ] && prefix="/usr/local"; \
[ ! "$$sysconfdir" ] && sysconfdir=/etc; \
- mkdir -pv -m 755 "$$prefix/share/man/man1" "$$prefix/bin" "$$sysconfdir/xdg/bb" "$$sysconfdir/xdg/bb/helpers" \
- && cp -rv bbstartup.sh bindings.bb helpers "$$sysconfdir/xdg/bb/" \
+ mkdir -pv -m 755 "$$prefix/share/man/man1" "$$prefix/bin" "$$sysconfdir/xdg/bb" \
+ && cp -rv bindings.bb scripts/* "$$sysconfdir/xdg/bb/" \
&& cp -v bb.1 bbcmd.1 "$$prefix/share/man/man1/" \
&& rm -f "$$prefix/bin/$(NAME)" \
&& cp -v $(NAME) "$$prefix/bin/"
diff --git a/bb.1 b/bb.1
index c474fba..3aca4a0 100644
--- a/bb.1
+++ b/bb.1
@@ -1,6 +1,6 @@
.\" Manpage for bb.
.\" Contact bruce@bruce-hill.com to correct errors or typos.
-.TH man 1 "23 Feb 2020" "0.25" "bb manual page"
+.TH man 1 "23 Feb 2020" "0.26" "bb manual page"
.SH NAME
bb \- A bitty browser for command line file management
.SH SYNOPSIS
diff --git a/bb.c b/bb.c
index adbc8f5..7320f04 100644
--- a/bb.c
+++ b/bb.c
@@ -23,13 +23,13 @@ void bb_browse(bb_t *bb, const char *initial_path)
{
if (populate_files(bb, initial_path))
err("Could not find initial path: \"%s\"", initial_path);
- run_script(bb, runstartup);
+ run_script(bb, "bbstartup");
check_cmdfile(bb);
-
while (!bb->should_quit) {
render(bb);
handle_next_key_binding(bb);
}
+ run_script(bb, "bbshutdown");
}
/*
@@ -580,8 +580,7 @@ void run_bbcmd(bb_t *bb, const char *cmd)
if (populate_files(bb, value))
warn("Could not open directory: \"%s\"", value);
} else if (matches_cmd(cmd, "columns:")) { // +columns:
- strncpy(bb->columns, value, MAX_COLS);
- dirty = 1;
+ set_columns(bb, value);
} else if (matches_cmd(cmd, "deselect")) { // +deselect
while (bb->selected)
set_selected(bb, bb->selected, 0);
@@ -656,6 +655,7 @@ void run_bbcmd(bb_t *bb, const char *cmd)
if (unlink(filename) == -1) err("Couldn't delete temporary help file: '%s'", filename);
} else if (matches_cmd(cmd, "interleave:") || matches_cmd(cmd, "interleave")) { // +interleave
set_bool(bb->interleave_dirs);
+ set_interleave(bb, bb->interleave_dirs);
sort_files(bb);
} else if (matches_cmd(cmd, "move:")) { // +move:
int oldcur, isdelta, n;
@@ -936,6 +936,15 @@ int run_script(bb_t *bb, const char *cmd)
}
/*
+ * Set the columns displayed by bb.
+ */
+void set_columns(bb_t *bb, const char *cols)
+{
+ strncpy(bb->columns, cols, MAX_COLS);
+ setenv("BBCOLUMNS", bb->columns, 1);
+}
+
+/*
* Set bb's file cursor to the given index (and adjust the scroll as necessary)
*/
void set_cursor(bb_t *bb, int newcur)
@@ -965,6 +974,28 @@ void set_cursor(bb_t *bb, int newcur)
}
/*
+ * Set the glob pattern(s) used by bb. Patterns are ' ' delimited
+ */
+void set_globs(bb_t *bb, const char *globs)
+{
+ free(bb->globpats);
+ bb->globpats = memcheck(strdup(globs));
+ setenv("BBGLOB", bb->globpats, 1);
+}
+
+
+/*
+ * Set whether or not bb should interleave directories and files.
+ */
+void set_interleave(bb_t *bb, int interleave)
+{
+ bb->interleave_dirs = interleave;
+ if (interleave) setenv("BBINTERLEAVE", "interleave", 1);
+ else unsetenv("BBINTERLEAVE");
+ dirty = 1;
+}
+
+/*
* Set bb's scroll to the given index (and adjust the cursor as necessary)
*/
void set_scroll(bb_t *bb, int newscroll)
@@ -984,17 +1015,6 @@ void set_scroll(bb_t *bb, int newscroll)
if (bb->cursor < 0) bb->cursor = 0;
}
-
-/*
- * Set the glob pattern(s) used by bb. Patterns are ' ' delimited
- */
-void set_globs(bb_t *bb, const char *globs)
-{
- free(bb->globpats);
- bb->globpats = memcheck(strdup(globs));
- setenv("BBGLOB", bb->globpats, 1);
-}
-
/*
* Select or deselect a file.
*/
@@ -1034,6 +1054,7 @@ void set_sort(bb_t *bb, const char *sort)
size_t len = MIN(MAX_SORT, strlen(sort));
memmove(bb->sort + len, bb->sort, MAX_SORT+1 - len);
memmove(bb->sort, sortbuf, len);
+ setenv("BBSORT", bb->sort, 1);
}
/*
@@ -1204,12 +1225,12 @@ int main(int argc, char *argv[])
setenv("BBPATH", bbpath, 1);
}
if (getenv("BBPATH")) {
- if (asprintf(&newpath, "%s/helpers:%s/bb/helpers:%s",
- getenv("BBPATH"), getenv("XDG_CONFIG_HOME"), getenv("PATH")) < 0)
+ if (asprintf(&newpath, "%s/bb:%s/scripts:%s",
+ getenv("XDG_CONFIG_HOME"), getenv("BBPATH"), getenv("PATH")) < 0)
err("Could not allocate memory for PATH");
} else {
- if (asprintf(&newpath, "%s/xdg/bb/helpers:%s/bb/helpers:%s",
- getenv("sysconfdir"), getenv("XDG_CONFIG_HOME"), getenv("PATH")) < 0)
+ if (asprintf(&newpath, "%s/bb:%s/xdg/bb:%s",
+ getenv("XDG_CONFIG_HOME"), getenv("sysconfdir"), getenv("PATH")) < 0)
err("Could not allocate memory for PATH");
}
setenv("PATH", newpath, 1);
@@ -1285,17 +1306,6 @@ int main(int argc, char *argv[])
fflush(stdout);
}
- {
- char path[PATH_MAX + strlen("/bb/state.sh")];
- sprintf(path, "%s/bb/state.sh", xdg_data_home);
- FILE *f = fopen(path, "w");
- fprintf(f, "bbcmd glob:'%s'\n", bb.globpats);
- fprintf(f, "bbcmd sort:'%s'\n", bb.sort);
- fprintf(f, "bbcmd columns:'%s'\n", bb.columns);
- if (bb.interleave_dirs) fprintf(f, "bbcmd interleave\n");
- fclose(f);
- }
-
if (print_dir)
printf("%s\n", bb.path);
diff --git a/bb.h b/bb.h
index 479943f..3e1a270 100644
--- a/bb.h
+++ b/bb.h
@@ -26,7 +26,7 @@
#include "bterm.h"
// Macros:
-#define BB_VERSION "0.25.0"
+#define BB_VERSION "0.26.0"
#ifndef PATH_MAX
#define PATH_MAX 4096
@@ -203,8 +203,10 @@ static void run_bbcmd(bb_t *bb, const char *cmd);
static void render(bb_t *bb);
static void restore_term(const struct termios *term);
static int run_script(bb_t *bb, const char *cmd);
+static void set_columns(bb_t *bb, const char *cols);
static void set_cursor(bb_t *bb, int i);
static void set_globs(bb_t *bb, const char *globs);
+static void set_interleave(bb_t *bb, int interleave);
static void set_selected(bb_t *bb, entry_t *e, int selected);
static void set_scroll(bb_t *bb, int i);
static void set_sort(bb_t *bb, const char *sort);
@@ -243,15 +245,4 @@ static const struct termios default_termios = {
static const char *description_str = "bb - an itty bitty console TUI file browser\n";
static const char *usage_str = "Usage: bb (-h/--help | -v/--version | -s | -d | -0 | +command)* [[--] directory]\n";
-static const char *runstartup =
-"if [ \"$BBPATH\" ]; then\n"
-" . \"$BBPATH/bbstartup.sh\"\n"
-"else\n"
-" for path in \"$XDG_CONFIG_HOME/bb\" \"$sysconfdir/xdg/bb\"; do\n"
-" [ -e \"$path/bbstartup.sh\" ] || continue\n"
-" . \"$path/bbstartup.sh\"\n"
-" break\n"
-" done\n"
-"fi\n";
-
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1
diff --git a/bbcmd.1 b/bbcmd.1
index 06794de..ed7249b 100644
--- a/bbcmd.1
+++ b/bbcmd.1
@@ -1,6 +1,6 @@
.\" Manpage for bbcmd.
.\" Contact bruce@bruce-hill.com to correct errors or typos.
-.TH man 1 "23 Feb 2020" "0.25" "bbcmd manual page"
+.TH man 1 "23 Feb 2020" "0.26" "bbcmd manual page"
.de TPx
. TP 4n
diff --git a/helpers/bbask b/scripts/bbask
index ad446ec..ad446ec 100755
--- a/helpers/bbask
+++ b/scripts/bbask
diff --git a/helpers/bbcmd b/scripts/bbcmd
index fdc4e78..fdc4e78 100755
--- a/helpers/bbcmd
+++ b/scripts/bbcmd
diff --git a/helpers/bbconfirm b/scripts/bbconfirm
index cae1153..cae1153 100755
--- a/helpers/bbconfirm
+++ b/scripts/bbconfirm
diff --git a/helpers/bbpause b/scripts/bbpause
index 6604fbd..6604fbd 100755
--- a/helpers/bbpause
+++ b/scripts/bbpause
diff --git a/helpers/bbpick b/scripts/bbpick
index 3316484..3316484 100755
--- a/helpers/bbpick
+++ b/scripts/bbpick
diff --git a/scripts/bbshutdown b/scripts/bbshutdown
new file mode 100755
index 0000000..368fd2f
--- /dev/null
+++ b/scripts/bbshutdown
@@ -0,0 +1,3 @@
+#!/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/bbstartup.sh b/scripts/bbstartup
index a64394e..40de50b 100755
--- a/bbstartup.sh
+++ b/scripts/bbstartup
@@ -1,6 +1,5 @@
#!/bin/sh
# This file contains the script that is run when bb launches
-# See API.md for details on bb's command API.
[ ! -d "$XDG_DATA_HOME/bb" ] && mkdir -p "$XDG_DATA_HOME/bb"
@@ -11,6 +10,6 @@ else
cat "$sysconfdir/xdg/bb/bindings.bb" "$XDG_CONFIG_HOME/bb/bindings.bb"
fi 2>/dev/null | awk '/^#/ {next} /^[^ ]/ {printf "\0bind:"} {print $0} END {printf "\0"}' >> "$BBCMD"
-if [ -e "$XDG_DATA_HOME/bb/state.sh" ]; then
- . "$XDG_DATA_HOME/bb/state.sh"
+if [ -e "$XDG_DATA_HOME/bb/settings.sh" ]; then
+ . "$XDG_DATA_HOME/bb/settings.sh"
fi
diff --git a/helpers/bbtargets b/scripts/bbtargets
index 1862ca0..1862ca0 100755
--- a/helpers/bbtargets
+++ b/scripts/bbtargets
diff --git a/helpers/bbunscroll b/scripts/bbunscroll
index 15102c4..15102c4 100755
--- a/helpers/bbunscroll
+++ b/scripts/bbunscroll