Add ccecho feature, and modified the main script
This commit is contained in:
50
README.md
50
README.md
@@ -11,6 +11,7 @@ This project provides a modular system for managing Bash scripts within the .bas
|
||||
- **Automatic Directory Structure**: The installer automatically creates directories for managing available, enabled, removed, and required scripts.
|
||||
- **Customizable Script Templates**: When creating a new script, a template with placeholders for options, variables, functions, and execution logic is provided.
|
||||
- **Easy Integration**: Automatically integrate with your existing .bashrc setup.
|
||||
- **Colorful Echo (`ccecho`)**: Print colored and styled messages for better terminal output, ( usable even outside of the brc-script environment )
|
||||
|
||||
## Directory Structure
|
||||
|
||||
@@ -23,14 +24,13 @@ After installation, the system uses the following directory layout to manage scr
|
||||
- `scripts-enabled/`: Symbolic links to enabled scripts.
|
||||
- `scripts-needed/`: Essential scripts required for the system to work.
|
||||
- `brc-script.sh`
|
||||
- `ccecho.sh`
|
||||
- `scripts-removed/`: Backup of removed scripts, timestamped.
|
||||
|
||||
## Installation
|
||||
|
||||
### Automated Installation
|
||||
|
||||
To install the system automatically, follow these steps:
|
||||
|
||||
1. Clone the repository:
|
||||
```bash
|
||||
git clone https://github.com/your-repo/modular-bashrc-manager.git
|
||||
@@ -46,20 +46,19 @@ To install the system automatically, follow these steps:
|
||||
The installer will:
|
||||
- Create the necessary directory structure: `scripts-needed`, `scripts-enabled`, `scripts-available`, and `scripts-removed`.
|
||||
- Append the required configuration to your .bashrc file.
|
||||
- Copy the main `brc-script.sh` script to `scripts-needed/`.
|
||||
- Copy the main `brc-script.sh` script and `ccecho.sh` to `scripts-needed/`.
|
||||
|
||||
After the installation completes, restart your shell or reload the .bashrc file by running:
|
||||
Reload the `.bashrc` file by running:
|
||||
```bash
|
||||
source ~/.bashrc
|
||||
```
|
||||
|
||||
### Manual Installation
|
||||
|
||||
If you prefer a manual installation process, follow these steps:
|
||||
|
||||
1. Copy the `brc-script.sh` file to the `~/.bashrc.d/scripts-needed/` folder:
|
||||
1. Copy the `brc-script.sh` and `ccecho.sh` files to the `~/.bashrc.d/scripts-needed/` folder:
|
||||
```bash
|
||||
cp brc-script.sh ~/.bashrc.d/scripts-needed/
|
||||
chmod 750 ~/.bashrc.d/scripts-needed/brc-script.sh
|
||||
cp brc-script.sh ccecho.sh ~/.bashrc.d/scripts-needed/
|
||||
chmod 750 ~/.bashrc.d/scripts-needed/brc-script.sh ~/.bashrc.d/scripts-needed/ccecho.sh
|
||||
```
|
||||
|
||||
2. Append the following lines to your `.bashrc` file:
|
||||
@@ -82,7 +81,7 @@ If you prefer a manual installation process, follow these steps:
|
||||
mkdir -p ~/.bashrc.d/scripts-needed ~/.bashrc.d/scripts-enabled ~/.bashrc.d/scripts-available ~/.bashrc.d/scripts-removed
|
||||
```
|
||||
|
||||
4. Restart your shell or source `.bashrc`:
|
||||
4. Reload `.bashrc`:
|
||||
```bash
|
||||
source ~/.bashrc
|
||||
```
|
||||
@@ -125,6 +124,37 @@ The `brc-script.sh` script provides a series of commands to manage your .bashrc
|
||||
brc-script -r
|
||||
```
|
||||
|
||||
## Extra Utilities
|
||||
|
||||
### `ccecho`: Colorful Echo for Enhanced Output
|
||||
|
||||
The project includes a utility script `ccecho.sh` located in `scripts-needed/`, which defines a function `ccecho`. This command allows you to print styled and colored messages to the terminal.
|
||||
|
||||
#### Usage
|
||||
|
||||
```bash
|
||||
ccecho -t green -b black -s bold "Success!"
|
||||
ccecho -t red -s underline "Error!"
|
||||
ccecho "Normal message without styling"
|
||||
```
|
||||
|
||||
#### Available Text Colors
|
||||
`black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`, `bblack`, `bred`, `bgreen`, `byellow`, `bblue`, `bmagenta`, `bcyan`, `bwhite`
|
||||
|
||||
#### Background Colors
|
||||
Same as above, applied with `-b`
|
||||
|
||||
#### Styles
|
||||
`bold`, `dim`, `italic`, `underline`, `blink`, `reverse`, `hidden`, `strike`
|
||||
|
||||
#### Make `ccecho` Globally Available
|
||||
|
||||
If you'd like to use `ccecho` in other terminal sessions or scripts, you can source it in your `.bashrc`:
|
||||
|
||||
```bash
|
||||
source ~/.bashrc.d/scripts-needed/ccecho.sh
|
||||
```
|
||||
|
||||
## Why Use This System?
|
||||
|
||||
Managing a large .bashrc file can become unmanageable, especially when adding multiple custom commands or functions. This system offers a structured approach to handle modular scripts, making it easier to enable or disable specific configurations without manually editing the .bashrc file each time.
|
||||
|
||||
66
README.md.backup
Executable file → Normal file
66
README.md.backup
Executable file → Normal file
@@ -1,5 +1,6 @@
|
||||
# Modular Bashrc Manager
|
||||
A simple, modular, and clean way to manage your .bashrc file in Linux.
|
||||
### A simple, modular, and clean way to manage your .bashrc file in Linux.
|
||||
---
|
||||
|
||||
This project provides a modular system for managing Bash scripts within the .bashrc environment. It allows users to easily enable, disable, create, and manage custom scripts through a well-structured directory layout, making the .bashrc configuration cleaner and easier to maintain.
|
||||
|
||||
@@ -10,6 +11,7 @@ This project provides a modular system for managing Bash scripts within the .bas
|
||||
- **Automatic Directory Structure**: The installer automatically creates directories for managing available, enabled, removed, and required scripts.
|
||||
- **Customizable Script Templates**: When creating a new script, a template with placeholders for options, variables, functions, and execution logic is provided.
|
||||
- **Easy Integration**: Automatically integrate with your existing .bashrc setup.
|
||||
- **Colorful Echo (`ccecho`)**: Print colored and styled messages for better terminal output, ( usable even outside of the brc-script environment )
|
||||
|
||||
## Directory Structure
|
||||
|
||||
@@ -18,19 +20,17 @@ After installation, the system uses the following directory layout to manage scr
|
||||
- `~/.bashrc.d/`: Main directory for managing Bash scripts.
|
||||
- `installer/`: Contains the installer and base script.
|
||||
- `brc-script-install.sh`
|
||||
- `brc-script.sh`
|
||||
- `scripts-available/`: Scripts available to be enabled.
|
||||
- `scripts-enabled/`: Symbolic links to enabled scripts.
|
||||
- `scripts-needed/`: Essential scripts required for the system to work.
|
||||
- `brc-script.sh`
|
||||
- `ccecho.sh`
|
||||
- `scripts-removed/`: Backup of removed scripts, timestamped.
|
||||
|
||||
## Installation
|
||||
|
||||
### Automated Installation
|
||||
|
||||
To install the system automatically, follow these steps:
|
||||
|
||||
1. Clone the repository:
|
||||
```bash
|
||||
git clone https://github.com/your-repo/modular-bashrc-manager.git
|
||||
@@ -46,20 +46,19 @@ To install the system automatically, follow these steps:
|
||||
The installer will:
|
||||
- Create the necessary directory structure: `scripts-needed`, `scripts-enabled`, `scripts-available`, and `scripts-removed`.
|
||||
- Append the required configuration to your .bashrc file.
|
||||
- Copy the main `brc-script.sh` script to `scripts-needed/`.
|
||||
- Copy the main `brc-script.sh` script and `ccecho.sh` to `scripts-needed/`.
|
||||
|
||||
After the installation completes, restart your shell or reload the .bashrc file by running:
|
||||
Reload the `.bashrc` file by running:
|
||||
```bash
|
||||
source ~/.bashrc
|
||||
```
|
||||
|
||||
### Manual Installation
|
||||
|
||||
If you prefer a manual installation process, follow these steps:
|
||||
|
||||
1. Copy the `brc-script.sh` file to the `~/.bashrc.d/scripts-needed/` folder:
|
||||
1. Copy the `brc-script.sh` and `ccecho.sh` files to the `~/.bashrc.d/scripts-needed/` folder:
|
||||
```bash
|
||||
cp brc-script.sh ~/.bashrc.d/scripts-needed/
|
||||
chmod 750 ~/.bashrc.d/scripts-needed/brc-script.sh
|
||||
cp brc-script.sh ccecho.sh ~/.bashrc.d/scripts-needed/
|
||||
chmod 750 ~/.bashrc.d/scripts-needed/brc-script.sh ~/.bashrc.d/scripts-needed/ccecho.sh
|
||||
```
|
||||
|
||||
2. Append the following lines to your `.bashrc` file:
|
||||
@@ -82,7 +81,7 @@ If you prefer a manual installation process, follow these steps:
|
||||
mkdir -p ~/.bashrc.d/scripts-needed ~/.bashrc.d/scripts-enabled ~/.bashrc.d/scripts-available ~/.bashrc.d/scripts-removed
|
||||
```
|
||||
|
||||
4. Restart your shell or source `.bashrc`:
|
||||
4. Reload `.bashrc`:
|
||||
```bash
|
||||
source ~/.bashrc
|
||||
```
|
||||
@@ -94,9 +93,9 @@ The `brc-script.sh` script provides a series of commands to manage your .bashrc
|
||||
- `-c` : Create a new script in the `scripts-available/` folder.
|
||||
- `-m` : Modify an existing script.
|
||||
- `-l` : List all available and enabled scripts.
|
||||
- `-e <index>` : Enable a script from the `scripts-available/` folder.
|
||||
- `-d <index>` : Disable an enabled script.
|
||||
- `-r <index>` : Remove a script, backing it up in `scripts-removed/`.
|
||||
- `-e` : Enable a script from the `scripts-available/` folder.
|
||||
- `-d` : Disable an enabled script.
|
||||
- `-r` : Remove a script, backing it up in `scripts-removed/`.
|
||||
|
||||
### Example Commands
|
||||
|
||||
@@ -112,19 +111,50 @@ The `brc-script.sh` script provides a series of commands to manage your .bashrc
|
||||
|
||||
- Enable a script:
|
||||
```bash
|
||||
brc-script -e <index>
|
||||
brc-script -e
|
||||
```
|
||||
|
||||
- Disable a script:
|
||||
```bash
|
||||
brc-script -d <index>
|
||||
brc-script -d
|
||||
```
|
||||
|
||||
- Remove a script:
|
||||
```bash
|
||||
brc-script -r <index>
|
||||
brc-script -r
|
||||
```
|
||||
|
||||
## Extra Utilities
|
||||
|
||||
### `ccecho`: Colorful Echo for Enhanced Output
|
||||
|
||||
The project includes a utility script `ccecho.sh` located in `scripts-needed/`, which defines a function `ccecho`. This command allows you to print styled and colored messages to the terminal.
|
||||
|
||||
#### Usage
|
||||
|
||||
```bash
|
||||
ccecho -t green -b black -s bold "Success!"
|
||||
ccecho -t red -s underline "Error!"
|
||||
ccecho "Normal message without styling"
|
||||
```
|
||||
|
||||
#### Available Text Colors
|
||||
`black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`, `bblack`, `bred`, `bgreen`, `byellow`, `bblue`, `bmagenta`, `bcyan`, `bwhite`
|
||||
|
||||
#### Background Colors
|
||||
Same as above, applied with `-b`
|
||||
|
||||
#### Styles
|
||||
`bold`, `dim`, `italic`, `underline`, `blink`, `reverse`, `hidden`, `strike`
|
||||
|
||||
#### Make `ccecho` Globally Available
|
||||
|
||||
If you'd like to use `ccecho` in other terminal sessions or scripts, you can source it in your `.bashrc`:
|
||||
|
||||
```bash
|
||||
source ~/.bashrc.d/scripts-needed/ccecho.sh
|
||||
```
|
||||
|
||||
## Why Use This System?
|
||||
|
||||
Managing a large .bashrc file can become unmanageable, especially when adding multiple custom commands or functions. This system offers a structured approach to handle modular scripts, making it easier to enable or disable specific configurations without manually editing the .bashrc file each time.
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
export NVM_DIR="$HOME/.nvm"
|
||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
|
||||
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
|
||||
|
||||
# Modular Bashrc
|
||||
mkdir -p ~/.bashrc.d/scripts-needed
|
||||
mkdir -p ~/.bashrc.d/scripts-enabled
|
||||
|
||||
@@ -23,17 +23,17 @@ bashrc="${home_folder}.bashrc"
|
||||
refresh-brc(){
|
||||
if [ "$1" == "-dis" ]; then
|
||||
echo "------------------------------------"
|
||||
echo "[ Bashrc Refreshed ]"
|
||||
ccecho -t bblue "[ Bashrc Refreshed ]"
|
||||
echo "You can't use the old commands from now!"
|
||||
echo "------------------------------------"
|
||||
elif [ "$1" == "-en" ]; then
|
||||
echo "------------------------------------"
|
||||
echo "[ Bashrc Refreshed ]"
|
||||
ccecho -t bblue "[ Bashrc Refreshed ]"
|
||||
echo "------------------------------------"
|
||||
echo "You can you the new commands from now!"
|
||||
ccecho -t bgreen -s bold "You can you the new commands from now!"
|
||||
echo "------------------------------------"
|
||||
else
|
||||
echo "[ Bashrc Refreshed ]"
|
||||
ccecho -t bblue "[ Bashrc Refreshed ]"
|
||||
fi
|
||||
source "$bashrc"
|
||||
}
|
||||
@@ -46,7 +46,7 @@ createscript() {
|
||||
echo "Name of the script: "
|
||||
read namenewscript
|
||||
if [ -f "${available_scripts}$namenewscript" ]; then
|
||||
echo "Script already exists!"
|
||||
ccecho -t byellow "Script already exists!"
|
||||
else
|
||||
newscriptav="${available_scripts}$namenewscript.sh"
|
||||
|
||||
@@ -100,7 +100,7 @@ createscript() {
|
||||
ln -sf "$newscriptav" "${enabled_scripts}$namenewscript.sh"
|
||||
refresh-brc -en
|
||||
else
|
||||
echo "Script not enabled!"
|
||||
ccecho -t byellow "Script not enabled!"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
@@ -112,10 +112,15 @@ listitem() {
|
||||
(( index ++ ))
|
||||
enabled=""
|
||||
if [ -f "$enabled_scripts$i" ]; then
|
||||
enabled="-"
|
||||
enabled='-'
|
||||
fi
|
||||
if [ "$enabled" == "-" ]; then
|
||||
printf "%5d | %1s %s\n" "$index" "$( ccecho -t blue -s bold $enabled)" "$( ccecho -t green $inotext)"
|
||||
else
|
||||
printf "%5d | %1s %s\n" "$index" "$enabled" "$( ccecho -t yellow $inotext)"
|
||||
fi
|
||||
printf "%5d | %1s %s\n" "$index" "$enabled" "$inotext"
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -130,22 +135,22 @@ managescript() {
|
||||
# DISABLE WITH NUMBER #
|
||||
if [ "$1" == "--disable" ]; then
|
||||
if [ ! -f "${enabled_scripts}$i" ]; then
|
||||
echo "Script not enabled!"
|
||||
ccecho -t byellow "Script not enabled!"
|
||||
else
|
||||
unlink "${enabled_scripts}$i"
|
||||
inoext=${i:0:-3}
|
||||
echo "[ Scripts $inoext Disabled ]"
|
||||
ccecho -t bmagenta -s bold "[ Scripts $inoext Disabled ]"
|
||||
refresh-brc -dis
|
||||
fi
|
||||
# ENABLE WITH NUMBER #
|
||||
elif [ "$1" == "--enable" ]; then
|
||||
if [ -f "${enabled_scripts}$i" ]; then
|
||||
echo "Script already enabled!"
|
||||
ccecho -t bblue "Script already enabled!"
|
||||
else
|
||||
ln -sf "$available_scripts$i" "${enabled_scripts}$i"
|
||||
inoext=${i:0:-3}
|
||||
echo "------------------------------------"
|
||||
echo "[ Scripts $inoext Enabled ]"
|
||||
ccecho -t bgreen -s bold "[ Scripts $inoext Enabled ]"
|
||||
refresh-brc -en
|
||||
fi
|
||||
|
||||
@@ -201,14 +206,14 @@ managescript() {
|
||||
wasenabled=0
|
||||
if [ -f "$enabled_scripts$i" ]; then
|
||||
unlink "$enabled_scripts$i"
|
||||
echo "[ Temporary Disabled Script ]"
|
||||
ccecho -t byellow "[ Temporary Disabled Script ]"
|
||||
wasenabled=1
|
||||
fi
|
||||
mv "$available_scripts$i" "${available_scripts}$renamenow.sh"
|
||||
echo "[ Script $i renamed to $renamenow.sh ]"
|
||||
ccecho -t blue "[ Script $i renamed to $renamenow.sh ]"
|
||||
if [ "$wasenabled" -eq 1 ]; then
|
||||
ln -sf "${available_scripts}$renamenow.sh" "${enabled_scripts}$renamenow.sh"
|
||||
echo "[ Script Enabled Again ]"
|
||||
ccecho -t bgreen "[ Script Enabled Again ]"
|
||||
fi
|
||||
countloop=1
|
||||
fi
|
||||
@@ -222,11 +227,11 @@ managescript() {
|
||||
fi
|
||||
if [ -f "${enabled_scripts}$i" ]; then
|
||||
unlink "${enabled_scripts}$i"
|
||||
echo "[ Script $i unabled! ]"
|
||||
ccecho -t yellow "[ Script $i unabled! ]"
|
||||
fi
|
||||
removed_data="$i-`date +%F`_`date +%T`"
|
||||
mv "${available_scripts}$i" "${bin_folder}$removed_data"
|
||||
echo "[ Script $i removed! ] "
|
||||
ccecho -t bmagenta "[ Script $i removed! ] "
|
||||
echo "You can find it in the folder: "
|
||||
echo "'$bin_folder' "
|
||||
echo "------------------------------------"
|
||||
@@ -256,13 +261,16 @@ enablescript() {
|
||||
}
|
||||
|
||||
enableallscript() {
|
||||
echo "------------------------------------"
|
||||
echo " Enable All Scripts "
|
||||
echo "------------------------------------"
|
||||
for i in $(ls "$available_scripts"); do
|
||||
ln -sf "$available_scripts$i" "${enabled_scripts}$i"
|
||||
inoext=${i:0:-3}
|
||||
echo "enabled $inoext"
|
||||
echo -n "enabled " && ccecho -t green -s underline "$inoext"
|
||||
done
|
||||
echo "------------------------------------"
|
||||
echo "[ All available scripts enabled ]"
|
||||
ccecho -t bgreen -s bold "[ All available scripts enabled ]"
|
||||
refresh-brc -en
|
||||
}
|
||||
|
||||
@@ -277,14 +285,17 @@ disablescript() {
|
||||
|
||||
|
||||
disableallscript() {
|
||||
echo "------------------------------------"
|
||||
echo " Disable All Enabled Scripts "
|
||||
echo "------------------------------------"
|
||||
# Disabilita tutti gli script
|
||||
for i in $(ls "$enabled_scripts"); do
|
||||
unlink "${enabled_scripts}$i"
|
||||
inoext=${i:0:-3}
|
||||
echo "disabled $inoext"
|
||||
echo -n "disabled " && ccecho -t red -s underline "$inoext"
|
||||
done
|
||||
echo "------------------------------------"
|
||||
echo "[ All Scripts Disabled ]"
|
||||
ccecho -t bmagenta -s bold "[ All Scripts Disabled ]"
|
||||
refresh-brc -dis
|
||||
}
|
||||
|
||||
@@ -351,3 +362,4 @@ brc-script() {
|
||||
echo "-----------------------------"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
51
scripts-needed/ccecho.sh
Normal file
51
scripts-needed/ccecho.sh
Normal file
@@ -0,0 +1,51 @@
|
||||
#!/bin/bash
|
||||
|
||||
ccecho() {
|
||||
local text_color=""
|
||||
local bg_color=""
|
||||
local style=""
|
||||
local msg=""
|
||||
|
||||
# Color and Styles in ANSI code
|
||||
declare -A COLORS=(
|
||||
[black]=30 [red]=31 [green]=32 [yellow]=33 [blue]=34
|
||||
[magenta]=35 [cyan]=36 [white]=37
|
||||
[bblack]=90 [bred]=91 [bgreen]=92 [byellow]=93
|
||||
[bblue]=94 [bmagenta]=95 [bcyan]=96 [bwhite]=97
|
||||
)
|
||||
|
||||
declare -A BGCOLORS=(
|
||||
[black]=40 [red]=41 [green]=42 [yellow]=43 [blue]=44
|
||||
[magenta]=45 [cyan]=46 [white]=47
|
||||
[bblack]=100 [bred]=101 [bgreen]=102 [byellow]=103
|
||||
[bblue]=104 [bmagenta]=105 [bcyan]=106 [bwhite]=107
|
||||
)
|
||||
|
||||
declare -A STYLES=(
|
||||
[bold]=1 [dim]=2 [italic]=3 [underline]=4
|
||||
[blink]=5 [reverse]=7 [hidden]=8 [strike]=9
|
||||
)
|
||||
|
||||
# Parsing options
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-t|--text) text_color=${COLORS[$2]}; shift 2 ;;
|
||||
-b|--bg) bg_color=${BGCOLORS[$2]}; shift 2 ;;
|
||||
-s|--style) style=${STYLES[$2]}; shift 2 ;;
|
||||
*) msg+="$1 "; shift ;;
|
||||
esac
|
||||
done
|
||||
|
||||
local sequence=""
|
||||
[[ -n "$style" ]] && sequence+="${style};"
|
||||
[[ -n "$text_color" ]] && sequence+="${text_color};"
|
||||
[[ -n "$bg_color" ]] && sequence+="${bg_color};"
|
||||
|
||||
if [[ -n "$sequence" ]]; then
|
||||
sequence="${sequence%;}" # remove the last ";"
|
||||
echo -e "\e[${sequence}m${msg}\e[0m"
|
||||
else
|
||||
echo "$msg"
|
||||
fi
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user