Moved bbstartup into a script, renamed helper/ -> scripts/, and added
bbshutdown script. Also tweaked some of the precedence.
This commit is contained in:
parent
304cbddf73
commit
88fd9c416b
4
Makefile
4
Makefile
@ -24,8 +24,8 @@ install: $(NAME)
|
|||||||
fi; \
|
fi; \
|
||||||
[ ! "$$prefix" ] && prefix="/usr/local"; \
|
[ ! "$$prefix" ] && prefix="/usr/local"; \
|
||||||
[ ! "$$sysconfdir" ] && sysconfdir=/etc; \
|
[ ! "$$sysconfdir" ] && sysconfdir=/etc; \
|
||||||
mkdir -pv -m 755 "$$prefix/share/man/man1" "$$prefix/bin" "$$sysconfdir/xdg/bb" "$$sysconfdir/xdg/bb/helpers" \
|
mkdir -pv -m 755 "$$prefix/share/man/man1" "$$prefix/bin" "$$sysconfdir/xdg/bb" \
|
||||||
&& cp -rv bbstartup.sh bindings.bb helpers "$$sysconfdir/xdg/bb/" \
|
&& cp -rv bindings.bb scripts/* "$$sysconfdir/xdg/bb/" \
|
||||||
&& cp -v bb.1 bbcmd.1 "$$prefix/share/man/man1/" \
|
&& cp -v bb.1 bbcmd.1 "$$prefix/share/man/man1/" \
|
||||||
&& rm -f "$$prefix/bin/$(NAME)" \
|
&& rm -f "$$prefix/bin/$(NAME)" \
|
||||||
&& cp -v $(NAME) "$$prefix/bin/"
|
&& cp -v $(NAME) "$$prefix/bin/"
|
||||||
|
2
bb.1
2
bb.1
@ -1,6 +1,6 @@
|
|||||||
.\" Manpage for bb.
|
.\" Manpage for bb.
|
||||||
.\" Contact bruce@bruce-hill.com to correct errors or typos.
|
.\" 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
|
.SH NAME
|
||||||
bb \- A bitty browser for command line file management
|
bb \- A bitty browser for command line file management
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
|
70
bb.c
70
bb.c
@ -23,13 +23,13 @@ void bb_browse(bb_t *bb, const char *initial_path)
|
|||||||
{
|
{
|
||||||
if (populate_files(bb, initial_path))
|
if (populate_files(bb, initial_path))
|
||||||
err("Could not find initial path: \"%s\"", initial_path);
|
err("Could not find initial path: \"%s\"", initial_path);
|
||||||
run_script(bb, runstartup);
|
run_script(bb, "bbstartup");
|
||||||
check_cmdfile(bb);
|
check_cmdfile(bb);
|
||||||
|
|
||||||
while (!bb->should_quit) {
|
while (!bb->should_quit) {
|
||||||
render(bb);
|
render(bb);
|
||||||
handle_next_key_binding(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))
|
if (populate_files(bb, value))
|
||||||
warn("Could not open directory: \"%s\"", value);
|
warn("Could not open directory: \"%s\"", value);
|
||||||
} else if (matches_cmd(cmd, "columns:")) { // +columns:
|
} else if (matches_cmd(cmd, "columns:")) { // +columns:
|
||||||
strncpy(bb->columns, value, MAX_COLS);
|
set_columns(bb, value);
|
||||||
dirty = 1;
|
|
||||||
} else if (matches_cmd(cmd, "deselect")) { // +deselect
|
} else if (matches_cmd(cmd, "deselect")) { // +deselect
|
||||||
while (bb->selected)
|
while (bb->selected)
|
||||||
set_selected(bb, bb->selected, 0);
|
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);
|
if (unlink(filename) == -1) err("Couldn't delete temporary help file: '%s'", filename);
|
||||||
} else if (matches_cmd(cmd, "interleave:") || matches_cmd(cmd, "interleave")) { // +interleave
|
} else if (matches_cmd(cmd, "interleave:") || matches_cmd(cmd, "interleave")) { // +interleave
|
||||||
set_bool(bb->interleave_dirs);
|
set_bool(bb->interleave_dirs);
|
||||||
|
set_interleave(bb, bb->interleave_dirs);
|
||||||
sort_files(bb);
|
sort_files(bb);
|
||||||
} else if (matches_cmd(cmd, "move:")) { // +move:
|
} else if (matches_cmd(cmd, "move:")) { // +move:
|
||||||
int oldcur, isdelta, n;
|
int oldcur, isdelta, n;
|
||||||
@ -935,6 +935,15 @@ int run_script(bb_t *bb, const char *cmd)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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)
|
* Set bb's file cursor to the given index (and adjust the scroll as necessary)
|
||||||
*/
|
*/
|
||||||
@ -964,6 +973,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)
|
* Set bb's scroll to the given index (and adjust the cursor as necessary)
|
||||||
*/
|
*/
|
||||||
@ -984,17 +1015,6 @@ void set_scroll(bb_t *bb, int newscroll)
|
|||||||
if (bb->cursor < 0) bb->cursor = 0;
|
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.
|
* 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));
|
size_t len = MIN(MAX_SORT, strlen(sort));
|
||||||
memmove(bb->sort + len, bb->sort, MAX_SORT+1 - len);
|
memmove(bb->sort + len, bb->sort, MAX_SORT+1 - len);
|
||||||
memmove(bb->sort, sortbuf, 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);
|
setenv("BBPATH", bbpath, 1);
|
||||||
}
|
}
|
||||||
if (getenv("BBPATH")) {
|
if (getenv("BBPATH")) {
|
||||||
if (asprintf(&newpath, "%s/helpers:%s/bb/helpers:%s",
|
if (asprintf(&newpath, "%s/bb:%s/scripts:%s",
|
||||||
getenv("BBPATH"), getenv("XDG_CONFIG_HOME"), getenv("PATH")) < 0)
|
getenv("XDG_CONFIG_HOME"), getenv("BBPATH"), getenv("PATH")) < 0)
|
||||||
err("Could not allocate memory for PATH");
|
err("Could not allocate memory for PATH");
|
||||||
} else {
|
} else {
|
||||||
if (asprintf(&newpath, "%s/xdg/bb/helpers:%s/bb/helpers:%s",
|
if (asprintf(&newpath, "%s/bb:%s/xdg/bb:%s",
|
||||||
getenv("sysconfdir"), getenv("XDG_CONFIG_HOME"), getenv("PATH")) < 0)
|
getenv("XDG_CONFIG_HOME"), getenv("sysconfdir"), getenv("PATH")) < 0)
|
||||||
err("Could not allocate memory for PATH");
|
err("Could not allocate memory for PATH");
|
||||||
}
|
}
|
||||||
setenv("PATH", newpath, 1);
|
setenv("PATH", newpath, 1);
|
||||||
@ -1285,17 +1306,6 @@ int main(int argc, char *argv[])
|
|||||||
fflush(stdout);
|
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)
|
if (print_dir)
|
||||||
printf("%s\n", bb.path);
|
printf("%s\n", bb.path);
|
||||||
|
|
||||||
|
15
bb.h
15
bb.h
@ -26,7 +26,7 @@
|
|||||||
#include "bterm.h"
|
#include "bterm.h"
|
||||||
|
|
||||||
// Macros:
|
// Macros:
|
||||||
#define BB_VERSION "0.25.0"
|
#define BB_VERSION "0.26.0"
|
||||||
|
|
||||||
#ifndef PATH_MAX
|
#ifndef PATH_MAX
|
||||||
#define PATH_MAX 4096
|
#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 render(bb_t *bb);
|
||||||
static void restore_term(const struct termios *term);
|
static void restore_term(const struct termios *term);
|
||||||
static int run_script(bb_t *bb, const char *cmd);
|
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_cursor(bb_t *bb, int i);
|
||||||
static void set_globs(bb_t *bb, const char *globs);
|
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_selected(bb_t *bb, entry_t *e, int selected);
|
||||||
static void set_scroll(bb_t *bb, int i);
|
static void set_scroll(bb_t *bb, int i);
|
||||||
static void set_sort(bb_t *bb, const char *sort);
|
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 *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 *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
|
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1
|
||||||
|
2
bbcmd.1
2
bbcmd.1
@ -1,6 +1,6 @@
|
|||||||
.\" Manpage for bbcmd.
|
.\" Manpage for bbcmd.
|
||||||
.\" Contact bruce@bruce-hill.com to correct errors or typos.
|
.\" 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
|
.de TPx
|
||||||
. TP 4n
|
. TP 4n
|
||||||
|
3
scripts/bbshutdown
Executable file
3
scripts/bbshutdown
Executable file
@ -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
|
@ -1,6 +1,5 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# This file contains the script that is run when bb launches
|
# 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"
|
[ ! -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"
|
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"
|
fi 2>/dev/null | awk '/^#/ {next} /^[^ ]/ {printf "\0bind:"} {print $0} END {printf "\0"}' >> "$BBCMD"
|
||||||
|
|
||||||
if [ -e "$XDG_DATA_HOME/bb/state.sh" ]; then
|
if [ -e "$XDG_DATA_HOME/bb/settings.sh" ]; then
|
||||||
. "$XDG_DATA_HOME/bb/state.sh"
|
. "$XDG_DATA_HOME/bb/settings.sh"
|
||||||
fi
|
fi
|
Loading…
Reference in New Issue
Block a user