on master help sign in
Add cat alias detection to info.sh (#911)
96aedf6Ethan P
diagnostics/info.sh+28−21
@@ -71,27 +71,34 @@ _bat_wrapper_:run() {
71}
71}
72
72
73_bat_wrapper_function_:run() {
73_bat_wrapper_function_:run() {
74+ _bat_wrapper_function_:detect_wrapper() {
75+ local command="$1"
74− case "$("$SHELL" --version | head -n 1)" in
76+ case "$("$SHELL" --version | head -n 1)" in
75− *fish*)
77+ *fish*)
76− if "$SHELL" --login -i -c 'type bat' 2>&1 | grep 'function' &> /dev/null; then
78+ if "$SHELL" --login -i -c "type ${command}" 2>&1 | grep 'function' &>/dev/null; then
77− _out_fence "$SHELL" --login -c 'functions bat'
79+ _out_fence "$SHELL" --login -i -c "functions ${command}"
78− return
80+ return
79− fi
81+ fi ;;
80− ;;
82+
81−
82− *bash* | *zsh*)
83+ *bash*|*zsh*)
84+ local type="$("$SHELL" --login -i -c "type ${command}" 2>&1)"
83− if "$SHELL" --login -i -c 'type bat' 2>&1 | grep 'function' &> /dev/null; then
85+ if grep 'function' <<< "$type" &>/dev/null; then
84− _out_fence "$SHELL" --login -i -c 'declare -f bat'
86+ _out_fence "$SHELL" --login -i -c "declare -f ${command}"
87+ return
88+ elif grep 'alias' <<< "$type" &>/dev/null; then
89+ _out_fence "$SHELL" --login -i -c "type ${command}"
85− return
90+ return
86− fi
91+ fi ;;
87− ;;
92+
88−
89− *)
93+ *)
90− echo "Unable to determine if a wrapper function is set."
94+ echo "Unable to determine if a wrapper function for '${command}' is set."
91− return
95+ return ;;
92− ;;
93− esac
96+ esac
94− printf "\nNo wrapper function.\n"
97+ printf "\nNo wrapper function for '%s'.\n" "${command}"
98+ }
99+
100+ _bat_wrapper_function_:detect_wrapper bat
101+ _bat_wrapper_function_:detect_wrapper cat
95}
102}
96
103
97_system_:run() {
104_system_:run() {