on master help sign in
Add cat alias detection to info.sh (#911)
commit96aedf624031901c34763fa44513628e23ded6ca authorEthan P <32112321+eth-p@users.noreply.github.com> dateMon 20 Apr 2020, 23:33 (7 years ago) parent4cc2989
1 file changed+28−21
diagnostics/info.sh+28−21
diagnostics/info.sh+28−21
@@ -71,27 +71,34 @@ _bat_wrapper_:run() {
7171}
7272
7373_bat_wrapper_function_:run() {
74− case "$("$SHELL" --version | head -n 1)" in
75− *fish*)
76− if "$SHELL" --login -i -c 'type bat' 2>&1 | grep 'function' &> /dev/null; then
77− _out_fence "$SHELL" --login -c 'functions bat'
78− return
79− fi
80− ;;
81−
82− *bash* | *zsh*)
83− if "$SHELL" --login -i -c 'type bat' 2>&1 | grep 'function' &> /dev/null; then
84− _out_fence "$SHELL" --login -i -c 'declare -f bat'
85− return
86− fi
87− ;;
88−
89− *)
90− echo "Unable to determine if a wrapper function is set."
91− return
92− ;;
93− esac
94− printf "\nNo wrapper function.\n"
74+ _bat_wrapper_function_:detect_wrapper() {
75+ local command="$1"
76+ case "$("$SHELL" --version | head -n 1)" in
77+ *fish*)
78+ if "$SHELL" --login -i -c "type ${command}" 2>&1 | grep 'function' &>/dev/null; then
79+ _out_fence "$SHELL" --login -i -c "functions ${command}"
80+ return
81+ fi ;;
82+
83+ *bash*|*zsh*)
84+ local type="$("$SHELL" --login -i -c "type ${command}" 2>&1)"
85+ if grep 'function' <<< "$type" &>/dev/null; then
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}"
90+ return
91+ fi ;;
92+
93+ *)
94+ echo "Unable to determine if a wrapper function for '${command}' is set."
95+ return ;;
96+ esac
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
95102}
96103
97104_system_:run() {