From 88fd9c416be0f5fe1e5fd48ba7c27d4d1e25261c Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 24 Feb 2020 03:39:44 -0800 Subject: Moved bbstartup into a script, renamed helper/ -> scripts/, and added bbshutdown script. Also tweaked some of the precedence. --- bb.c | 70 +++++++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 40 insertions(+), 30 deletions(-) (limited to 'bb.c') 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; @@ -935,6 +935,15 @@ int run_script(bb_t *bb, const char *cmd) 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) */ @@ -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) */ @@ -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); -- cgit v1.2.3