Add some print info/success/warning/error helpers
- ID
547f8a2- date
2025-04-23 06:07:17+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
cc03935- message
Add some print info/success/warning/error helpers- changed files
6 files, 107 additions, 16 deletions
Changed files
debug/README.md (0) → debug/README.md (2047)
diff --git a/debug/README.md b/debug/README.md
new file mode 100644
index 0000000..3d73011
--- /dev/null
+++ b/debug/README.md
@@ -0,0 +1,88 @@
+# debug
+
+This is a collection of scripts that use [ANSI escape codes](https://stackoverflow.com/a/5947802/1558022) to print coloured messages to the terminal.
+
+I have them saved as individual shell scripts so I can call them from any of my other scripts.
+
+## The individual scripts
+
+<!-- [[[cog
+
+# This adds the root of the repo to the PATH, which has cog_helpers.py
+from os.path import abspath, dirname
+import sys
+
+sys.path.append(abspath(dirname(dirname("."))))
+
+import cog_helpers
+
+folder_name = "debug"
+
+scripts = [
+ {
+ "usage": "print_error [MESSAGE]",
+ "description": """
+ print an error message in red and to stdout
+ """
+ },
+ {
+ "usage": "print_info [MESSAGE]",
+ "description": """
+ print an info message in blue
+ """
+ },
+ {
+ "usage": "print_success [MESSAGE]",
+ "description": """
+ print a success message in green
+ """
+ },
+ {
+ "usage": "print_warning [MESSAGE]",
+ "description": """
+ print a warning message in yellow
+ """
+ },
+]
+
+cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
+
+]]]-->
+<dl>
+ <dt>
+ <a href="https://github.com/alexwlchan/scripts/blob/main/debug/print_error">
+ <code>print_error [MESSAGE]</code>
+ </a>
+ </dt>
+ <dd>
+ print an error message in red and to stdout
+ </dd>
+
+ <dt>
+ <a href="https://github.com/alexwlchan/scripts/blob/main/debug/print_info">
+ <code>print_info [MESSAGE]</code>
+ </a>
+ </dt>
+ <dd>
+ print an info message in blue
+ </dd>
+
+ <dt>
+ <a href="https://github.com/alexwlchan/scripts/blob/main/debug/print_success">
+ <code>print_success [MESSAGE]</code>
+ </a>
+ </dt>
+ <dd>
+ print a success message in green
+ </dd>
+
+ <dt>
+ <a href="https://github.com/alexwlchan/scripts/blob/main/debug/print_warning">
+ <code>print_warning [MESSAGE]</code>
+ </a>
+ </dt>
+ <dd>
+ print a warning message in yellow
+ </dd>
+</dl>
+<!-- [[[end]]] (checksum: 6fc892fcb4c7c365c7cd03abce3b6946) -->
debug/print_error (0) → debug/print_error (84)
diff --git a/debug/print_error b/debug/print_error
new file mode 100755
index 0000000..68c57a8
--- /dev/null
+++ b/debug/print_error
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+set -o errexit
+set -o nounset
+
+echo -e "\033[31m$1\033[0m" >&2
git/print_info (80) → debug/print_info (80)
diff --git a/git/print_info b/debug/print_info
similarity index 100%
rename from git/print_info
rename to debug/print_info
debug/print_success (0) → debug/print_success (80)
diff --git a/debug/print_success b/debug/print_success
new file mode 100755
index 0000000..591ed9b
--- /dev/null
+++ b/debug/print_success
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+set -o errexit
+set -o nounset
+
+echo -e "\033[32m$1\033[0m"
debug/print_warning (0) → debug/print_warning (80)
diff --git a/debug/print_warning b/debug/print_warning
new file mode 100755
index 0000000..b63e138
--- /dev/null
+++ b/debug/print_warning
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+set -o errexit
+set -o nounset
+
+echo -e "\033[33m$1\033[0m"
git/README.md (8029) → git/README.md (7624)
diff --git a/git/README.md b/git/README.md
index b159f1a..83dd2e4 100644
--- a/git/README.md
+++ b/git/README.md
@@ -114,12 +114,6 @@ scripts = [
open the current Git repo in <a href="https://gitup.co/">GitUp</a>, my GUI Git client of choice
"""
},
- {
- "usage": "print_info [MESSAGE]",
- "description": """
- helper script that lets me print text in blue inside other Git scripts
- """
- },
]
cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
@@ -273,14 +267,5 @@ cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
<dd>
open the current Git repo in <a href="https://gitup.co/">GitUp</a>, my GUI Git client of choice
</dd>
-
- <dt>
- <a href="https://github.com/alexwlchan/scripts/blob/main/git/print_info">
- <code>print_info [MESSAGE]</code>
- </a>
- </dt>
- <dd>
- helper script that lets me print text in blue inside other Git scripts
- </dd>
</dl>
-<!-- [[[end]]] (checksum: 8e699083c35f78871a88e9bf6ca053bd) -->
+<!-- [[[end]]] (checksum: 113cfe8c833dfc74985f3f7dff2bcace) -->