diff options
| author | Deposite Pirate | 2025-10-17 14:48:08 +0200 |
|---|---|---|
| committer | Deposite Pirate | 2025-10-17 14:48:08 +0200 |
| commit | ff441f2d975ac9ee2dcaeecc138511c75b763da5 (patch) | |
| tree | 8eda2c33ac8d65901a7f1d7899fd7428458c798c /conf.d/00functions.fish | |
| parent | df080c8210795c7827f05ce25dc160c6f0cf3afc (diff) | |
Add a pretty print function
modified: conf.d/00functions.fish
Diffstat (limited to 'conf.d/00functions.fish')
| -rw-r--r-- | conf.d/00functions.fish | 44 |
1 files changed, 43 insertions, 1 deletions
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 |
