From 9211a58624f9df6f94720cc2928e77218f027cb6 Mon Sep 17 00:00:00 2001 From: M/R <10809708-meanruse@users.noreply.gitlab.com> Date: Tue, 3 Jan 2023 18:33:02 +0000 Subject: [PATCH] Fully avoid outputting color escapes when redirected (garuda-inxi) --- usr/bin/garuda-inxi | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/usr/bin/garuda-inxi b/usr/bin/garuda-inxi index c16419c..fe1818f 100755 --- a/usr/bin/garuda-inxi +++ b/usr/bin/garuda-inxi @@ -1,5 +1,13 @@ #!/bin/bash +if [ -t 1 ] ; then + c_134=$'\033[1;34m' + c_131=$'\033[1;31m' + c_off=$'\033[0m' +else + c0="c0" +fi + detect_dual_boot() { if [[ $EUID -eq 0 ]] && [[ -x /usr/bin/os-prober ]]; then local OSPROBER_OUT="$(os-prober)" || { DUALBOOT="Os-prober error"; exit; } @@ -55,23 +63,25 @@ generate_system_update() { last_update="$(date -r /var/lib/garuda/last_update +%s 2> /dev/null)" || { echo "Unknown/Never"; return; } local reboot="" if [ "$last_update" -gt "$(date -r /proc +%s)" ]; then - reboot=" \033[1;31m↻" + reboot=" ${c_131}↻${c_off}" fi echo -e "$(date -d"@$last_update" +%F)${reboot}" } -[ -t 0 ] && inxi -Faz --zv || inxi -Fazc0 --zv -echo -e "\033[1;34mGaruda ($(pacman -Q garuda-common-settings | awk '{print $2}')):\033[0m" +inxi -Faz${c0} --zv + +echo -e "${c_134}Garuda ($(pacman -Q garuda-common-settings | awk '{print $2}')):${c_off}" install_date="$(head -n1 /var/log/pacman.log | cut -d " " -f1 | cut -c 2-11)" -echo -e "\033[1;34m System install date:\033[0m ${install_date}" -echo -e "\033[1;34m Last full system update:\033[0m $(generate_system_update)" -echo -e "\033[1;34m Is partially upgraded: \033[0m $([ -e /var/lib/garuda/partial_upgrade ] && echo Yes || echo No)" -echo -e "\033[1;34m Relevant software: \033[0m $(generate_relevant_software)" +echo -e "${c_134} System install date:${c_off} ${install_date}" +echo -e "${c_134} Last full system update:${c_off} $(generate_system_update)" +echo -e "${c_134} Is partially upgraded: ${c_off} $([ -e /var/lib/garuda/partial_upgrade ] && echo Yes || echo No)" +echo -e "${c_134} Relevant software: ${c_off} $(generate_relevant_software)" detect_dual_boot &> /dev/null -echo -e "\033[1;34m Windows dual boot: \033[0m ${DUALBOOT}" -echo -e "\033[1;34m Failed units: \033[0m $(systemctl list-units --failed --full --all --plain --no-legend | awk '{printf("%s ",$1)}')" +echo -e "${c_134} Windows dual boot: ${c_off} ${DUALBOOT}" +echo -e "${c_134} Failed units: ${c_off} $(systemctl list-units --failed --full --all --plain --no-legend | awk '{printf("%s ",$1)}')" if [ "$1" == "funstuff" ]; then update_count="$(paclog --grep="starting full system upgrade" | wc -l)" -echo -e "\033[1;34m Total system updates: \033[0m ${update_count}" -echo -e "\033[1;34m --> Updates per week: \033[0m $(( ${update_count}/(($(date +%s) - $(date --date="$install_date" +%s) )/(60*60*24*7)) ))" +echo -e "${c_134} Total system updates: ${c_off} ${update_count}" +echo -e "${c_134} --> Updates per week: ${c_off} $(( ${update_count}/(($(date +%s) - $(date --date="$install_date" +%s) )/(60*60*24*7)) ))" fi +