Files
Modular-Bashrc-Manager/README.md
T

231 lines
8.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Modular Bashrc Manager
### A simple, modular, and clean way to manage your `.bashrc` file in Linux.
---
`Modular Bashrc Manager` is a shell-based system designed to keep your Bash configuration clean, structured, and easy to maintain.
Instead of placing everything directly inside `.bashrc`, this project lets you split your configuration into modular scripts that are loaded automatically at shell startup.
The project includes:
- an automated intelligent installer with OS detection and automatic migration
- a command-line management tool (`brc-script`)
- a modular directory layout (`scripts-available`, `scripts-enabled`, `scripts-needed`, `scripts-removed`)
- default ready-to-use scripts (Git highlights, multi-distro bashboard with Cockpit auto-detection, aliases)
- a reusable colored echo utility (`ccecho`)
- Gitea update and self-upgrade mechanism
This makes it easier to add, remove, enable, disable, preview, and maintain shell customizations without turning `.bashrc` into a long and messy file.
---
## Features
- **Modular setup**
Keep `.bashrc` organized by loading only the scripts you need.
- **Intelligent Installer & Migration**
Automatically migrates your pre-existing `.bashrc` into `00_default.sh` and enables it, cleans `.bashrc` to only contain the loader, and installs required tools (`jq`, `curl`) matching your Linux distribution.
- **Multi-Script Management**
Enable or disable multiple scripts in a single command using numerical IDs or script names (e.g. `brc-script -d 1 5 12 10` or `brc-script -e 01_git-cli-highlitgh 03_bashboard`).
- **Quick Script Preview (`cat`)**
Inspect script content and line numbers directly from the terminal with `brc-script -p <id|name>` without opening text editors.
- **Cockpit Auto-Detection**
`03_bashboard.sh` automatically detects if Cockpit is installed and running, discovers its listening port dynamically (from `/etc/cockpit/cockpit.conf`, systemd sockets, or 9090), and shows the direct URL.
- **Gitea Updates & Upgrades**
Check for project updates directly from Gitea with `brc-script --update` and upgrade core and standard scripts safely with `brc-script --upgrade` without touching your personal customizations.
- **Reusable utility functions**
Includes `ccecho`, a colored echo helper for cleaner terminal output.
---
## How It Works
The installer backs up your existing `.bashrc`, migrates its content into `~/.bashrc.d/scripts-available/00_default.sh`, enables it, and replaces `.bashrc` with a minimal loader block.
That block sources scripts from the modular directories:
- `scripts-needed/`
Essential logic scripts required for the system to work (`brc-script.sh`, `ccecho.sh`).
- `scripts-enabled/`
Scripts that should be loaded at shell startup (symlinks to `scripts-available/`).
- `scripts-available/`
Scripts that are installed and ready to be enabled or customized.
- `scripts-removed/`
Scripts that were removed and stored as timestamped backups.
---
## Directory Structure
After installation, the system uses the following layout:
```text
~/.bashrc.d/
├── .version
├── scripts-needed/
│ ├── brc-script.sh
│ └── ccecho.sh
├── scripts-available/
│ ├── 00_default.sh
│ ├── 01_git-cli-highlitgh.sh
│ ├── 02_git-cli-highlitgh-root.sh
│ ├── 03_bashboard.sh
│ └── 04_aliases.sh
├── scripts-enabled/
│ └── 00_default.sh -> ~/.bashrc.d/scripts-available/00_default.sh
└── scripts-removed/
```
---
## Installation
### Automated Installation
1. Clone the repository from the official Gitea server:
```bash
git clone https://gitea.sld-server.org/sld-admin/Modular-Bashrc-Manager
cd Modular-Bashrc-Manager/installer
```
2. Make the installer executable and run it:
```bash
chmod +x brc-script-install.sh
./brc-script-install.sh
```
### What the installer does:
- Detects the Linux distribution (`apt`, `dnf`, `yum`, `pacman`, `zypper`, `apk`, `brew`) and automatically installs `jq` and `curl` if missing.
- Creates timestamped backup of your current `.bashrc`.
- Automatically copies your existing `.bashrc` content into `~/.bashrc.d/scripts-available/00_default.sh` and enables it.
- Writes the clean modular loader block to `.bashrc`.
- Copies core scripts to `scripts-needed/` and default scripts to `scripts-available/`.
- Initializes the `.version` file for future update tracking.
3. Reload `.bashrc`:
```bash
source ~/.bashrc
# or run: refresh-brc
```
---
## Usage (`brc-script`)
The main command-line management tool is `brc-script`.
### Available Commands
| Command | Alias / Flags | Description |
| :--- | :--- | :--- |
| **List Scripts** | `brc-script -l` / `--list` | Lists all available scripts and indicates active/enabled status (`-`). |
| **Preview / Cat Script** | `brc-script -p` / `--cat <id\|name ...>` | Prints script source code with line numbers and status without opening an editor. |
| **Enable Script(s)** | `brc-script -e` / `--enable <id\|name ...>` | Enables one or multiple scripts by numeric ID or name. |
| **Disable Script(s)** | `brc-script -d` / `--disable <id\|name ...>` | Disables one or multiple scripts by numeric ID or name. |
| **Enable All** | `brc-script -ea` / `--enable-all` | Enables all available scripts. |
| **Disable All** | `brc-script -da` / `--disable-all` | Disables all currently enabled scripts. |
| **Create Script** | `brc-script -c` / `--create` | Prompts for a name, generates a template, and opens it in your editor. |
| **Modify Script** | `brc-script -m` / `--modify <id\|name>` | Opens a script in editor and allows renaming. |
| **Remove Script** | `brc-script -r` / `--remove <id\|name ...>` | Moves script(s) to `scripts-removed/` with a timestamp. |
| **Check Updates** | `brc-script -u` / `--update` | Queries Gitea repository for latest commits and new updates. |
| **Upgrade System** | `brc-script --upgrade` | Upgrades core and default scripts from Gitea (never touches `00_default.sh`). |
| **Reload Shell** | `refresh-brc` | Reloads `.bashrc` in current session. |
---
### Command Examples
#### 1. Listing scripts
```bash
brc-script -l
```
#### 2. Enabling multiple scripts at once (by ID or Name)
```bash
# Enable by multiple IDs
brc-script -e 1 3 4
# Enable by script names (with or without .sh)
brc-script -e 01_git-cli-highlitgh 03_bashboard
```
#### 3. Disabling multiple scripts at once
```bash
# Disable multiple IDs
brc-script -d 1 5 12 10
# Disable by name
brc-script -d 03_bashboard 04_aliases
```
#### 4. Quick viewing / catting script contents
```bash
# Preview by name
brc-script -p 03_bashboard
# Preview by numerical ID
brc-script --cat 2
```
#### 5. Checking and applying Gitea updates
```bash
# Check if new versions or commits are available
brc-script --update
# Perform safe self-upgrade from Gitea
brc-script --upgrade
```
---
## Included Default Scripts
### `00_default.sh` Personal Configuration & Migration
Contains all your original aliases, functions, and environment variables migrated during installation. This file is yours and is never overwritten during upgrades.
### `01_git-cli-highlitgh.sh` & `02_git-cli-highlitgh-root.sh` Git Prompt
Shows branch name, uncommitted changes, staged files, untracked files, and ahead/behind remote indicators directly in your prompt.
### `03_bashboard.sh` Terminal System Dashboard
Displays CPU, RAM, disk usage, IP addresses, distro info, uptime, available packages updates, and automatically discovers **Cockpit Web UI** if installed (with dynamic port detection).
### `04_aliases.sh` Common Aliases
Useful starting aliases such as `alias ls="ls --color"`.
---
## Extra Utilities: `ccecho`
The project includes `ccecho.sh` in `scripts-needed/` for formatted and colored terminal output.
```bash
ccecho -t green -b black -s bold "Success!"
ccecho -t red -s underline "Error!"
```
**Text colors:** `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`, `bblack`, `bred`, `bgreen`, `byellow`, `bblue`, `bmagenta`, `bcyan`, `bwhite`.
**Styles:** `bold`, `dim`, `italic`, `underline`, `blink`, `reverse`, `hidden`, `strike`.
---
## Official Repository & Updates
- **Gitea:** [https://gitea.sld-server.org/sld-admin/Modular-Bashrc-Manager](https://gitea.sld-server.org/sld-admin/Modular-Bashrc-Manager)
- **Author:** Simone Cusano ([https://sld-server.org](https://sld-server.org))
---
## License
This project is licensed under the GNU General Public License v3.0.