Switched some stuff to use $() instead of `` for better composing,

rearranged things a bit to launch bb fewer times for commands.
This commit is contained in:
Bruce Hill 2019-06-12 15:11:29 -07:00
parent 85a4be481b
commit 69955d3808
3 changed files with 30 additions and 20 deletions

View File

@ -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

10
bb.c
View File

@ -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] == '+') {
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;

View File

@ -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; then true; else " PAUSE "; exit; fi; "
"bb +refresh; "
"for f; do "
" renamed=\"`dirname \"$f\"`/`basename \"$f\" | sed -E \"$patt\"`\" || "PAUSE" && exit; "
" if test \"$f\" != \"$renamed\" && mv -i \"$f\" \"$renamed\"; then "
" test $BBSELECTED && bb \"+deselect:$f\" \"+select:$renamed\"; "
" fi; "
"done", B("Regex rename")" files"},
" renamed=\"$(dirname \"$f\")/$(basename \"$f\" | sed -E \"$patt\")\"; "
" if test \"$f\" != \"$renamed\" && mv -i \"$f\" \"$renamed\" && test $BBSELECTED; then "
" printf \"+deselect:$f\\0+select:$renamed\\0\"; "
" fi;"
"done | xargs -0 bb", B("Regex rename")" files"},
{{'P'},
"patt=`ask 'Select pattern: '` && "
"for f in *; do echo \"$f\" | grep \"$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"},