Fixed Modify option | Added data to the removed scripts

This commit is contained in:
2024-10-01 23:34:06 +01:00
parent 20ae8f2e15
commit 0cbb943e5b
2 changed files with 148 additions and 49 deletions

53
brc-script-install.sh Normal file
View File

@@ -0,0 +1,53 @@
#!/bin/bash
mainfolder="/home/$(whoami)/.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 "$mainfolder" ]; then
mkdir $mainfolder
echo "[ Created $mainfolder ]"
fi
if [ ! -d "$mainfolder" ]; then
mkdir $mainfolder
echo "[ Created $mainfolder ]"
fi
}
# Modular Bashrc
mkdir -p ~/.bashrc.d/scripts-needed
mkdir -p ~/.bashrc.d/scripts-enabled
mkdir -p ~/.bashrc.d/scripts-available
if [ -d ~/.bashrc.d ]; then
for needed in ~/.bashrc.d/scripts-needed/*.sh; do
[ -r "$needed" ] && source "$needed"
done
unset needed
for file in ~/.bashrc.d/scripts-enabled/*.sh; do
[ -r "$file" ] && source "$file"
done
unset file
fi

View File

@@ -8,11 +8,12 @@ editor="vim"
################# #################
### VARIABLES ### ### VARIABLES ###
################# #################
available_scripts="/home/$(whoami)/.bashrc.d/scripts-available/" home_folder="$HOME/"
enabled_scripts="/home/$(whoami)/.bashrc.d/scripts-enabled/" available_scripts="${home_folder}.bashrc.d/scripts-available/"
needed_scripts="/home/$(whoami)/.bashrc.d/scripts-needed" enabled_scripts="${home_folder}.bashrc.d/scripts-enabled/"
bin_folder="/home/$(whoami)/.bashrc.d/scripts-removed/" needed_scripts="${home_folder}.bashrc.d/scripts-needed"
bashrc="/home/$(whoami)/.bashrc" bin_folder="${home_folder}.bashrc.d/scripts-removed/"
bashrc="${home_folder}.bashrc"
################# #################
### FUNCTIONS ### ### FUNCTIONS ###
@@ -21,24 +22,27 @@ bashrc="/home/$(whoami)/.bashrc"
# Refresh Bash # # Refresh Bash #
refresh-brc(){ refresh-brc(){
if [ "$1" == "-dis" ]; then if [ "$1" == "-dis" ]; then
echo "------------------------------------"
echo "[ Bashrc Refreshed ]" echo "[ Bashrc Refreshed ]"
echo "You can't use the old commands from now!" echo "You can't use the old commands from now!"
echo "------------------------" echo "------------------------------------"
elif [ "$1" == "-en" ]; then elif [ "$1" == "-en" ]; then
echo "------------------------------------"
echo "[ Bashrc Refreshed ]" echo "[ Bashrc Refreshed ]"
echo "------------------------------------"
echo "You can you the new commands from now!" echo "You can you the new commands from now!"
echo "-----------------------" echo "------------------------------------"
else else
echo "[ Bashrc Refreshed ]" echo "[ Bashrc Refreshed ]"
fi fi
source $bashrc source "$bashrc"
} }
createscript() { createscript() {
echo "-----------------------" echo "------------------------------------"
echo " Creation New Scripts: " echo " Creation New Scripts: "
echo "-----------------------" echo "------------------------------------"
echo "Name of the script: " echo "Name of the script: "
read namenewscript read namenewscript
if [ -f "${available_scripts}$namenewscript" ]; then if [ -f "${available_scripts}$namenewscript" ]; then
@@ -68,15 +72,14 @@ createscript() {
### END NEW SCRIPT ### ### END NEW SCRIPT ###
vim "$newscriptav" vim "$newscriptav"
echo "------------------------------------"
echo "------------------------------" echo " Script $namenewscript created!"
echo "Script $namenewscript created!" echo " Do you want to enable it?"
echo " Do you want to enable it?" echo "------------------------------------"
echo "------------------------------" echo " 1 | yes "
echo " 1 | yes " echo " 2 | no "
echo " 2 | no " echo " Def | no "
echo " Def | no " echo "------------------------------------"
echo "------------------------------"
read answer read answer
if [ "$answer" -eq 1 ]; then if [ "$answer" -eq 1 ]; then
ln -sf "$newscriptav" "${enabled_scripts}$namenewscript.sh" ln -sf "$newscriptav" "${enabled_scripts}$namenewscript.sh"
@@ -102,9 +105,9 @@ listitem() {
managescript() { managescript() {
echo "---------------------" echo "------------------------------------"
echo " Select the index: " echo " Select the index: "
echo "---------------------" echo "------------------------------------"
read manageindex read manageindex
index2=1 index2=1
for i in $(ls "$available_scripts"); do for i in $(ls "$available_scripts"); do
@@ -126,7 +129,7 @@ managescript() {
else else
ln -sf "$available_scripts$i" "${enabled_scripts}$i" ln -sf "$available_scripts$i" "${enabled_scripts}$i"
inoext=${i:0:-3} inoext=${i:0:-3}
echo "-----------------------" echo "------------------------------------"
echo "[ Scripts $inoext Enabled ]" echo "[ Scripts $inoext Enabled ]"
refresh-brc -en refresh-brc -en
fi fi
@@ -150,6 +153,52 @@ managescript() {
vim "$available_scripts$i" vim "$available_scripts$i"
fi fi
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 refresh-brc -en
# REMOVE SCRIPT # # REMOVE SCRIPT #
elif [ "$1" == "--remove" ]; then elif [ "$1" == "--remove" ]; then
@@ -160,11 +209,12 @@ managescript() {
unlink "${enabled_scripts}$i" unlink "${enabled_scripts}$i"
echo "[ Script $i unabled! ]" echo "[ Script $i unabled! ]"
fi fi
mv "${available_scripts}$i" $bin_folder removed_data="$i-`date +%F`_`date +%T`"
mv "${available_scripts}$i" "${bin_folder}$removed_data"
echo "[ Script $i removed! ] " echo "[ Script $i removed! ] "
echo "You can find it in the folder: " echo "You can find it in the folder: "
echo "'$bin_folder' " echo "'$bin_folder' "
echo "--------------------------------" echo "------------------------------------"
refresh-brc refresh-brc
fi fi
@@ -175,17 +225,17 @@ managescript() {
} }
removescript(){ removescript(){
echo "-----------------------" echo "------------------------------------"
echo " Remove Script " echo " Remove Script "
echo "-----------------------" echo "------------------------------------"
listitem listitem
managescript --remove managescript --remove
} }
enablescript() { enablescript() {
echo "-----------------------" echo "------------------------------------"
echo " Enable Scripts " echo " Enable Scripts "
echo "-----------------------" echo "------------------------------------"
listitem listitem
managescript --enable managescript --enable
} }
@@ -196,16 +246,16 @@ enableallscript() {
inoext=${i:0:-3} inoext=${i:0:-3}
echo "enabled $inoext" echo "enabled $inoext"
done done
echo "-----------------------" echo "------------------------------------"
echo "[ All available scripts enabled ]" echo "[ All available scripts enabled ]"
refresh-brc -en refresh-brc -en
} }
disablescript() { disablescript() {
echo "-----------------------" echo "------------------------------------"
echo " Disable Scripts " echo " Disable Scripts "
echo "-----------------------" echo "------------------------------------"
listitem listitem
managescript --disable managescript --disable
} }
@@ -218,7 +268,7 @@ disableallscript() {
inoext=${i:0:-3} inoext=${i:0:-3}
echo "disabled $inoext" echo "disabled $inoext"
done done
echo "------------------------" echo "------------------------------------"
echo "[ All Scripts Disabled ]" echo "[ All Scripts Disabled ]"
refresh-brc -dis refresh-brc -dis
} }
@@ -247,23 +297,19 @@ brc-script() {
### SCRIPTS LIST ### ### SCRIPTS LIST ###
elif [ "$1" == "-l" ]; then elif [ "$1" == "-l" ]; then
echo "-----------------------------" echo "------------------------------------"
echo " Scripts List " echo " Scripts List "
echo "-----------------------------" echo "------------------------------------"
listitem listitem
echo "-----------------------------" echo "------------------------------------"
echo " The script preceded by the" echo " The script preceded by the"
echo " '-' character is active. " echo " '-' character is active. "
echo "-----------------------------" echo "------------------------------------"
### MODIFY SCRIPTS ### ### MODIFY SCRIPTS ###
elif [ "$1" == "-m" ]; then elif [ "$1" == "-m" ]; then
echo "###### MODIFY SCRIPTS #######" echo "###### MODIFY SCRIPTS #######"
listitem listitem
echo "-----------------------------"
echo " Type the name of the script "
echo " you need to modify: "
echo "-----------------------------"
managescript --modify managescript --modify
### CREATE NEW SCRIPT ### ### CREATE NEW SCRIPT ###
@@ -276,7 +322,7 @@ brc-script() {
### COMMAND LISTS ### ### COMMAND LISTS ###
else else
echo "-----------------------------" echo "-----------------------------"
echo " List of brc-scripts command " echo " List of brc-scripts command "
echo "-----------------------------" echo "-----------------------------"
echo " -c | Create New Script " echo " -c | Create New Script "