-p view source code of the script with lines number, -v shows only the plain script

This commit is contained in:
2026-08-27 11:30:33 +01:00
parent a40e5dfba8
commit 84a7eb49fd
4 changed files with 61 additions and 25 deletions
+39 -10
View File
@@ -216,17 +216,25 @@ EOF
fi
}
# Preview / Cat a script
catscript() {
# Display helper for cat and preview
_display_script() {
local numbered="$1"
shift
local targets=("$@")
local action_title="View / Cat Script"
local prompt_msg="Select script number(s) or name(s) to view: "
if [ "$numbered" -eq 1 ]; then
action_title="Preview Script (Numbered)"
prompt_msg="Select script number(s) or name(s) to preview: "
fi
if [ ${#targets[@]} -eq 0 ]; then
echo "------------------------------------"
echo " Preview / Cat Script "
echo " $action_title"
echo "------------------------------------"
listitem
echo "------------------------------------"
read -rp "Select script number(s) or name(s) to preview: " input_str
read -rp "$prompt_msg" input_str
# shellcheck disable=SC2206
targets=($input_str)
fi
@@ -261,10 +269,14 @@ catscript() {
ccecho -t white " 📊 Lines: ${total_lines}"
echo "================================================================================"
if command -v nl >/dev/null 2>&1; then
nl -ba -w4 -s': ' "$full_path"
if [ "$numbered" -eq 1 ]; then
if command -v nl >/dev/null 2>&1; then
nl -ba -w4 -s': ' "$full_path"
else
cat -n "$full_path"
fi
else
cat -n "$full_path"
cat "$full_path"
fi
echo "================================================================================"
@@ -275,6 +287,16 @@ catscript() {
done
}
# Plain Cat of script(s)
catscript() {
_display_script 0 "$@"
}
# Numbered Preview of script(s)
previewscript() {
_display_script 1 "$@"
}
# Enable one or more scripts by ID or Name
enablescript() {
local targets=("$@")
@@ -669,8 +691,13 @@ brc-script() {
fi
case "$cmd" in
### PREVIEW / CAT SCRIPT ###
-p|-v|--cat|--view|--show|cat|show|view)
### PREVIEW SCRIPT (WITH LINE NUMBERS) ###
-p|--preview|preview)
previewscript "$@"
;;
### VIEW / CAT SCRIPT (PLAIN CODE) ###
-v|--cat|--view|--show|cat|show|view)
catscript "$@"
;;
@@ -738,7 +765,8 @@ brc-script() {
echo " List of brc-script commands "
echo "--------------------------------------------------------"
echo " -l, --list | List all scripts "
echo " -p, --cat <id|name ...> | Preview / Cat script(s) "
echo " -p, --preview <id|name ...> | Preview (with numbers) "
echo " -v, --cat <id|name ...> | Cat / view (plain code) "
echo " -e, --enable <id|name ...> | Enable script(s) "
echo " -d, --disable <id|name ...> | Disable script(s) "
echo " -ea, --enable-all | Enable all scripts "
@@ -752,6 +780,7 @@ brc-script() {
echo " Example: brc-script -d 1 5 12 03_bashboard "
echo " Example: brc-script -e 2 4 01_git-cli-highlitgh "
echo " Example: brc-script -p 03_bashboard "
echo " Example: brc-script -v 03_bashboard "
echo "--------------------------------------------------------"
;;
esac