From ff441f2d975ac9ee2dcaeecc138511c75b763da5 Mon Sep 17 00:00:00 2001 From: Deposite Pirate Date: Fri, 17 Oct 2025 14:48:08 +0200 Subject: Add a pretty print function modified: conf.d/00functions.fish --- conf.d/00functions.fish | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/conf.d/00functions.fish b/conf.d/00functions.fish index d1ad87b..d20c270 100644 --- a/conf.d/00functions.fish +++ b/conf.d/00functions.fish @@ -35,8 +35,50 @@ function find_prog --description "Find one or more programs in \$PATH" end end +function pp --description "Pretty print a message from a script" -a type -a msg + + if test -z "$msg" + return + end + + if test -z "$type" + set type info + end + + switch $type + case error + set -f mcolor red + set -f pcolor red + set -f prefix '!! ' + case warn + set -f mcolor yellow + set -f pcolor yellow + set -f prefix '?? ' + case info + set -f mcolor normal + set -f pcolor green + set -f prefix '==> ' + case info2 + set -f mcolor normal + set -f pcolor blue + set -f prefix ' -> ' + case ask + set -f mcolor normal + set -f pcolor blue + set -f prefix ':: ' + case debug + set -f mcolor cyan + set -f pcolor cyan + set -f prefix '** ' + end + + echo -n (set_color -o $pcolor)"$prefix"(set_color normal) + echo $(set_color $mcolor)"$msg"(set_color normal) + +end + function ask --description "Ask a question answered by yes or no" - read -n 1 -f -P (set_color -o blue)"::"(set_color normal)" $argv[1] [y/N] " answer + read -n 1 -f -P (pp ask "$argv[1] [y/N] ") answer switch $answer case y Y return 0 # yes -- cgit v1.3.1