Skip to content

Commit

Permalink
Feat/dbn 7 sub menues (#21)
Browse files Browse the repository at this point in the history
* --system flag for menu

* documentation
  • Loading branch information
jd-apprentice authored Feb 2, 2023
1 parent 5557cea commit e806bb4
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 46 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.swp
error.log
notes.txt
.notes.txt.swp
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
- 🗑️ Empty the recycle bin to permanently delete files.
- 🌧️ Check weather for you current location.
- 🧹 Uninstall programs you no longer need.
- 💵 Check local rate for USD-ARS.
- 🔍 Search for a specific file.
- 🍎 Download youtube videos.
- 🕰️ Check the system uptime.
- 🔒 Check open ports.

Expand All @@ -34,6 +36,7 @@
## 🏳️ Flags

- `--help`: 📜 Display a help message with a list of all available options.
- `--system || --sys`: 🖥 Filters the menu to only show system utility options.
- `--esp`: 🇪🇸 Enable Spanish translation.

## 📁 Folder structure
Expand Down
33 changes: 8 additions & 25 deletions usr/bin/dbn-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,17 @@ args=()
prompt="Enter an option: "

# Source functions
for file in $(find /usr/bin/ -name '*.sh'); do
if [[ $file == *"functions"* ]]; then
source "$file"
elif [[ $file == *"constants"* ]]; then
source "$file"
fi
done


# Iterate over all the arguments
for arg in "$@"; do
if [[ $arg == "--help" ]]; then
source /usr/bin/constants/help.sh # Look for a way to not source this file again
for description in "${descriptions[@]}"; do
echo "$description"
done
exit
for file in $(find usr/bin/ -name '*.sh'); do
if [[ $file == *"functions"* ]]; then
source "$file"
elif [[ $file == *"constants"* ]]; then
source "$file"
fi

if [[ $arg == "--esp" ]]; then
language="esp"
continue
fi

# Otherwise, store the argument in the array
args+=("$arg")
done

# Read and build the menu
ReadArguments "$@"

# Display the menu options
DisplayMenuOptions

Expand Down
20 changes: 6 additions & 14 deletions usr/bin/functions/display-menu-options.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,20 @@
function random_color() {
color=$((RANDOM % 6 + 1))
case $color in
1) echo -ne "\e[31m" ;; # red
2) echo -ne "\e[32m" ;; # green
3) echo -ne "\e[33m" ;; # yellow
4) echo -ne "\e[34m" ;; # blue
5) echo -ne "\e[35m" ;; # purple
6) echo -ne "\e[36m" ;; # cyan
1) echo -ne "\e[31m" ;; # red
2) echo -ne "\e[32m" ;; # green
3) echo -ne "\e[33m" ;; # yellow
4) echo -ne "\e[34m" ;; # blue
5) echo -ne "\e[35m" ;; # purple
6) echo -ne "\e[36m" ;; # cyan
esac
}


# Display the menu options
function DisplayMenuOptions() {

source /usr/bin/constants/ascii.sh

# Check if the language is Spanish
if [[ $language == "esp" ]]; then
prompt="Ingrese una opción: "
menu_options=("${menu_options_spanish[@]}")
fi

echo "$menu_top"
echo "$menu_separator"

Expand All @@ -33,7 +26,6 @@ function DisplayMenuOptions() {
echo -e "$color ${menu_options[$i]} \e[0m"
done


}

export -f DisplayMenuOptions
48 changes: 48 additions & 0 deletions usr/bin/functions/read-arguments.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!bin/bash

function ReadArguments() {
# Python functions (soon to be moved out)
UsdArs="/usr/bin/functions/usd-ars.py"

# Base options when no arguments is passed
options=(DiskUsage DeleteTemporary EmptyRecycleBin UninstallPackage SystemInfo MemoryUsage Uptime OpenPorts GetWeather DownloadVideo FindFile $UsdArs exit)

local arguments="$1"
for arg in "$arguments"; do
if [[ $arg == "--help" ]]; then
source /usr/bin/constants/help.sh # Look for a way to not source this file again
for description in "${descriptions[@]}"; do
echo "$description"
done
exit
fi

# Check if the language is Spanish
if [[ $arg == "--esp" ]]; then
language="esp"
prompt="Ingrese una opción: "
menu_options=("${menu_options_spanish[@]}")
continue
fi

# Menu choice for the system utilities
if [[ $arg == "--system" || $arg == "--sys" ]]; then
options=(DiskUsage SystemInfo UninstallPackage Uptime OpenPorts MemoryUsage exit)
menu_options=(
"1) Analyze disk usage"
"2) System information"
"3) Uninstall a package"
"4) System uptime"
"5) Open ports"
"6) Memory usage"
"7) Exit"
)
continue
fi

# Otherwise, store the argument in the array
args+=("$arg")
done
}

export -f ReadArguments
8 changes: 1 addition & 7 deletions usr/bin/functions/read-prompt.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
#!bin/bash

# Python functions
UsdArs="/usr/bin/functions/usd-ars.py"

function ReadPrompt() {
# Order is based on usr/bin/constants/menu.sh file, if you are going to edit something from here, edit it there too
options=(DiskUsage DeleteTemporary EmptyRecycleBin UninstallPackage SystemInfo MemoryUsage Uptime OpenPorts GetWeather DownloadVideo FindFile $UsdArs exit)

# Read the user's option
read -p "$prompt" option

# Perform the action corresponding to the chosen option
if [[ $option -le ${#options[@]} && $option -gt 0 ]]; then
${options[$option-1]}
${options[$option - 1]}
else
echo "Invalid option"
fi
Expand Down

0 comments on commit e806bb4

Please sign in to comment.