aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-10-03 14:57:34 -0700
committerBruce Hill <bruce@bruce-hill.com>2019-10-03 14:57:34 -0700
commit7f0fcdeea449a3ffc7a65a3024b6b5d4a1b3e93b (patch)
tree45f43e00d7bbafd122d423f96c73a5baa1f53baa
parent97bae88a1ef368b962df5b1ee147094a0d47d43e (diff)
Removed some unnecessary +refreshes, no longer enable cursor by default,
but instead have ask() etc. make the cursor visible. Also cleaned up some of the failure cases for better feedback.
-rw-r--r--Makefile12
-rw-r--r--bb.c1
-rw-r--r--bb.h3
-rw-r--r--bindings.bb34
4 files changed, 29 insertions, 21 deletions
diff --git a/Makefile b/Makefile
index d0c953d..b49fb9d 100644
--- a/Makefile
+++ b/Makefile
@@ -24,16 +24,16 @@ endif
ifneq (, $(PICKER))
PICKER_FLAG=-D"PICK=\"$(PICKER) --prompt=\\\"$$1\\\"\""
ifeq ($(shell which $(PICKER)),$(shell which fzy 2>/dev/null || echo '<none>'))
- PICKER_FLAG=-D'PICK="printf \"\\033[3A\" >/dev/tty; fzy --lines=3 --prompt=\"\033[1m$$1\033[0m\""'
+ PICKER_FLAG=-D'PICK="printf \"\\033[3A\\033[?25h\" >/dev/tty; fzy --lines=3 --prompt=\"\033[1m$$1\033[0m\""'
endif
ifeq ($(shell which $(PICKER)),$(shell which fzf 2>/dev/null || echo '<none>'))
- PICKER_FLAG=-D'PICK="printf \"\\033[3A\" >/dev/tty; fzf --height=4 --prompt=\"$$1\""'
+ PICKER_FLAG=-D'PICK="printf \"\\033[3A\\033[?25h\" >/dev/tty; fzf --height=4 --prompt=\"$$1\""'
endif
ifeq ($(shell which $(PICKER)),$(shell which ask 2>/dev/null || echo '<none>'))
- PICKER_FLAG=-D'PICK="/usr/bin/env ask --prompt=\"$$1\""'
+ PICKER_FLAG=-D'PICK="/usr/bin/env ask --prompt=\"$$1\033[?25h\""'
endif
ifeq ($(shell which $(PICKER)),$(shell which pick 2>/dev/null || echo '<none>'))
- PICKER_FLAG=-D'PICK="pick"'
+ PICKER_FLAG=-D'PICK="printf \"\\033[?25h\" >/dev/tty; pick"'
endif
ifeq ($(shell which $(PICKER)),$(shell which dmenu 2>/dev/null || echo '<none>'))
PICKER_FLAG=-D'PICK="dmenu -i -l 10 -p \"$$1\""'
@@ -44,8 +44,8 @@ CFLAGS += $(PICKER_FLAG)
ifneq (, $(ASKER))
PERCENT := %
ifeq ($(shell which $(ASKER)),$(shell which ask 2>/dev/null || echo '<none>'))
- CFLAGS += -D'ASK="eval \"$$1=\\$$(/usr/bin/env ask --history=bb.hist --prompt=\\\"$$2\\\" --query=\\\"$$3\\\")\""'
- CFLAGS += -D'CONFIRM="/usr/bin/env ask -n \"Is that okay?\""'
+ CFLAGS += -D'ASK="eval \"$$1=\\$$(/usr/bin/env ask --history=bb.hist --prompt=\\\"$$2\033[?25h\\\" --query=\\\"$$3\\\")\""'
+ CFLAGS += -D'CONFIRM="/usr/bin/env ask -n \"Is that okay?\033[?25h\""'
endif
ifeq ($(shell which $(ASKER)),$(shell which dmenu 2>/dev/null || echo '<none>'))
CFLAGS += -D'ASK="eval \"$$1=\\$$(echo \"$$3\" | dmenu -p \"$$2\")\""'
diff --git a/bb.c b/bb.c
index 2a5ee44..1b539b1 100644
--- a/bb.c
+++ b/bb.c
@@ -159,7 +159,6 @@ void bb_browse(bb_t *bb, const char *path)
process_cmd(bb, binding->script);
} else {
move_cursor(tty_out, 0, termheight-1);
- fputs(T_ON(T_SHOW_CURSOR), tty_out);
restore_term(&default_termios);
run_script(bb, binding->script);
init_term();
diff --git a/bb.h b/bb.h
index 6f2a8f9..95f7175 100644
--- a/bb.h
+++ b/bb.h
@@ -240,7 +240,8 @@ static const char *bbcmdfn = "bb() {\n"
#ifdef ASK
ASK ";\n"
#else
-" printf \"\033[1m%s\033[0m\" \"$2\" >/dev/tty;\n"
+" [ $# -lt 2 ] && printf '\033[31;1mNot enough args to ask!\033[0m\n' && return 1;\n"
+" printf \"\033[1m%s\033[0m\033[?25h\" \"$2\" >/dev/tty;\n"
" read $1 </dev/tty >/dev/tty\n"
#endif
"}\n"
diff --git a/bindings.bb b/bindings.bb
index 0bae3c1..e7a90ea 100644
--- a/bindings.bb
+++ b/bindings.bb
@@ -69,8 +69,7 @@ Ctrl-s: # Save the selection
Ctrl-o: # Open a saved selection
loadpath="$(find ~/.config/bb -maxdepth 1 -type f | pick "Load selection: ")" &&
[ -e "$loadpath" ] && bb +deselect &&
- while IFS= read -r -d $'\0'; do bb +select:"$REPLY"; done < "$loadpath" &&
- bb +refresh
+ while IFS= read -r -d $'\0'; do bb +select:"$REPLY"; done < "$loadpath"
J: # Spread selection down
bb +spread:+1
K: # Spread selection up
@@ -133,21 +132,29 @@ p: # Page through a file with $PAGER
>: # Open a shell
tput rmcup; $SHELL; bb +r
r,F2: # Rename a file
- ask newname "Rename \033[33m$(basename "$BBCURSOR")\033[39m: " "$(basename "$BBCURSOR")" || exit
+ ask newname "Rename $(printf "\033[33m%s\033[39m" "$(basename "$BBCURSOR")"): " "$(basename "$BBCURSOR")" || exit
r="$(dirname "$BBCURSOR")/$newname" || exit
- [ "$r" != "$BBCURSOR" ] && mv -i "$BBCURSOR" "$r" && bb +refresh &&
+ [ "$r" = "$BBCURSOR" ] && exit
+ [ -e "$r" ] && printf "\033[31;1m$r already exists! It will be overwritten.\033[0m " &&
+ confirm && { rm -rf "$r" || { pause; exit; }; }
+ mv "$BBCURSOR" "$r" && bb +refresh &&
while [ $# -gt 0 ]; do "$1" = "$BBCURSOR" && bb +deselect:"$BBCURSOR" +select:"$r"; shift; done &&
- bb +goto:"$r" +refresh
+ bb +goto:"$r" || { pause; exit; }
R: # Rename all selected files
- bb +refresh;
for f; do
- ask newname "Rename \033[33m$(basename "$f")\033[39m: " "$(basename "$f")" || break;
+ ask newname "Rename $(printf "\033[33m%s\033[39m" "$(basename "$f")"): " "$(basename "$f")" || break;
r="$(dirname "$f")/$newname";
- [ "$r" != "$f" ] && mv -i "$f" "$r" && bb +deselect:"$f" +select:"$r";
- [ "$f" = "$BBCURSOR" ] && bb +goto:"$r" +refresh;
- done
+ [ "$r" = "$f" ] && continue;
+ [ -e "$r" ] && printf "\033[31;1m$r already exists! It will be overwritten.\033[0m "
+ && confirm && { rm -rf "$r" || { pause; exit; }; }
+ mv "$f" "$r" || { pause; exit; }
+ bb +deselect:"$f" +select:"$r";
+ [ "$f" = "$BBCURSOR" ] && bb +goto:"$r";
+ done;
+ bb +refresh
Ctrl-r: # Regex rename files
- command -v rename >/dev/null || { echo 'The `rename` command is not installed. Please install it to use this key binding.'; pause; exit; };
+ command -v rename >/dev/null ||
+ { printf '\033[31;1mThe `rename` command is not installed. Please install it to use this key binding.\033[0m\n'; pause; exit; };
ask patt "Replace pattern: " && ask rep "Replacement: " &&
printf "\033[1mRenaming:\n\033[33m$(if [ $# -gt 0 ]; then rename -nv "$patt" "$rep" "$@"; else rename -nv "$patt" "$rep" *; fi)\033[0m" | more &&
confirm &&
@@ -157,7 +164,7 @@ Ctrl-r: # Regex rename files
Section: Viewing Options
s: # Sort by...
ask1 sort "Sort (n)ame (s)ize (m)odification (c)reation (a)ccess (r)andom (p)ermissions: " &&
- bb +sort:"~$sort" +refresh
+ bb +sort:"~$sort"
---,#: # Set columns
ask columns "Set columns (*)selected (a)ccessed (c)reated (m)odified (n)ame (p)ermissions (r)andom (s)ize: " &&
bb +col:"$columns"
@@ -168,6 +175,7 @@ i: # Toggle interleaving files and directories
F5: # Refresh view
bb +refresh
Ctrl-b: # Bind a key to a script
- ask1 key "Press key to bind..." && echo && ask script "Bind script: " && bb +bind:"$(printf "$key:$script")"
+ ask1 key "Press key to bind..." && echo && ask script "Bind script: " &&
+ bb +bind:"$key":"{ $script; } || pause" || pause
Section: User Bindings