on master help sign in
Check for 'batcat' in info.sh
commit7bc4020a9235e39144d0017e904deb5d62c40b64 authorEthan P <eth-p+git@hidden.email> dateSat 2 May 2020, 01:13 (7 years ago) parent0792195
1 file changed+43−14
diagnostics/info.sh+43−14
diagnostics/info.sh+43−14
@@ -7,6 +7,12 @@ set -o pipefail
77export LC_ALL=C
88export LANG=C
99
10+if command -v batcat &> /dev/null; then
11+ BAT="batcat"
12+else
13+ BAT="bat"
14+fi
15+
1016# -----------------------------------------------------------------------------
1117# Modules:
1218# -----------------------------------------------------------------------------
@@ -41,33 +47,42 @@ _tool_:description() {
4147# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4248
4349_bat_:run() {
44− _out bat --version
50+ _out "$BAT" --version
4551 _out env | grep '^BAT_\|^PAGER='
4652
4753 local cache_dir="$(bat --cache-dir)"
4854 if [[ -f "${cache_dir}/syntaxes.bin" ]]; then
49− _print_command "bat" "--list-languages"
55+ _print_command "$BAT" "--list-languages"
5056 echo "Found custom syntax set."
5157 fi
5258
5359 if [[ -f "${cache_dir}/themes.bin" ]]; then
54− _print_command "bat" "--list-themes"
60+ _print_command "$BAT" "--list-themes"
5561 echo "Found custom theme set."
5662 fi
5763}
5864
5965_bat_config_:run() {
60− if [[ -f "$(bat --config-file)" ]]; then
61− _out_fence cat "$(bat --config-file)"
66+ if [[ -f "$("$BAT" --config-file)" ]]; then
67+ _out_fence cat "$("$BAT" --config-file)"
6268 fi
6369}
6470
6571_bat_wrapper_:run() {
66− if file "$(which bat)" | grep "text executable" &> /dev/null; then
67− _out_fence cat "$(which bat)"
68− return
72+ _bat_wrapper_:detect_wrapper() {
73+ local bat="$1"
74+ if file "$(which "${bat}")" | grep "text executable" &> /dev/null; then
75+ _out_fence cat "$(which "${bat}")"
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"
6985 fi
70− printf "\nNo wrapper script.\n"
7186}
7287
7388_bat_wrapper_function_:run() {
@@ -75,17 +90,17 @@ _bat_wrapper_function_:run() {
7590 local command="$1"
7691 case "$("$SHELL" --version | head -n 1)" in
7792 *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
7994 _out_fence "$SHELL" --login -i -c "functions ${command}"
8095 return
8196 fi ;;
8297
83− *bash*|*zsh*)
98+ *bash* | *zsh*)
8499 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
86101 _out_fence "$SHELL" --login -i -c "declare -f ${command}"
87102 return
88− elif grep 'alias' <<< "$type" &>/dev/null; then
103+ elif grep 'alias' <<< "$type" &> /dev/null; then
89104 _out_fence "$SHELL" --login -i -c "type ${command}"
90105 return
91106 fi ;;
@@ -99,6 +114,9 @@ _bat_wrapper_function_:run() {
99114
100115 _bat_wrapper_function_:detect_wrapper bat
101116 _bat_wrapper_function_:detect_wrapper cat
117+ if [[ "$BAT" != "bat" ]]; then
118+ _bat_wrapper_function_:detect_wrapper "$BAT"
119+ fi
102120}
103121
104122_system_:run() {
@@ -169,7 +187,8 @@ EOF
169187 declare -f "_$1_:run" \
170188 | sed 's/^ *//; s/;$//' \
171189 | grep '^_out[^ ]* ' \
172− | sed 's/^_out[^ ]* //' 1>&2
190+ | sed 's/^_out[^ ]* //' \
191+ | sed "s/\"\$BAT\"/$BAT/" 1>&2
173192
174193 # Prompt
175194 printf "\n" 1>&2
@@ -196,6 +215,16 @@ _run_module() {
196215# Functions:
197216# -----------------------------------------------------------------------------
198217
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+
199228# Ask for consent.
200229if [[ "$1" == '-y' ]]; then
201230 _modules_consented=("${_modules[@]}")