diff options
author | Ethan P <eth-p+git@hidden.email> | 2020-02-25 13:54:31 -0800 |
---|---|---|
committer | David Peter <sharkdp@users.noreply.github.com> | 2020-02-28 08:03:13 +0100 |
commit | 8648b86a73542a4ec65157218cb03d7135d9f72f (patch) | |
tree | 0e91f9cdbcf9cecde3ef1f8cbf49c3988433ea48 /diagnostics | |
parent | 39d9343a7d3f1e1292e8d558789812ec90a080e1 (diff) |
Add detection of a wrapper function to info.sh
Diffstat (limited to 'diagnostics')
-rwxr-xr-x | diagnostics/info.sh | 36 |
1 files 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 |