diff --git a/README.md b/README.md index 765778b..e15a7b9 100644 --- a/README.md +++ b/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. diff --git a/README.md.backup b/README.md.backup old mode 100755 new mode 100644 index cf5c7b1..e15a7b9 --- a/README.md.backup +++ b/README.md.backup @@ -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 ` : Enable a script from the `scripts-available/` folder. -- `-d ` : Disable an enabled script. -- `-r ` : 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 + brc-script -e ``` - Disable a script: ```bash - brc-script -d + brc-script -d ``` - Remove a script: ```bash - brc-script -r + 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. diff --git a/installer/NEEDED-FOR-INSTALLER b/installer/NEEDED-FOR-INSTALLER index 5789e9a..b668d59 100644 --- a/installer/NEEDED-FOR-INSTALLER +++ b/installer/NEEDED-FOR-INSTALLER @@ -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 diff --git a/scripts-needed/brc-script.sh b/scripts-needed/brc-script.sh index 264caf7..d9e3a8f 100755 --- a/scripts-needed/brc-script.sh +++ b/scripts-needed/brc-script.sh @@ -21,57 +21,57 @@ bashrc="${home_folder}.bashrc" # Refresh Bash # refresh-brc(){ - if [ "$1" == "-dis" ]; then - echo "------------------------------------" - echo "[ Bashrc Refreshed ]" - echo "You can't use the old commands from now!" - echo "------------------------------------" - elif [ "$1" == "-en" ]; then - echo "------------------------------------" - echo "[ Bashrc Refreshed ]" - echo "------------------------------------" - echo "You can you the new commands from now!" - echo "------------------------------------" - else - echo "[ Bashrc Refreshed ]" - fi - source "$bashrc" + if [ "$1" == "-dis" ]; then + echo "------------------------------------" + ccecho -t bblue "[ Bashrc Refreshed ]" + echo "You can't use the old commands from now!" + echo "------------------------------------" + elif [ "$1" == "-en" ]; then + echo "------------------------------------" + ccecho -t bblue "[ Bashrc Refreshed ]" + echo "------------------------------------" + ccecho -t bgreen -s bold "You can you the new commands from now!" + echo "------------------------------------" + else + ccecho -t bblue "[ Bashrc Refreshed ]" + fi + source "$bashrc" } createscript() { - echo "------------------------------------" - echo " Creation New Scripts: " - echo "------------------------------------" - echo "Name of the script: " - read namenewscript - if [ -f "${available_scripts}$namenewscript" ]; then - echo "Script already exists!" - else - newscriptav="${available_scripts}$namenewscript.sh" - - ### INITIALIZZATION NEW SCRIPT ### - touch $newscriptav - echo "#!/bin/bash" >> $newscriptav - echo "" >> $newscriptav - echo "### OPTIONS ###" >> $newscriptav - echo "" >> $newscriptav - echo "" >> $newscriptav - echo "### VARIABLES ###" >> $newscriptav - echo "" >> $newscriptav - echo "" >> $newscriptav - echo "### FUNCTIONS ###" >> $newscriptav - echo "${namenewscript}() {" >> $newscriptav - echo "# Add your code here!" >> $newscriptav - echo 'echo "This is the new script"' >> $newscriptav - echo "}" >> $newscriptav - echo "" >> $newscriptav - echo "### EXECUTE ###" >> $newscriptav - echo "" >> $newscriptav - echo "" >> $newscriptav - ### END NEW SCRIPT ### + echo "------------------------------------" + echo " Creation New Scripts: " + echo "------------------------------------" + echo "Name of the script: " + read namenewscript + if [ -f "${available_scripts}$namenewscript" ]; then + ccecho -t byellow "Script already exists!" + else + newscriptav="${available_scripts}$namenewscript.sh" - vim "$newscriptav" + ### INITIALIZZATION NEW SCRIPT ### + touch $newscriptav + echo "#!/bin/bash" >> $newscriptav + echo "" >> $newscriptav + echo "### OPTIONS ###" >> $newscriptav + echo "" >> $newscriptav + echo "" >> $newscriptav + echo "### VARIABLES ###" >> $newscriptav + echo "" >> $newscriptav + echo "" >> $newscriptav + echo "### FUNCTIONS ###" >> $newscriptav + echo "${namenewscript}() {" >> $newscriptav + echo "# Add your code here!" >> $newscriptav + echo 'echo "This is the new script"' >> $newscriptav + echo "}" >> $newscriptav + echo "" >> $newscriptav + echo "### EXECUTE ###" >> $newscriptav + echo "" >> $newscriptav + echo "" >> $newscriptav + ### END NEW SCRIPT ### + + vim "$newscriptav" if [ $? -ne 0 ]; then echo "------------------------------------" echo " Editor aborted!" @@ -87,67 +87,72 @@ createscript() { return fi fi - echo "------------------------------------" - echo " Script $namenewscript created!" - echo " Do you want to enable it?" - echo "------------------------------------" - echo " 1 | yes " - echo " 2 | no " - echo " Def | no " - echo "------------------------------------" - read answer - if [ "$answer" -eq 1 ]; then - ln -sf "$newscriptav" "${enabled_scripts}$namenewscript.sh" - refresh-brc -en - else - echo "Script not enabled!" - fi - fi + echo "------------------------------------" + echo " Script $namenewscript created!" + echo " Do you want to enable it?" + echo "------------------------------------" + echo " 1 | yes " + echo " 2 | no " + echo " Def | no " + echo "------------------------------------" + read answer + if [ "$answer" -eq 1 ]; then + ln -sf "$newscriptav" "${enabled_scripts}$namenewscript.sh" + refresh-brc -en + else + ccecho -t byellow "Script not enabled!" + fi + fi } listitem() { - index=0 - for i in $(ls "$available_scripts"); do - inotext=${i:0:-3} - (( index ++ )) + index=0 + for i in $(ls "$available_scripts"); do + inotext=${i:0:-3} + (( index ++ )) enabled="" - if [ -f "$enabled_scripts$i" ]; then - enabled="-" - fi - printf "%5d | %1s %s\n" "$index" "$enabled" "$inotext" + if [ -f "$enabled_scripts$i" ]; then + 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 done + } managescript() { - echo "------------------------------------" - echo " Select the index: " - echo "------------------------------------" + echo "------------------------------------" + echo " Select the index: " + echo "------------------------------------" read manageindex index2=1 for i in $(ls "$available_scripts"); do if [ "$manageindex" == "$index2" ]; then # DISABLE WITH NUMBER # if [ "$1" == "--disable" ]; then - if [ ! -f "${enabled_scripts}$i" ]; then - echo "Script not enabled!" - else - unlink "${enabled_scripts}$i" - inoext=${i:0:-3} - echo "[ Scripts $inoext Disabled ]" - refresh-brc -dis - fi + if [ ! -f "${enabled_scripts}$i" ]; then + ccecho -t byellow "Script not enabled!" + else + unlink "${enabled_scripts}$i" + inoext=${i:0:-3} + 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!" - else - ln -sf "$available_scripts$i" "${enabled_scripts}$i" - inoext=${i:0:-3} - echo "------------------------------------" - echo "[ Scripts $inoext Enabled ]" - refresh-brc -en - fi + if [ -f "${enabled_scripts}$i" ]; then + ccecho -t bblue "Script already enabled!" + else + ln -sf "$available_scripts$i" "${enabled_scripts}$i" + inoext=${i:0:-3} + echo "------------------------------------" + ccecho -t bgreen -s bold "[ Scripts $inoext Enabled ]" + refresh-brc -en + fi # MODIFY WITH NUMBER # elif [ "$1" == "--modify" ]; then @@ -168,71 +173,71 @@ managescript() { vim "$available_scripts$i" fi fi - clear - echo "------------------------------------" - echo "Would you like to rename the script?" - echo "------------------------------------" - echo " 1 | yes " - echo " 2 | no " - echo " default | no " - echo "------------------------------------" - read renscr - if [ $renscr == "1" ]; then - clear - countloop=0 - while [ $countloop -lt 1 ]; do - echo "------------------------------------" - echo "Insert new name:" - read renamenow - echo "------------------------------------" - echo "Is the name correct? " - echo "------------------------------------" - echo " 1 | no " - echo " 0 | yes " - echo " default | yes " - echo "------------------------------------" - read confirm - if [ "$confirm" == "1" ]; then - countloop=0 - clear - echo "------------------------------------" - echo "Rename again the file:" - else - wasenabled=0 - if [ -f "$enabled_scripts$i" ]; then - unlink "$enabled_scripts$i" - echo "[ Temporary Disabled Script ]" - wasenabled=1 - fi - mv "$available_scripts$i" "${available_scripts}$renamenow.sh" - echo "[ 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 ]" - fi - countloop=1 - fi - done - fi + clear + echo "------------------------------------" + echo "Would you like to rename the script?" + echo "------------------------------------" + echo " 1 | yes " + echo " 2 | no " + echo " default | no " + echo "------------------------------------" + read renscr + if [ $renscr == "1" ]; then + clear + countloop=0 + while [ $countloop -lt 1 ]; do + echo "------------------------------------" + echo "Insert new name:" + read renamenow + echo "------------------------------------" + echo "Is the name correct? " + echo "------------------------------------" + echo " 1 | no " + echo " 0 | yes " + echo " default | yes " + echo "------------------------------------" + read confirm + if [ "$confirm" == "1" ]; then + countloop=0 + clear + echo "------------------------------------" + echo "Rename again the file:" + else + wasenabled=0 + if [ -f "$enabled_scripts$i" ]; then + unlink "$enabled_scripts$i" + ccecho -t byellow "[ Temporary Disabled Script ]" + wasenabled=1 + fi + mv "$available_scripts$i" "${available_scripts}$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" + ccecho -t bgreen "[ Script Enabled Again ]" + fi + countloop=1 + fi + done + fi refresh-brc -en - # REMOVE SCRIPT # - elif [ "$1" == "--remove" ]; then - if [ ! -d "$bin_folder" ]; then - mkdir $bin_folder - fi - if [ -f "${enabled_scripts}$i" ]; then - unlink "${enabled_scripts}$i" - echo "[ Script $i unabled! ]" - fi - removed_data="$i-`date +%F`_`date +%T`" - mv "${available_scripts}$i" "${bin_folder}$removed_data" - echo "[ Script $i removed! ] " - echo "You can find it in the folder: " - echo "'$bin_folder' " - echo "------------------------------------" - refresh-brc + # REMOVE SCRIPT # + elif [ "$1" == "--remove" ]; then + if [ ! -d "$bin_folder" ]; then + mkdir $bin_folder + fi + if [ -f "${enabled_scripts}$i" ]; then + unlink "${enabled_scripts}$i" + ccecho -t yellow "[ Script $i unabled! ]" + fi + removed_data="$i-`date +%F`_`date +%T`" + mv "${available_scripts}$i" "${bin_folder}$removed_data" + ccecho -t bmagenta "[ Script $i removed! ] " + echo "You can find it in the folder: " + echo "'$bin_folder' " + echo "------------------------------------" + refresh-brc fi - + break fi ((index2++)) @@ -240,52 +245,58 @@ managescript() { } removescript(){ - echo "------------------------------------" - echo " Remove Script " - echo "------------------------------------" - listitem - managescript --remove -} + echo "------------------------------------" + echo " Remove Script " + echo "------------------------------------" + listitem + managescript --remove +} enablescript() { - echo "------------------------------------" - echo " Enable Scripts " - echo "------------------------------------" - listitem - managescript --enable + echo "------------------------------------" + echo " Enable Scripts " + echo "------------------------------------" + listitem + managescript --enable } enableallscript() { - for i in $(ls "$available_scripts"); do - ln -sf "$available_scripts$i" "${enabled_scripts}$i" + 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" - done - echo "------------------------------------" - echo "[ All available scripts enabled ]" - refresh-brc -en + echo -n "enabled " && ccecho -t green -s underline "$inoext" + done + echo "------------------------------------" + ccecho -t bgreen -s bold "[ All available scripts enabled ]" + refresh-brc -en } disablescript() { - echo "------------------------------------" - echo " Disable Scripts " - echo "------------------------------------" - listitem - managescript --disable + echo "------------------------------------" + echo " Disable Scripts " + echo "------------------------------------" + listitem + managescript --disable } disableallscript() { - # Disabilita tutti gli script - for i in $(ls "$enabled_scripts"); do - unlink "${enabled_scripts}$i" - inoext=${i:0:-3} - echo "disabled $inoext" - done - echo "------------------------------------" - echo "[ All Scripts Disabled ]" - refresh-brc -dis + 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 -n "disabled " && ccecho -t red -s underline "$inoext" + done + echo "------------------------------------" + ccecho -t bmagenta -s bold "[ All Scripts Disabled ]" + refresh-brc -dis } ################# @@ -294,60 +305,61 @@ disableallscript() { # Main Script # brc-script() { - ### ENABLE SCRIPTS ### - if [ "$1" == "-e" ]; then - enablescript + ### ENABLE SCRIPTS ### + if [ "$1" == "-e" ]; then + enablescript - ### ENABLE ALL SCRIPTS ### - elif [ "$1" == "-ea" ]; then - enableallscript + ### ENABLE ALL SCRIPTS ### + elif [ "$1" == "-ea" ]; then + enableallscript - ### DISABLE SCRIPT ### - elif [ "$1" == "-d" ]; then - disablescript + ### DISABLE SCRIPT ### + elif [ "$1" == "-d" ]; then + disablescript - ### DISABLE ALL SCRIPTS ### - elif [ "$1" == "-da" ]; then - disableallscript + ### DISABLE ALL SCRIPTS ### + elif [ "$1" == "-da" ]; then + disableallscript - ### SCRIPTS LIST ### - elif [ "$1" == "-l" ]; then - echo "------------------------------------" - echo " Scripts List " - echo "------------------------------------" - listitem - echo "------------------------------------" - echo " The script preceded by the" - echo " '-' character is active. " - echo "------------------------------------" - - ### MODIFY SCRIPTS ### - elif [ "$1" == "-m" ]; then - echo "###### MODIFY SCRIPTS #######" - listitem - managescript --modify - - ### CREATE NEW SCRIPT ### - elif [ "$1" == "-c" ]; then - createscript - - ### REMOVE SCRIPT ### - elif [ "$1" == "-r" ]; then - removescript + ### SCRIPTS LIST ### + elif [ "$1" == "-l" ]; then + echo "------------------------------------" + echo " Scripts List " + echo "------------------------------------" + listitem + echo "------------------------------------" + echo " The script preceded by the" + echo " '-' character is active. " + echo "------------------------------------" - ### COMMAND LISTS ### - else - echo "-----------------------------" - echo " List of brc-scripts command " - echo "-----------------------------" - echo " -c | Create New Script " - echo " -m | Modify Script " - echo " -l | Scripts List " - echo " -e | Enable Scripts " - echo " -d | Disable Scripts " - echo " -da | Disable All Scripts " - echo " -ea | Enable All Scripts " - echo " -r | Remove Script " - echo "-----------------------------" - fi + ### MODIFY SCRIPTS ### + elif [ "$1" == "-m" ]; then + echo "###### MODIFY SCRIPTS #######" + listitem + managescript --modify + + ### CREATE NEW SCRIPT ### + elif [ "$1" == "-c" ]; then + createscript + + ### REMOVE SCRIPT ### + elif [ "$1" == "-r" ]; then + removescript + + ### COMMAND LISTS ### + else + echo "-----------------------------" + echo " List of brc-scripts command " + echo "-----------------------------" + echo " -c | Create New Script " + echo " -m | Modify Script " + echo " -l | Scripts List " + echo " -e | Enable Scripts " + echo " -d | Disable Scripts " + echo " -da | Disable All Scripts " + echo " -ea | Enable All Scripts " + echo " -r | Remove Script " + echo "-----------------------------" + fi } + diff --git a/scripts-needed/ccecho.sh b/scripts-needed/ccecho.sh new file mode 100644 index 0000000..a66a470 --- /dev/null +++ b/scripts-needed/ccecho.sh @@ -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 +} +