From f8592c215a589d5cad0d5e4dd4ed5517f16a32bf Mon Sep 17 00:00:00 2001 From: hygienic-books Date: Mon, 6 Mar 2023 02:03:54 +0100 Subject: [PATCH] feat(script): Add colored print (#1) --- pacman-zfs-snapshot.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pacman-zfs-snapshot.sh b/pacman-zfs-snapshot.sh index 0bf380d..7c74832 100755 --- a/pacman-zfs-snapshot.sh +++ b/pacman-zfs-snapshot.sh @@ -31,6 +31,32 @@ if [[ ! "${snap_op_installation_suffix}" ]]; then snap_op_installation_suffix='i if [[ ! "${snap_op_remove_suffix}" ]]; then snap_op_remove_suffix='rmvl'; fi if [[ ! "${snap_op_upgrade_suffix}" ]]; then snap_op_upgrade_suffix='upgr'; fi +function pprint () { + local style msg exit_code + style="${1:?}" + msg="${2:?}" + exit_code="${3}" + + local color_reset color_lyellow + color_reset='\e[0m' + color_lyellow='\e[93m' + color_red='\e[31m' + + case "${style}" in + warn) + printf -- "${color_lyellow}"'[WARN]'"${color_reset}"' %s\n' "${msg}" + ;; + err) + printf -- "${color_red}"'[ERR]'"${color_reset}"' %s\n' "${msg}" + ;; + *) + printf -- '[INFO] %s\n' "${msg}" + ;; + esac + + [[ "${exit_code}" ]] && exit "${exit_code}" +} + function split_pkgs_by_importance () { local pkgs_in_transaction pkgs_in_transaction=("${@}")