Compare commits

...

10 Commits

Author SHA1 Message Date
53aa364139 minor fix 2025-06-17 21:49:51 +01:00
4762d195b7 Add ccecho feature, and modified the main script 2025-06-13 14:02:04 +01:00
Simone Cusano
a736a3ae27 Merge pull request #1 from edneville/menu_padding
Pad menu items and align enable status
2024-12-27 12:56:32 +00:00
ed neville
d1f6dec046 Pad menu items and align enable status
* if the editor quits non-zero ask if action should abort
2024-12-21 22:22:59 +00:00
b1c3dac09b Modified the description. 2024-11-23 18:00:20 +00:00
5b6960643d Removed not needed files. 2024-11-23 17:52:16 +00:00
c350409018 Upadting Installer 2024-11-23 17:21:14 +00:00
c761614013 Updated Description2 2024-10-02 10:02:07 +01:00
875b570148 Updated Description 2024-10-02 10:00:14 +01:00
b06c592037 Updated Description2 2024-10-02 02:24:29 +01:00
8 changed files with 532 additions and 756 deletions

View File

@@ -1,5 +1,6 @@
# Modular Bashrc Manager
### 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,22 +20,20 @@ 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
git clone https://github.com/SimoLinuxDesign/Modular-Bashrc-Manager.git
cd modular-bashrc-manager/installer
```
@@ -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,17 +111,48 @@ 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?

66
README.md.backup Executable file → Normal file
View 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,17 +111,48 @@ 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?

View File

@@ -1,78 +0,0 @@
#!/bin/bash
home="/home/$(whoami)"
bashrc="$home/.bashrc"
mainfolder="$home/.bashrc.d/"
neededfold="${mainfolder}scripts-needed"
avfolder="${mainfolder}scripts-available"
enfolder="${mainfolder}scripts-enabled"
rmfolder="${mainfolder}scripts-removed"
## FUNCTIONS ##
createdir(){
if [ ! -d "$mainfolder" ]; then
mkdir $mainfolder
echo "[ Created $mainfolder ]"
fi
if [ ! -d "$neededfold" ]; then
mkdir $neededfold
echo "[ Created $neededfold ]"
fi
if [ ! -d "$avfolder" ]; then
mkdir $avfolder
echo "[ Created $avfolder ]"
fi
if [ ! -d "$enfolder" ]; then
mkdir $enfolder
echo "[ Created $enfolder ]"
fi
if [ ! -d "$rmfolder" ]; then
mkdir $rmfolder
echo "[ Created $rmfolder ]"
fi
}
modular-bashrc(){
echo 'mkdir -p ~/.bashrc.d/scripts-needed' >> $bashrc
echo 'mkdir -p ~/.bashrc.d/scripts-enabled' >> $bashrc
echo 'mkdir -p ~/.bashrc.d/scripts-available' >> $bashrc
echo 'if [ -d ~/.bashrc.d ]; then' >> $bashrc
echo ' for needed in ~/.bashrc.d/scripts-needed/*.sh; do' >> $bashrc
echo ' [ -r "$needed" ] && source "$needed"' >> $bashrc
echo ' done' >> $bashrc
echo ' unset needed' >> $bashrc
echo ' for file in ~/.bashrc.d/scripts-enabled/*.sh; do' >> $bashrc
echo ' [ -r "$file" ] && source "$file"' >> $bashrc
echo ' done' >> $bashrc
echo ' unset file' >> $bashrc
echo 'fi' >> $bashrc
}
## EXECUTION ##
echo "### Creation Folders ###"
createdir
echo "### Adding brc-script for .bashrc ###"
modular-bashrc
echo [ brc-script installed ]
echo "##################################"
echo " Small Introduction "
echo "##################################"
echo ""
echo "You can handle you script by adding in the $avfolder."
echo "Make sure that all the the script that you are adding are added in a function, otherwise their will be loaded at each open of the bash cli."
echo "You can start to handle all the script by writing the command brc-script, also you can refresh the bash with the command refresh-brc."
echo "You can start to create your own script by use the 'brc-script -c' command"
echo "To enable an available script (after you copied or created one in the scripts-available) by using 'brc-script -e' and the the index command that you need"
echo "You can also modify the existing script by the 'brc-script -m' command."
echo ""
echo "##################################"
echo " Thanks for using this script. "
echo "##################################"
echo " Visit my website www.simolinuxdesign.org to discover more plugin that i created!

View File

@@ -13,4 +13,3 @@ if [ -d ~/.bashrc.d ]; then
unset file
fi

181
installer/brc-script-install.sh Normal file → Executable file
View File

@@ -1,5 +1,101 @@
#!/bin/bash
home="/home/$(whoami)"
clear
user=$(whoami) # Remove the extra space
follow() {
read -p "Press 'Enter' to continue"
}
loop2=0
while [ $loop2 -lt 1 ]; do # Corrected the integer comparison
echo "### brc-script installer ###"
echo "---------------------------------------------"
echo "Do you want to install for the current user ($user)?"
echo "---------------------------------------------"
echo " y - yes"
echo " n - no"
echo " q - exit"
echo " default - yes"
echo "---------------------------------------------"
read choice
if [ "$choice" == "n" ]; then
loop2=1
loop1=0
clear
while [ $loop1 -lt 1 ]; do # Corrected the integer comparison
echo "----------------------------"
echo "List of the available users:"
echo "----------------------------"
for i in $(grep -E ':/home/' /etc/passwd | cut -d: -f1); do echo $i; done
echo "q = exit"
echo "----------------------------"
echo "Type the user:"
read choice2
if [ -d "/home/$choice2" ]; then
user=$choice2
echo "Selected user '$choice2'!"
echo "-------------------"
echo "Can you confirm it?"
echo "-------------------"
echo " y = yes "
echo " n = no "
echo " default = no "
echo "-------------------"
read confirm # Changed 'input' to 'read'
if [ "$confirm" == "y" ]; then
user=$choice2
echo "Using user '$choice2'"
loop1=1
else
echo "Wrong selection, for user '$choice2' "
follow
loop1=0
fi
elif [ "$choice2" == "q" ]; then
echo "Exit from the installer script"
exit 1
else
echo "Home folder for '$choice2' does not exist!"
echo "Try with another one!"
fi
done
elif [ "$choice" == "q" ]; then
echo "[ Exit from the installer script! ]"
exit 1
else
clear
loop3=0
while [ $loop3 -eq 0 ]; do
echo "--------------------------------"
echo "Do you want to use '$user' user?"
echo "--------------------------------"
echo " y = yes"
echo " n = no "
echo "--------------------------------"
read choice3
if [ "$choice3" == "y" ]; then
echo "Selected the current user '$user'"
loop2=1
loop3=1
follow
elif [ "$choice3" == "n" ]; then # Corrected from 'no' to 'n'
echo "Not selected the current user '$user'"
loop3=1
follow
clear
else
echo "Pressed wrong button!"
follow
clear
clear
fi
done
fi
done
#### NEEDED VARIABLES ####
location="$(pwd)/../"
home="/home/$user"
bashrc="$home/.bashrc"
mainfolder="$home/.bashrc.d/"
neededfold="${mainfolder}scripts-needed"
@@ -7,75 +103,34 @@ avfolder="${mainfolder}scripts-available"
enfolder="${mainfolder}scripts-enabled"
rmfolder="${mainfolder}scripts-removed"
## FUNCTIONS ##
createdir(){
if [ ! -d "$mainfolder" ]; then
mkdir $mainfolder
echo "[ Created $mainfolder ]"
fi
if [ ! -d "$neededfold" ]; then
mkdir $neededfold
echo "[ Created $neededfold ]"
fi
if [ ! -d "$avfolder" ]; then
mkdir $avfolder
echo "[ Created $avfolder ]"
fi
if [ ! -d "$enfolder" ]; then
mkdir $enfolder
echo "[ Created $enfolder ]"
fi
if [ ! -d "$rmfolder" ]; then
mkdir $rmfolder
echo "[ Created $rmfolder ]"
fi
}
modular-bashrc(){
echo 'mkdir -p ~/.bashrc.d/scripts-needed' >> $bashrc
echo 'mkdir -p ~/.bashrc.d/scripts-enabled' >> $bashrc
echo 'mkdir -p ~/.bashrc.d/scripts-available' >> $bashrc
echo 'if [ -d ~/.bashrc.d ]; then' >> $bashrc
echo ' for needed in ~/.bashrc.d/scripts-needed/*.sh; do' >> $bashrc
echo ' [ -r "$needed" ] && source "$needed"' >> $bashrc
echo ' done' >> $bashrc
echo ' unset needed' >> $bashrc
echo ' for file in ~/.bashrc.d/scripts-enabled/*.sh; do' >> $bashrc
echo ' [ -r "$file" ] && source "$file"' >> $bashrc
echo ' done' >> $bashrc
echo ' unset file' >> $bashrc
echo 'fi' >> $bashrc
}
copy-brc() {
cp -r brc-script.sh ../scripts-needed/
chmod 750 -R ../scripts-needed/brc-script.sh
}
#### INSTALLATION ####
cp "$bashrc" "bashrc-backup-`date +%F`"
echo "[ Created a backup ]"
cat NEEDED-FOR-INSTALLER >> $bashrc
echo "[ Added info in the .bashrc file ]"
cp -r $location $mainfolder
echo "[ Installed Main Folder ]"
echo $mainfolder
source $bashrc
echo "[ Refreshed bashrc ]"
echo ""
echo "Intallation Completed!"
follow
clear
## EXECUTION ##
echo "### Creation Folders ###"
createdir
echo "### Adding brc-script for .bashrc ###"
modular-bashrc
echo [ brc-script installed ]
echo "##################################"
echo " Small Introduction "
echo "##################################"
echo ""
echo "You can handle you script by adding in the $avfolder."
echo "Make sure that all the the script that you are adding are added in a function, otherwise their will be loaded at each open of the bash cli."
echo "You can start to handle all the script by writing the command brc-script, also you can refresh the bash with the command refresh-brc."
echo "You can start to create your own script by use the 'brc-script -c' command"
echo "To enable an available script (after you copied or created one in the scripts-available) by using 'brc-script -e' and the the index command that you need"
echo "You can also modify the existing script by the 'brc-script -m' command."
echo "You can handle your script by adding them in the $avfolder."
echo "Make sure that all the scripts you add are within a function, otherwise they will be loaded each time you open the bash CLI."
echo "You can start managing scripts by using the command 'brc-script', and refresh bash with 'refresh-brc'."
echo "You can create your own script using 'brc-script -c'."
echo "To enable an available script (after copying or creating one in the scripts-available), use 'brc-script -e' and provide the index."
echo "You can also modify existing scripts using 'brc-script -m'."
echo ""
echo "##################################"
echo " Thanks for using this script. "
echo "##################################"
echo " Visit my website www.simolinuxdesign.org to discover more plugin that i created!
echo "Visit my website www.simolinuxdesign.org to discover more plugins I created!"

View File

@@ -1,338 +0,0 @@
#!/bin/bash
###############
### OPTIONS ###
###############
editor="vim"
#################
### VARIABLES ###
#################
home_folder="$HOME/"
available_scripts="${home_folder}.bashrc.d/scripts-available/"
enabled_scripts="${home_folder}.bashrc.d/scripts-enabled/"
needed_scripts="${home_folder}.bashrc.d/scripts-needed"
bin_folder="${home_folder}.bashrc.d/scripts-removed/"
bashrc="${home_folder}.bashrc"
#################
### FUNCTIONS ###
#################
# 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"
}
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 ###
vim "$newscriptav"
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
}
listitem() {
index=0
for i in $(ls "$available_scripts"); do
inotext=${i:0:-3}
(( index ++ ))
if [ -f "$enabled_scripts$i" ]; then
echo "$index) - $inotext"
else
echo "$index) $inotext"
fi
done
}
managescript() {
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
# 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
# MODIFY WITH NUMBER #
elif [ "$1" == "--modify" ]; then
if [ "$editor" == "vim" ]; then
vim "$available_scripts$i"
elif [ "$editor" == "nano" ]; then
nano "$available_scripts$i"
else
echo "------------"
echo " 1 - nano "
echo " 2 - vim "
echo " def - vim "
echo "------------"
read ched
if [ "$ched" == "1" ]; then
nano "$available_scripts$i"
else
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
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
fi
break
fi
((index2++))
done
}
removescript(){
echo "------------------------------------"
echo " Remove Script "
echo "------------------------------------"
listitem
managescript --remove
}
enablescript() {
echo "------------------------------------"
echo " Enable Scripts "
echo "------------------------------------"
listitem
managescript --enable
}
enableallscript() {
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
}
disablescript() {
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
}
#################
### EXECUTION ###
#################
# Main Script #
brc-script() {
### ENABLE SCRIPTS ###
if [ "$1" == "-e" ]; then
enablescript
### ENABLE ALL SCRIPTS ###
elif [ "$1" == "-ea" ]; then
enableallscript
### DISABLE SCRIPT ###
elif [ "$1" == "-d" ]; then
disablescript
### 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
### 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
}

View File

@@ -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"
@@ -72,6 +72,21 @@ createscript() {
### END NEW SCRIPT ###
vim "$newscriptav"
if [ $? -ne 0 ]; then
echo "------------------------------------"
echo " Editor aborted!"
echo " Continue or remove $namenewscript?"
echo "------------------------------------"
echo " 1 | Continue "
echo " 2 | Abort "
echo " Def | Continue "
echo "------------------------------------"
read answer
if [ "${answer}x" = "2x" ]; then
rm "$newscriptav"
return
fi
fi
echo "------------------------------------"
echo " Script $namenewscript created!"
echo " Do you want to enable it?"
@@ -85,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
}
@@ -95,12 +110,17 @@ listitem() {
for i in $(ls "$available_scripts"); do
inotext=${i:0:-3}
(( index ++ ))
enabled=""
if [ -f "$enabled_scripts$i" ]; then
echo "$index) - $inotext"
enabled='-'
fi
if [ "$enabled" == "-" ]; then
printf "%5d | %1s %s\n" "$index" "$( ccecho -t blue -s bold $enabled)" "$( ccecho -t green $inotext)"
else
echo "$index) $inotext"
printf "%5d | %1s %s\n" "$index" "$enabled" "$( ccecho -t yellow $inotext)"
fi
done
}
@@ -115,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
@@ -186,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
@@ -207,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 "------------------------------------"
@@ -241,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
}
@@ -262,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
}
@@ -336,3 +362,4 @@ brc-script() {
echo "-----------------------------"
fi
}

51
scripts-needed/ccecho.sh Normal file
View 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
}