From 6497bc04a044569b22f5c24d646265254446f391 Mon Sep 17 00:00:00 2001 From: Ethan P Date: Sun, 4 Apr 2021 14:22:39 -0700 Subject: [PATCH] batpipe: Change the install commands to enable color automatically --- src/batpipe.sh | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/batpipe.sh b/src/batpipe.sh index 7f19dc0..aba7a51 100755 --- a/src/batpipe.sh +++ b/src/batpipe.sh @@ -81,11 +81,30 @@ if [[ "$#" -eq 0 ]]; then printc '%{YELLOW}set -e %{CLEAR}LESSCLOSE;\n' ;; *) # Bash-like - printc '%{MAGENTA}LESSOPEN%{YELLOW}=%{CYAN}"|%s %%s"%{CLEAR};\n' "$SELF" + printc '%{MAGENTA}LESSOPEN%{CLEAR}=%{CYAN}"|%s %%s"%{CLEAR};\n' "$SELF" printc '%{YELLOW}export%{CLEAR} LESSOPEN;\n' "$SELF" printc '%{YELLOW}unset%{CLEAR} LESSCLOSE;\n' ;; esac + + # Print the commands required to use color in `less` with `batpipe`. + if [[ -t 1 ]]; then + printc "\n%{DIM}# The following will enable colors when using batpipe with less:\n" + fi + + # shellcheck disable=SC2016 + case "$(basename -- "${detected_shell:bash}")" in + fish) # Fish + printc '%{YELLOW}set -x %{CLEAR}LESS %{CYAN}"%{MAGENTA}$LESS%{CYAN} -R"%{CLEAR};\n' "$SELF" + printc '%{YELLOW}set -x %{CLEAR}BATPIPE %{CYAN}"color"%{CLEAR};\n' + ;; + *) # Bash-like + printc '%{MAGENTA}LESS%{CLEAR}=%{CYAN}"%{MAGENTA}$LESS%{CYAN} -R"%{CLEAR};\n' "$SELF" + printc '%{MAGENTA}BATPIPE%{CLEAR}=%{CYAN}"color"%{CLEAR};\n' "$SELF" + printc '%{YELLOW}export%{CLEAR} LESS;\n' "$SELF" + printc '%{YELLOW}export%{CLEAR} BATPIPE;\n' "$SELF" + ;; + esac exit 0 fi