From 8648b86a73542a4ec65157218cb03d7135d9f72f Mon Sep 17 00:00:00 2001 From: Ethan P Date: Tue, 25 Feb 2020 13:54:31 -0800 Subject: [PATCH] Add detection of a wrapper function to info.sh --- diagnostics/info.sh | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/diagnostics/info.sh b/diagnostics/info.sh index f92c594c..f95a4b42 100755 --- a/diagnostics/info.sh +++ b/diagnostics/info.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -_modules=('system' 'bat' 'bat_config' 'bat_wrapper' 'tool') +_modules=('system' 'bat' 'bat_config' 'bat_wrapper' 'bat_wrapper_function' 'tool') _modules_consented=() @@ -20,6 +20,10 @@ _bat_wrapper_:description() { _collects "Any wrapper script used by 'bat'." } +_bat_wrapper_function_description() { + _collects "The wrapper function surrounding 'bat' (if applicable)." +} + _system_:description() { _collects "Operating system name." _collects "Operating system version." @@ -46,7 +50,28 @@ _bat_config_:run() { _bat_wrapper_:run() { if file "$(which bat)" | grep "text executable" &>/dev/null; then _out cat "$(which bat)" + return fi + printf "\nNo wrapper script.\n" +} + +_bat_wrapper_function_:run() { + case "$("$SHELL" --version | head -n 1)" in + *fish*) + if "$SHELL" --login -c 'type bat' 2>&1 | grep 'function' &>/dev/null; then + _out "$SHELL" --login -c 'functions bat' + fi ;; + + *bash*) + if "$SHELL" --login -c 'type bat' 2>&1 | grep 'function' &>/dev/null; then + _out "$SHELL" --login -c 'declare -f bat' + fi ;; + + *) + echo "Unable to determine if a wrapper function is set." + return ;; + esac + printf "\nNo wrapper function.\n" } _system_:run() { @@ -65,11 +90,14 @@ _tool_:run() { # Functions: # ----------------------------------------------------------------------------- -_out() { +_print_command() { printf "\n+" 1>&2 printf " %s" "$@" 1>&2 printf "\n" 1>&2 +} +_out() { + _print_command "$@" "$@" 2>&1 } @@ -107,8 +135,8 @@ EOF _tput sgr0 declare -f "_$1_:run" \ | sed 's/^ *//; s/;$//' \ - | grep '^_out ' \ - | sed 's/^_out //' 1>&2 + | grep '^_out\([21]*\) ' \ + | sed 's/^_out\([21]*\) //' 1>&2 # Prompt printf "\n" 1>&2