on master help sign in
Add custom theme/syntax detection to info.sh
commite037afeacaa33ce08e08dd123c13a26e3d8067e1 authorEthan P <eth-p+git@hidden.email> dateTue 3 Mar 2020, 13:28 (7 years ago) parent7b87af1
1 file changed+18−5
diagnostics/info.sh+18−5
diagnostics/info.sh+18−5
@@ -2,6 +2,7 @@
22_modules=('system' 'bat' 'bat_config' 'bat_wrapper' 'bat_wrapper_function' 'tool')
33_modules_consented=()
44
5+set -o pipefail
56
67# -----------------------------------------------------------------------------
78# Modules:
@@ -9,6 +10,7 @@ _modules_consented=()
910
1011_bat_:description() {
1112 _collects "Version information for 'bat'."
13+ _collects "Custom syntaxes and themes for 'bat'."
1214}
1315
1416_bat_config_:description() {
@@ -39,11 +41,22 @@ _tool_:description() {
3941_bat_:run() {
4042 _out bat --version
4143 _out env | grep '^BAT_\|^PAGER='
44+
45+ local cache_dir="$(bat --cache-dir)"
46+ if [[ -f "${cache_dir}/syntaxes.bin" ]]; then
47+ _print_command "bat" "--list-languages"
48+ echo "Found custom syntax set."
49+ fi
50+
51+ if [[ -f "${cache_dir}/themes.bin" ]]; then
52+ _print_command "bat" "--list-themes"
53+ echo "Found custom theme set."
54+ fi
4255}
4356
4457_bat_config_:run() {
45− if [[ -f "$(bat --config-file)" ]]; then
46− _out_fence cat "$(bat --config-file)";
58+ if [[ -f "$(bat --config-file)" ]]; then
59+ _out_fence cat "$(bat --config-file)";
4760 fi
4861}
4962
@@ -57,7 +70,7 @@ _bat_wrapper_:run() {
5770
5871_bat_wrapper_function_:run() {
5972 case "$("$SHELL" --version | head -n 1)" in
60− *fish*)
73+ *fish*)
6174 if "$SHELL" --login -c 'type bat' 2>&1 | grep 'function' &>/dev/null; then
6275 _out_fence "$SHELL" --login -c 'functions bat'
6376 fi ;;
@@ -67,7 +80,7 @@ _bat_wrapper_function_:run() {
6780 _out_fence "$SHELL" --login -c 'declare -f bat'
6881 fi ;;
6982
70− *)
83+ *)
7184 echo "Unable to determine if a wrapper function is set."
7285 return ;;
7386 esac
@@ -135,7 +148,7 @@ EOF
135148 _tput sgr0
136149 "_$1_:description"
137150 _tput sgr0
138−
151+
139152 # Print preview.
140153 _tput setaf 3
141154 printf "\nThe following commands will be run:\n" 1>&2