on master help sign in
Check for 'batcat' in info.sh
7bc4020Ethan P
diagnostics/info.sh+43−14
@@ -7,6 +7,12 @@ set -o pipefail
7export LC_ALL=C
7export LC_ALL=C
8export LANG=C
8export LANG=C
9
9
10+if command -v batcat &> /dev/null; then
11+ BAT="batcat"
12+else
13+ BAT="bat"
14+fi
15+
10# -----------------------------------------------------------------------------
16# -----------------------------------------------------------------------------
11# Modules:
17# Modules:
12# -----------------------------------------------------------------------------
18# -----------------------------------------------------------------------------
@@ -41,33 +47,42 @@ _tool_:description() {
41# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
47# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
42
48
43_bat_:run() {
49_bat_:run() {
44− _out bat --version
50+ _out "$BAT" --version
45 _out env | grep '^BAT_\|^PAGER='
51 _out env | grep '^BAT_\|^PAGER='
46
52
47 local cache_dir="$(bat --cache-dir)"
53 local cache_dir="$(bat --cache-dir)"
48 if [[ -f "${cache_dir}/syntaxes.bin" ]]; then
54 if [[ -f "${cache_dir}/syntaxes.bin" ]]; then
49− _print_command "bat" "--list-languages"
55+ _print_command "$BAT" "--list-languages"
50 echo "Found custom syntax set."
56 echo "Found custom syntax set."
51 fi
57 fi
52
58
53 if [[ -f "${cache_dir}/themes.bin" ]]; then
59 if [[ -f "${cache_dir}/themes.bin" ]]; then
54− _print_command "bat" "--list-themes"
60+ _print_command "$BAT" "--list-themes"
55 echo "Found custom theme set."
61 echo "Found custom theme set."
56 fi
62 fi
57}
63}
58
64
59_bat_config_:run() {
65_bat_config_:run() {
60− if [[ -f "$(bat --config-file)" ]]; then
66+ if [[ -f "$("$BAT" --config-file)" ]]; then
61− _out_fence cat "$(bat --config-file)"
67+ _out_fence cat "$("$BAT" --config-file)"
62 fi
68 fi
63}
69}
64
70
65_bat_wrapper_:run() {
71_bat_wrapper_:run() {
72+ _bat_wrapper_:detect_wrapper() {
73+ local bat="$1"
66− if file "$(which bat)" | grep "text executable" &> /dev/null; then
74+ if file "$(which "${bat}")" | grep "text executable" &> /dev/null; then
67− _out_fence cat "$(which bat)"
75+ _out_fence cat "$(which "${bat}")"
68− return
76+ return
77+ fi
78+
79+ printf "\nNo wrapper script for '%s'.\n" "${bat}"
80+ }
81+
82+ _bat_wrapper_:detect_wrapper bat
83+ if [[ "$BAT" != "bat" ]]; then
84+ _bat_wrapper_:detect_wrapper "$BAT"
69 fi
85 fi
70− printf "\nNo wrapper script.\n"
71}
86}
72
87
73_bat_wrapper_function_:run() {
88_bat_wrapper_function_:run() {
@@ -75,17 +90,17 @@ _bat_wrapper_function_:run() {
75 local command="$1"
90 local command="$1"
76 case "$("$SHELL" --version | head -n 1)" in
91 case "$("$SHELL" --version | head -n 1)" in
77 *fish*)
92 *fish*)
78− if "$SHELL" --login -i -c "type ${command}" 2>&1 | grep 'function' &>/dev/null; then
93+ if "$SHELL" --login -i -c "type ${command}" 2>&1 | grep 'function' &> /dev/null; then
79 _out_fence "$SHELL" --login -i -c "functions ${command}"
94 _out_fence "$SHELL" --login -i -c "functions ${command}"
80 return
95 return
81 fi ;;
96 fi ;;
82
97
83− *bash*|*zsh*)
98+ *bash* | *zsh*)
84 local type="$("$SHELL" --login -i -c "type ${command}" 2>&1)"
99 local type="$("$SHELL" --login -i -c "type ${command}" 2>&1)"
85− if grep 'function' <<< "$type" &>/dev/null; then
100+ if grep 'function' <<< "$type" &> /dev/null; then
86 _out_fence "$SHELL" --login -i -c "declare -f ${command}"
101 _out_fence "$SHELL" --login -i -c "declare -f ${command}"
87 return
102 return
88− elif grep 'alias' <<< "$type" &>/dev/null; then
103+ elif grep 'alias' <<< "$type" &> /dev/null; then
89 _out_fence "$SHELL" --login -i -c "type ${command}"
104 _out_fence "$SHELL" --login -i -c "type ${command}"
90 return
105 return
91 fi ;;
106 fi ;;
@@ -99,6 +114,9 @@ _bat_wrapper_function_:run() {
99
114
100 _bat_wrapper_function_:detect_wrapper bat
115 _bat_wrapper_function_:detect_wrapper bat
101 _bat_wrapper_function_:detect_wrapper cat
116 _bat_wrapper_function_:detect_wrapper cat
117+ if [[ "$BAT" != "bat" ]]; then
118+ _bat_wrapper_function_:detect_wrapper "$BAT"
119+ fi
102}
120}
103
121
104_system_:run() {
122_system_:run() {
@@ -169,7 +187,8 @@ EOF
169 declare -f "_$1_:run" \
187 declare -f "_$1_:run" \
170 | sed 's/^ *//; s/;$//' \
188 | sed 's/^ *//; s/;$//' \
171 | grep '^_out[^ ]* ' \
189 | grep '^_out[^ ]* ' \
172− | sed 's/^_out[^ ]* //' 1>&2
190+ | sed 's/^_out[^ ]* //' \
191+ | sed "s/\"\$BAT\"/$BAT/" 1>&2
173
192
174 # Prompt
193 # Prompt
175 printf "\n" 1>&2
194 printf "\n" 1>&2
@@ -196,6 +215,16 @@ _run_module() {
196# Functions:
215# Functions:
197# -----------------------------------------------------------------------------
216# -----------------------------------------------------------------------------
198
217
218+# Tell the user if their executable isn't named "bat".
219+if [[ "$BAT" != "bat" ]] && [[ "$1" != '-y' ]]; then
220+ _tput setaf 1
221+ printf "The %s executable on your system is named '%s'.\n%s\n" "bat" "$BAT" \
222+ "If your issue is related to installation, please check that this isn't the issue."
223+ _tput sgr0
224+ printf "Press any key to continue...\n"
225+ read -rsn1
226+fi
227+
199# Ask for consent.
228# Ask for consent.
200if [[ "$1" == '-y' ]]; then
229if [[ "$1" == '-y' ]]; then
201 _modules_consented=("${_modules[@]}")
230 _modules_consented=("${_modules[@]}")