From 84a7eb49fd8f2921cc8bbb4b357be0af54142f81 Mon Sep 17 00:00:00 2001 From: sld-admin Date: Thu, 27 Aug 2026 11:30:33 +0100 Subject: [PATCH] -p view source code of the script with lines number, -v shows only the plain script --- README.it.md | 17 +++++---- README.md | 17 +++++---- installer/brc-script-install.sh | 3 +- installer/scripts-needed/brc-script.sh | 49 ++++++++++++++++++++------ 4 files changed, 61 insertions(+), 25 deletions(-) diff --git a/README.it.md b/README.it.md index cd2dea0..911b1f1 100644 --- a/README.it.md +++ b/README.it.md @@ -59,7 +59,7 @@ Invece di accumulare centinaia di alias, funzioni, variabili d'ambiente e prompt | ❌ Difficile isolare bug e testare modifiche | ✅ Attiva o disattiva i moduli all'istante (`brc-script -e` / `-d`) | | ❌ Rischio di rompere l'intera shell per un errore | ✅ Attivazione sicura tramite symlink e backup automatici | | ❌ Complesso condividere o sincronizzare snippet | ✅ File modulari pronti per essere condivisi o versionati | -| ❌ Necessità di aprire editor di testo per leggere i file | ✅ Anteprima immediata da terminale con numeri di riga (`brc-script -p`) | +| ❌ Necessità di aprire editor di testo per leggere i file | ✅ Anteprima immediata o cat da terminale (`brc-script -p` / `-v`) | --- @@ -74,8 +74,8 @@ Invece di accumulare centinaia di alias, funzioni, variabili d'ambiente e prompt - ⚡ **Gestione Massiva Multi-Script** Abilita, disabilita, visualizza o rimuovi più script simultaneamente passando gli ID numerici o i nomi dei file (es. `brc-script -e 1 3 4` oppure `brc-script -d 03_bashboard 04_aliases`). -- 👁️ **Anteprima Rapida del Codice (`cat`)** - Ispeziona il contenuto e la sintassi di uno script direttamente nel terminale con intestazioni colorate e numerazione delle righe senza dover aprire editor esterni (`brc-script -p `). +- 👁️ **Anteprima e Cat Immediato del Codice (`-p` / `-v`)** + Ispeziona il codice di uno script direttamente nel terminale senza dover aprire editor esterni. Usa `brc-script -p ` per l'anteprima numerata con intestazioni a colori, oppure `brc-script -v ` (o `--cat`) per visualizzare il codice pulito senza numeri di riga. - 🖥️ **Bashboard di Sistema Intelligente** Include `03_bashboard.sh`, una dashboard stile MOTD veloce che mostra CPU, RAM, dischi, temperatura, IP locali/pubblici, aggiornamenti di sistema e il **rilevamento dinamico automatico della Web UI di Cockpit**. @@ -167,7 +167,8 @@ Il comando principale per gestire l'intero ambiente è `brc-script`. | Azione | Flag / Alias | Argomenti | Descrizione | | :--- | :--- | :--- | :--- | | **Elenco Script** | `-l`, `--list`, `list` | *nessuno* | Mostra tutti gli script, l'ID numerico e lo stato di attivazione (`-` blu) | -| **Anteprima / Cat** | `-p`, `-v`, `--cat`, `--show`, `cat` | `` | Stampa a terminale il codice con numeri di riga senza aprire editor | +| **Anteprima (Numerata)** | `-p`, `--preview`, `preview` | `` | Stampa il codice con numeri di riga e intestazione informativa | +| **Cat / Vista (Semplice)** | `-v`, `--cat`, `--view`, `--show`, `cat`, `view` | `` | Stampa il codice pulito dello script senza numeri di riga | | **Abilita** | `-e`, `--enable`, `enable` | `` | Attiva uno o più script creando il symlink in `scripts-enabled/` | | **Disabilita** | `-d`, `--disable`, `disable` | `` | Disattiva uno o più script rimuovendo il symlink | | **Abilita Tutti** | `-ea`, `--enable-all`, `enable-all` | *nessuno* | Attiva contemporaneamente tutti gli script disponibili | @@ -221,13 +222,15 @@ brc-script -d 2 4 5 brc-script -d 03_bashboard 04_aliases ``` -#### 4. Visualizzare l'Anteprima del Codice Direttamente nel Terminale +#### 4. Visualizzare l'Anteprima o Eseguire il Cat del Codice nel Terminale Esamina cosa fa uno script prima di attivarlo: ```bash -# Anteprima tramite ID numerico +# Anteprima con numeri di riga e intestazione formattata brc-script -p 4 +brc-script --preview 03_bashboard -# Anteprima tramite nome script +# Stampa (cat) del codice pulito senza numeri di riga (ideale per copia-incolla) +brc-script -v 4 brc-script --cat 03_bashboard ``` diff --git a/README.md b/README.md index edea060..5aa5746 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ Instead of stuffing hundreds of aliases, functions, exports, and prompt customiz | ❌ Hard to debug errors and test changes | ✅ Enable or disable modules instantly (`brc-script -e` / `-d`) | | ❌ Risk of accidentally breaking the whole shell | ✅ Safe symlink-based activation and automatic backups | | ❌ Impossible to share individual snippets | ✅ Modular files ready to share, version-control, or reuse | -| ❌ Manually editing files to preview snippets | ✅ Instant terminal preview with line numbering (`brc-script -p`) | +| ❌ Manually editing files to preview snippets | ✅ Instant terminal preview or cat (`brc-script -p` / `-v`) | --- @@ -74,8 +74,8 @@ Instead of stuffing hundreds of aliases, functions, exports, and prompt customiz - ⚡ **Multi-Script Batch Management** Enable, disable, preview, or remove multiple scripts at the same time using either their numeric ID or script name (e.g. `brc-script -e 1 3 4` or `brc-script -d 03_bashboard 04_aliases`). -- 👁️ **Instant Script Code Preview (`cat`)** - View script contents with colored status headers and line numbering without opening an external editor (`brc-script -p `). +- 👁️ **Instant Script Code Preview & Cat (`-p` / `-v`)** + Inspect script contents directly in the terminal without opening an external editor. Use `brc-script -p ` for preview with colored headers and line numbers, or `brc-script -v ` (or `--cat`) for clean code cat without line numbers. - 🖥️ **Smart System Bashboard** Includes `03_bashboard.sh`, a fast MOTD-style dashboard showing CPU, RAM, disk usage, uptime, distro details, IP addresses, package update counts, and **automatic dynamic discovery of Cockpit Web UI**. @@ -167,7 +167,8 @@ When your shell starts, `~/.bashrc` executes a minimal loader loop that sources | Action | Flags / Aliases | Arguments | Description | | :--- | :--- | :--- | :--- | | **List** | `-l`, `--list`, `list` | *none* | Lists all scripts with IDs, names, and active status (`-` in blue) | -| **Preview** | `-p`, `-v`, `--cat`, `--show`, `cat` | `` | Prints script code with line numbers without opening an editor | +| **Preview (Numbered)** | `-p`, `--preview`, `preview` | `` | Prints script code with line numbers and status headers | +| **Cat / View (Plain)** | `-v`, `--cat`, `--view`, `--show`, `cat`, `view` | `` | Prints clean script code without line numbers | | **Enable** | `-e`, `--enable`, `enable` | `` | Activates one or more scripts by creating symlinks in `scripts-enabled/` | | **Disable** | `-d`, `--disable`, `disable` | `` | Deactivates one or more scripts by removing symlinks | | **Enable All** | `-ea`, `--enable-all`, `enable-all` | *none* | Enables all available scripts at once | @@ -221,13 +222,15 @@ brc-script -d 2 4 5 brc-script -d 03_bashboard 04_aliases ``` -#### 4. Previewing Script Code Directly in Terminal +#### 4. Previewing and Catting Script Code Directly in Terminal Inspect what a script does before enabling it: ```bash -# Preview using numeric ID +# Preview with line numbers and header info brc-script -p 4 +brc-script --preview 03_bashboard -# Preview using script name +# Cat clean code without line numbers (easy to copy & paste) +brc-script -v 4 brc-script --cat 03_bashboard ``` diff --git a/installer/brc-script-install.sh b/installer/brc-script-install.sh index 1c793a9..9f3c842 100755 --- a/installer/brc-script-install.sh +++ b/installer/brc-script-install.sh @@ -291,7 +291,8 @@ echo "" echo "Use commands:" echo " brc-script -> manage scripts" echo " brc-script -l -> list scripts" -echo " brc-script --cat -> preview a script" +echo " brc-script -p -> preview script (with line numbers)" +echo " brc-script -v -> cat script (plain code)" echo " brc-script -e -> enable script(s)" echo " brc-script -d -> disable script(s)" echo " brc-script --update -> check Gitea updates" diff --git a/installer/scripts-needed/brc-script.sh b/installer/scripts-needed/brc-script.sh index 3e50597..a13ea2e 100755 --- a/installer/scripts-needed/brc-script.sh +++ b/installer/scripts-needed/brc-script.sh @@ -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 | Preview / Cat script(s) " + echo " -p, --preview | Preview (with numbers) " + echo " -v, --cat | Cat / view (plain code) " echo " -e, --enable | Enable script(s) " echo " -d, --disable | 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