2020-02-23 03:14:30 +01:00
|
|
|
#!/usr/bin/env bash
|
2020-02-25 22:54:31 +01:00
|
|
|
_modules=('system' 'bat' 'bat_config' 'bat_wrapper' 'bat_wrapper_function' 'tool')
|
2020-02-23 03:14:30 +01:00
|
|
|
_modules_consented=()
|
|
|
|
|
2020-03-03 22:28:26 +01:00
|
|
|
set -o pipefail
|
2020-02-23 03:14:30 +01:00
|
|
|
|
2020-04-08 23:16:18 +02:00
|
|
|
export LC_ALL=C
|
|
|
|
export LANG=C
|
|
|
|
|
2020-05-02 10:24:43 +02:00
|
|
|
BAT="bat"
|
|
|
|
if ! command -v bat &>/dev/null; then
|
|
|
|
if command -v batcat &> /dev/null; then
|
|
|
|
BAT="batcat"
|
|
|
|
else
|
|
|
|
tput setaf 1
|
|
|
|
printf "%s\n%s\n" \
|
|
|
|
"Unable to find a bat executable on your PATH." \
|
|
|
|
"Please ensure that 'bat' exists and is not named something else."
|
|
|
|
tput sgr0
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-05-02 10:13:26 +02:00
|
|
|
fi
|
|
|
|
|
2020-02-23 03:14:30 +01:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Modules:
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
_bat_:description() {
|
|
|
|
_collects "Version information for 'bat'."
|
2020-03-03 22:28:26 +01:00
|
|
|
_collects "Custom syntaxes and themes for 'bat'."
|
2020-02-23 03:14:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_bat_config_:description() {
|
|
|
|
_collects "The environment variables used by 'bat'."
|
|
|
|
_collects "The 'bat' configuration file."
|
|
|
|
}
|
|
|
|
|
|
|
|
_bat_wrapper_:description() {
|
|
|
|
_collects "Any wrapper script used by 'bat'."
|
|
|
|
}
|
|
|
|
|
2020-02-27 23:46:36 +01:00
|
|
|
_bat_wrapper_function_:description() {
|
2020-02-25 22:54:31 +01:00
|
|
|
_collects "The wrapper function surrounding 'bat' (if applicable)."
|
|
|
|
}
|
|
|
|
|
2020-02-23 03:14:30 +01:00
|
|
|
_system_:description() {
|
|
|
|
_collects "Operating system name."
|
|
|
|
_collects "Operating system version."
|
|
|
|
}
|
|
|
|
|
|
|
|
_tool_:description() {
|
|
|
|
_collects "Version information for 'less'."
|
|
|
|
}
|
|
|
|
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
|
|
|
|
_bat_:run() {
|
2020-05-02 10:13:26 +02:00
|
|
|
_out "$BAT" --version
|
2020-02-23 03:14:30 +01:00
|
|
|
_out env | grep '^BAT_\|^PAGER='
|
2020-03-03 22:28:26 +01:00
|
|
|
|
2020-11-29 23:41:18 +01:00
|
|
|
local cache_dir
|
|
|
|
cache_dir="$($BAT --cache-dir)"
|
2020-03-03 22:28:26 +01:00
|
|
|
if [[ -f "${cache_dir}/syntaxes.bin" ]]; then
|
2020-05-02 10:13:26 +02:00
|
|
|
_print_command "$BAT" "--list-languages"
|
2020-03-03 22:28:26 +01:00
|
|
|
echo "Found custom syntax set."
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -f "${cache_dir}/themes.bin" ]]; then
|
2020-05-02 10:13:26 +02:00
|
|
|
_print_command "$BAT" "--list-themes"
|
2020-03-03 22:28:26 +01:00
|
|
|
echo "Found custom theme set."
|
|
|
|
fi
|
2020-02-23 03:14:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_bat_config_:run() {
|
2020-05-02 10:13:26 +02:00
|
|
|
if [[ -f "$("$BAT" --config-file)" ]]; then
|
|
|
|
_out_fence cat "$("$BAT" --config-file)"
|
2020-02-23 03:14:30 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
_bat_wrapper_:run() {
|
2020-05-02 10:13:26 +02:00
|
|
|
_bat_wrapper_:detect_wrapper() {
|
|
|
|
local bat="$1"
|
2020-11-29 23:41:18 +01:00
|
|
|
if file "$(command -v "${bat}")" | grep "text executable" &> /dev/null; then
|
|
|
|
_out_fence cat "$(command -v "${bat}")"
|
2020-05-02 10:13:26 +02:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
printf "\nNo wrapper script for '%s'.\n" "${bat}"
|
|
|
|
}
|
|
|
|
|
|
|
|
_bat_wrapper_:detect_wrapper bat
|
|
|
|
if [[ "$BAT" != "bat" ]]; then
|
|
|
|
_bat_wrapper_:detect_wrapper "$BAT"
|
2020-02-23 03:14:30 +01:00
|
|
|
fi
|
2020-02-25 22:54:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_bat_wrapper_function_:run() {
|
2020-04-21 08:33:44 +02:00
|
|
|
_bat_wrapper_function_:detect_wrapper() {
|
|
|
|
local command="$1"
|
|
|
|
case "$("$SHELL" --version | head -n 1)" in
|
|
|
|
*fish*)
|
2020-05-02 10:13:26 +02:00
|
|
|
if "$SHELL" --login -i -c "type ${command}" 2>&1 | grep 'function' &> /dev/null; then
|
2020-04-21 08:33:44 +02:00
|
|
|
_out_fence "$SHELL" --login -i -c "functions ${command}"
|
|
|
|
return
|
|
|
|
fi ;;
|
|
|
|
|
2020-05-02 10:13:26 +02:00
|
|
|
*bash* | *zsh*)
|
2020-11-29 23:41:18 +01:00
|
|
|
local type
|
|
|
|
type="$("$SHELL" --login -i -c "type ${command}" 2>&1)"
|
2020-05-02 10:13:26 +02:00
|
|
|
if grep 'function' <<< "$type" &> /dev/null; then
|
2020-04-21 08:33:44 +02:00
|
|
|
_out_fence "$SHELL" --login -i -c "declare -f ${command}"
|
|
|
|
return
|
2020-05-02 10:13:26 +02:00
|
|
|
elif grep 'alias' <<< "$type" &> /dev/null; then
|
2020-04-21 08:33:44 +02:00
|
|
|
_out_fence "$SHELL" --login -i -c "type ${command}"
|
|
|
|
return
|
|
|
|
fi ;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
echo "Unable to determine if a wrapper function for '${command}' is set."
|
|
|
|
return ;;
|
|
|
|
esac
|
|
|
|
printf "\nNo wrapper function for '%s'.\n" "${command}"
|
|
|
|
}
|
|
|
|
|
|
|
|
_bat_wrapper_function_:detect_wrapper bat
|
|
|
|
_bat_wrapper_function_:detect_wrapper cat
|
2020-05-02 10:13:26 +02:00
|
|
|
if [[ "$BAT" != "bat" ]]; then
|
|
|
|
_bat_wrapper_function_:detect_wrapper "$BAT"
|
|
|
|
fi
|
2020-02-23 03:14:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_system_:run() {
|
|
|
|
_out uname -srm
|
|
|
|
|
2020-04-08 23:16:46 +02:00
|
|
|
if command -v "sw_vers" &> /dev/null; then _out sw_vers; fi
|
|
|
|
if command -v "lsb_release" &> /dev/null; then _out lsb_release -a; fi
|
2020-02-23 03:14:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_tool_:run() {
|
|
|
|
_out less --version | head -n1
|
|
|
|
}
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Functions:
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
2020-02-25 22:54:31 +01:00
|
|
|
_print_command() {
|
2020-02-28 00:00:19 +01:00
|
|
|
printf '\n**$' 1>&2
|
|
|
|
printf ' %s' "$@" 1>&2
|
|
|
|
printf '**\n' 1>&2
|
2020-02-25 22:54:31 +01:00
|
|
|
}
|
2020-02-23 03:14:30 +01:00
|
|
|
|
2020-02-25 22:54:31 +01:00
|
|
|
_out() {
|
|
|
|
_print_command "$@"
|
2020-02-28 00:00:19 +01:00
|
|
|
"$@" 2>&1 | sed 's/$/ /'
|
|
|
|
}
|
|
|
|
|
|
|
|
_out_fence() {
|
|
|
|
_print_command "$@"
|
|
|
|
printf '```\n' 1>&2
|
2020-02-23 03:14:30 +01:00
|
|
|
"$@" 2>&1
|
2020-02-28 00:00:19 +01:00
|
|
|
printf '```\n' 1>&2
|
2020-02-23 03:14:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_tput() {
|
2020-04-08 23:16:46 +02:00
|
|
|
tput "$@" 1>&2 2> /dev/null
|
2020-02-23 03:14:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_collects() {
|
|
|
|
printf " - %s\n" "$1" 1>&2
|
|
|
|
}
|
|
|
|
|
|
|
|
_ask_module() {
|
|
|
|
_tput clear
|
|
|
|
_tput cup 0 0
|
|
|
|
|
2020-04-08 23:16:46 +02:00
|
|
|
cat 1>&2 << EOF
|
2020-02-23 03:14:30 +01:00
|
|
|
--------------------------------------------------------------------------------
|
2020-02-23 23:28:57 +01:00
|
|
|
This script runs some harmless commands to collect information about your
|
|
|
|
system and bat configuration. It will give you a small preview of the commands
|
|
|
|
that will be run, and ask consent before running them. Once completed, it will
|
|
|
|
output a small report that you can review and copy into the issue description.
|
2020-02-23 03:14:30 +01:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# Print description.
|
|
|
|
_tput setaf 3
|
|
|
|
printf "The following data will be collected:\n" 1>&2
|
|
|
|
_tput sgr0
|
|
|
|
"_$1_:description"
|
|
|
|
_tput sgr0
|
2020-03-03 22:28:26 +01:00
|
|
|
|
2020-02-23 03:14:30 +01:00
|
|
|
# Print preview.
|
|
|
|
_tput setaf 3
|
|
|
|
printf "\nThe following commands will be run:\n" 1>&2
|
|
|
|
_tput sgr0
|
|
|
|
declare -f "_$1_:run" \
|
|
|
|
| sed 's/^ *//; s/;$//' \
|
2020-02-28 00:00:19 +01:00
|
|
|
| grep '^_out[^ ]* ' \
|
2020-05-02 10:13:26 +02:00
|
|
|
| sed 's/^_out[^ ]* //' \
|
|
|
|
| sed "s/\"\$BAT\"/$BAT/" 1>&2
|
2020-02-23 03:14:30 +01:00
|
|
|
|
|
|
|
# Prompt
|
|
|
|
printf "\n" 1>&2
|
|
|
|
local response
|
|
|
|
while true; do
|
2020-04-08 23:16:46 +02:00
|
|
|
_tput cup "$(($( tput lines || echo 22) - 2))"
|
2020-02-23 03:14:30 +01:00
|
|
|
_tput el
|
|
|
|
read -er -p "Collect $(sed 's/_/ /' <<< "$1") data? [Y/n] " response
|
|
|
|
case "$response" in
|
2020-04-08 23:16:46 +02:00
|
|
|
Y | y | yes | '') return 0 ;;
|
|
|
|
N | n | no) return 1 ;;
|
|
|
|
*) continue ;;
|
2020-02-23 03:14:30 +01:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
_run_module() {
|
2020-02-28 00:00:19 +01:00
|
|
|
local module="$1"
|
|
|
|
printf "%s\n%s\n" "$module" "$(printf "%${#module}s" | tr ' ' '-')"
|
2020-02-23 03:14:30 +01:00
|
|
|
"_$1_:run"
|
|
|
|
}
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Functions:
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
2020-05-02 10:13:26 +02:00
|
|
|
# Tell the user if their executable isn't named "bat".
|
|
|
|
if [[ "$BAT" != "bat" ]] && [[ "$1" != '-y' ]]; then
|
2020-05-02 10:15:32 +02:00
|
|
|
trap '_tput rmcup; exit 1' INT
|
|
|
|
_tput smcup
|
|
|
|
_tput clear
|
|
|
|
_tput cup 0 0
|
2020-05-02 10:13:26 +02:00
|
|
|
_tput setaf 1
|
|
|
|
printf "The %s executable on your system is named '%s'.\n%s\n" "bat" "$BAT" \
|
|
|
|
"If your issue is related to installation, please check that this isn't the issue."
|
|
|
|
_tput sgr0
|
|
|
|
printf "Press any key to continue...\n"
|
|
|
|
read -rsn1
|
2020-05-02 10:15:32 +02:00
|
|
|
_tput rmcup
|
2020-05-02 10:13:26 +02:00
|
|
|
fi
|
|
|
|
|
2020-02-23 03:14:30 +01:00
|
|
|
# Ask for consent.
|
2020-04-08 23:16:46 +02:00
|
|
|
if [[ "$1" == '-y' ]]; then
|
2020-02-23 03:14:30 +01:00
|
|
|
_modules_consented=("${_modules[@]}")
|
|
|
|
else
|
|
|
|
trap '_tput rmcup; exit 1' INT
|
|
|
|
_tput smcup
|
|
|
|
for _module in "${_modules[@]}"; do
|
|
|
|
if _ask_module "$_module"; then
|
|
|
|
_modules_consented+=("$_module")
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
_tput rmcup
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Collect information.
|
|
|
|
for _module in "${_modules_consented[@]}"; do
|
2020-02-28 00:00:19 +01:00
|
|
|
_run_module "$_module" 2>&1
|
2020-02-23 03:14:30 +01:00
|
|
|
printf "\n"
|
|
|
|
done
|