From 69955d38082d5a5f47306daafeaf8c17171b0675 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 12 Jun 2019 15:11:29 -0700 Subject: [PATCH] Switched some stuff to use $() instead of `` for better composing, rearranged things a bit to launch bb fewer times for commands. --- Makefile | 7 ++++--- bb.c | 12 +++++++++++- config.def.h | 31 +++++++++++++++---------------- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index f4390c9..bd13618 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,10 @@ NAME=bb PREFIX= CC=gcc -CFLAGS=-O0 -std=gnu99 -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L -CWARN= -Wall -Wpedantic -Wno-unknown-pragmas -fsanitize=address -fno-omit-frame-pointer -G=-g +CFLAGS=-O2 -std=gnu99 -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L +CWARN= -Wall -Wpedantic -Wno-unknown-pragmas +#CWARN += -fsanitize=address -fno-omit-frame-pointer +G= ifeq ($(shell uname),Darwin) CFLAGS += -D_DARWIN_C_SOURCE diff --git a/bb.c b/bb.c index 647b3a2..89d9a4a 100644 --- a/bb.c +++ b/bb.c @@ -1387,6 +1387,8 @@ int main(int argc, char *argv[]) for (int i = 1; i < argc; i++) { if (argv[i][0] == '+') { ++cmd_args; + char *colon = strchr(argv[i], ':'); + if (colon && !colon[1]) break; continue; } if (strcmp(argv[i], "--") == 0) { @@ -1423,7 +1425,15 @@ int main(int argc, char *argv[]) int i; for (i = 1; i < argc; i++) { if (argv[i][0] == '+') { - write(cmdfd, argv[i]+1, strlen(argv[i]+1)+1); + char *colon = strchr(argv[i], ':'); + if (colon && !colon[1]) { + for (int j = i+1; j < argc; j++) { + write(cmdfd, argv[i]+1, strlen(argv[i]+1)); + write(cmdfd, argv[j], strlen(argv[j])+1); + } + } else { + write(cmdfd, argv[i]+1, strlen(argv[i]+1)+1); + } continue; } if (strcmp(argv[i], "--") == 0) break; diff --git a/config.def.h b/config.def.h index 3445120..ed06200 100644 --- a/config.def.h +++ b/config.def.h @@ -122,7 +122,7 @@ typedef struct { "sleep 0.01; "\ "while kill -0 $pid 2>/dev/null; do "\ " printf '%c\\033[D' \"$spinner\" >/dev/tty; "\ - " spinner=\"`echo $spinner | sed 's/\\(.\\)\\(.*\\)/\\2\\1/'`\"; "\ + " spinner=\"$(echo $spinner | sed 's/\\(.\\)\\(.*\\)/\\2\\1/')\"; "\ " sleep 0.1; "\ "done" #endif @@ -188,21 +188,21 @@ binding_t bindings[] = { {{' ','v','V'}, "+toggle", B("Toggle")" selection"}, {{KEY_ESC}, "+deselect:*", B("Clear")" selection"}, {{'e'}, "$EDITOR \"$@\" || "PAUSE, B("Edit")" file in $EDITOR"}, - {{KEY_CTRL_F}, "bb \"+g:`find | "PICK("Find: ", "")"`\"", B("Search")" for file"}, - {{'/'}, "bb \"+g:`ls -A | "PICK("Pick: ", "")"`\"", B("Pick")" file"}, + {{KEY_CTRL_F}, "bb \"+goto:$(find | "PICK("Find: ", "")")\"", B("Search")" for file"}, + {{'/'}, "bb \"+goto:$(ls -A | "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:`pwd`/`basename \"$f\"`\"; done || "PAUSE, + {{'M'}, SPIN("mv -i \"$@\" .")" && bb '+deselect:*' +r && for f; do printf \"$(pwd)/$(basename \"$f\")\\0\"; done | xargs -0 bb +sel: || "PAUSE, B("Move")" files to current directory"}, {{'c'}, SPIN("cp -ri \"$@\" .")" && bb +r || "PAUSE, B("Copy")" files to current directory"}, - {{'C'}, "bb '+de:*' && for f; do "SPIN("cp \"$f\" \"$f.copy\"")" && bb \"+sel:$f.copy\"; done && bb +r || "PAUSE, + {{'C'}, "for f; do "SPIN("cp \"$f\" \"$f.copy\"")"; done && bb +r || "PAUSE, B("Clone")" files"}, {{'n'}, ASK("name", "New file: ", "")" && touch \"$name\" && bb \"+goto:$name\" +r || "PAUSE, B("New file")}, {{'N'}, ASK("name", "New dir: ", "")" && mkdir \"$name\" && bb \"+goto:$name\" +r || "PAUSE, B("New directory")}, - {{KEY_CTRL_G}, "bb \"+cd:`" ASKECHO("Go to directory: ", "") "`\"", B("Go to")" directory"}, + {{KEY_CTRL_G}, "bb \"+cd:$(" ASKECHO("Go to directory: ", "") ")\"", B("Go to")" directory"}, {{'|'}, ASK("cmd", "|", "") " && printf '%s\\n' \"$@\" | sh -c \"$cmd\"; " PAUSE "; bb +r", B("Pipe")" selected files to a command"}, - {{':'}, "sh -c \"`" ASKECHO(":", "") "`\" -- \"$@\"; " PAUSE "; bb +refresh", + {{':'}, "sh -c \"$(" ASKECHO(":", "") ")\" -- \"$@\"; " PAUSE "; bb +refresh", B("Run")" a command"}, {{'>'}, "tput rmcup >/dev/tty; $SHELL; bb +r", "Open a "B("shell")}, {{'m'}, "read -n1 -p 'Mark: ' m && bb \"+mark:$m;$PWD\"", "Set "B("mark")}, @@ -222,24 +222,23 @@ binding_t bindings[] = { "if sed -E \"$patt\" /dev/null && bb \"+sel:$f\"; done", + ASK("patt", "Select pattern: ", "")" && ls -A | grep \"$patt\" | xargs bb +sel:", B("Regex select")" files"}, {{'J'}, "+spread:+1", B("Spread")" selection down"}, {{'K'}, "+spread:-1", B("Spread")" selection up"}, - {{'b'}, "bb \"+`"ASKECHO("bb +", "")"`\"", "Run a "B("bb command")}, + {{'b'}, "bb \"+$("ASKECHO("bb +", "")")\"", "Run a "B("bb command")}, {{'s'}, ("sort=\"$(printf '%s\\n' n s m c a r p | " PICK("Sort (n)ame (s)ize (m)odification (c)reation (a)ccess (r)andom (p)ermissions: ", "") ")\" " "&& bb \"+sort:+$sort\" +refresh"), B("Sort")" by..."}, - {{'#'}, "bb \"+col:`"ASKECHO("Set columns: ", "")"`\"", "Set "B("columns")}, + {{'#'}, "bb \"+col:$("ASKECHO("Set columns: ", "")")\"", "Set "B("columns")}, {{'.'}, "+dotfiles", "Toggle "B("dotfiles")}, {{'g', KEY_HOME}, "+move:0", "Go to "B("first")" file"}, {{'G', KEY_END}, "+move:100%n", "Go to "B("last")" file"},