on master help sign in
Add detection of a wrapper function to info.sh
commit8648b86a73542a4ec65157218cb03d7135d9f72f authorEthan P <eth-p+git@hidden.email> dateTue 25 Feb 2020, 13:54 (7 years ago) parent39d9343
1 file changed+32−4
diagnostics/info.sh+32−4
diagnostics/info.sh+32−4
@@ -1,5 +1,5 @@
11#!/usr/bin/env bash
2−_modules=('system' 'bat' 'bat_config' 'bat_wrapper' 'tool')
2+_modules=('system' 'bat' 'bat_config' 'bat_wrapper' 'bat_wrapper_function' 'tool')
33_modules_consented=()
44
55
@@ -20,6 +20,10 @@ _bat_wrapper_:description() {
2020 _collects "Any wrapper script used by 'bat'."
2121}
2222
23+_bat_wrapper_function_description() {
24+ _collects "The wrapper function surrounding 'bat' (if applicable)."
25+}
26+
2327_system_:description() {
2428 _collects "Operating system name."
2529 _collects "Operating system version."
@@ -46,7 +50,28 @@ _bat_config_:run() {
4650_bat_wrapper_:run() {
4751 if file "$(which bat)" | grep "text executable" &>/dev/null; then
4852 _out cat "$(which bat)"
53+ return
4954 fi
55+ printf "\nNo wrapper script.\n"
56+}
57+
58+_bat_wrapper_function_:run() {
59+ case "$("$SHELL" --version | head -n 1)" in
60+ *fish*)
61+ if "$SHELL" --login -c 'type bat' 2>&1 | grep 'function' &>/dev/null; then
62+ _out "$SHELL" --login -c 'functions bat'
63+ fi ;;
64+
65+ *bash*)
66+ if "$SHELL" --login -c 'type bat' 2>&1 | grep 'function' &>/dev/null; then
67+ _out "$SHELL" --login -c 'declare -f bat'
68+ fi ;;
69+
70+ *)
71+ echo "Unable to determine if a wrapper function is set."
72+ return ;;
73+ esac
74+ printf "\nNo wrapper function.\n"
5075}
5176
5277_system_:run() {
@@ -65,11 +90,14 @@ _tool_:run() {
6590# Functions:
6691# -----------------------------------------------------------------------------
6792
68−_out() {
93+_print_command() {
6994 printf "\n+" 1>&2
7095 printf " %s" "$@" 1>&2
7196 printf "\n" 1>&2
97+}
7298
99+_out() {
100+ _print_command "$@"
73101 "$@" 2>&1
74102}
75103
@@ -107,8 +135,8 @@ EOF
107135 _tput sgr0
108136 declare -f "_$1_:run" \
109137 | sed 's/^ *//; s/;$//' \
110− | grep '^_out ' \
111− | sed 's/^_out //' 1>&2
138+ | grep '^_out\([21]*\) ' \
139+ | sed 's/^_out\([21]*\) //' 1>&2
112140
113141 # Prompt
114142 printf "\n" 1>&2