1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-01-18 20:11:03 +00:00

Add custom theme/syntax detection to info.sh

This commit is contained in:
Ethan P 2020-03-03 13:28:26 -08:00 committed by David Peter
parent 7b87af1748
commit e037afeaca

View File

@ -2,6 +2,7 @@
_modules=('system' 'bat' 'bat_config' 'bat_wrapper' 'bat_wrapper_function' 'tool') _modules=('system' 'bat' 'bat_config' 'bat_wrapper' 'bat_wrapper_function' 'tool')
_modules_consented=() _modules_consented=()
set -o pipefail
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Modules: # Modules:
@ -9,6 +10,7 @@ _modules_consented=()
_bat_:description() { _bat_:description() {
_collects "Version information for 'bat'." _collects "Version information for 'bat'."
_collects "Custom syntaxes and themes for 'bat'."
} }
_bat_config_:description() { _bat_config_:description() {
@ -39,11 +41,22 @@ _tool_:description() {
_bat_:run() { _bat_:run() {
_out bat --version _out bat --version
_out env | grep '^BAT_\|^PAGER=' _out env | grep '^BAT_\|^PAGER='
local cache_dir="$(bat --cache-dir)"
if [[ -f "${cache_dir}/syntaxes.bin" ]]; then
_print_command "bat" "--list-languages"
echo "Found custom syntax set."
fi
if [[ -f "${cache_dir}/themes.bin" ]]; then
_print_command "bat" "--list-themes"
echo "Found custom theme set."
fi
} }
_bat_config_:run() { _bat_config_:run() {
if [[ -f "$(bat --config-file)" ]]; then if [[ -f "$(bat --config-file)" ]]; then
_out_fence cat "$(bat --config-file)"; _out_fence cat "$(bat --config-file)";
fi fi
} }
@ -57,7 +70,7 @@ _bat_wrapper_:run() {
_bat_wrapper_function_:run() { _bat_wrapper_function_:run() {
case "$("$SHELL" --version | head -n 1)" in case "$("$SHELL" --version | head -n 1)" in
*fish*) *fish*)
if "$SHELL" --login -c 'type bat' 2>&1 | grep 'function' &>/dev/null; then if "$SHELL" --login -c 'type bat' 2>&1 | grep 'function' &>/dev/null; then
_out_fence "$SHELL" --login -c 'functions bat' _out_fence "$SHELL" --login -c 'functions bat'
fi ;; fi ;;
@ -67,7 +80,7 @@ _bat_wrapper_function_:run() {
_out_fence "$SHELL" --login -c 'declare -f bat' _out_fence "$SHELL" --login -c 'declare -f bat'
fi ;; fi ;;
*) *)
echo "Unable to determine if a wrapper function is set." echo "Unable to determine if a wrapper function is set."
return ;; return ;;
esac esac
@ -135,7 +148,7 @@ EOF
_tput sgr0 _tput sgr0
"_$1_:description" "_$1_:description"
_tput sgr0 _tput sgr0
# Print preview. # Print preview.
_tput setaf 3 _tput setaf 3
printf "\nThe following commands will be run:\n" 1>&2 printf "\nThe following commands will be run:\n" 1>&2