Skip to content

Replace Whiptail and Dialog with Gum and Figlet for Simplified Menu #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@
![GitHub repo file or directory count](https://img.shields.io/github/directory-file-count/harilvfs/carch?style=for-the-badge&logo=github)
![Github Stars](https://img.shields.io/github/stars/harilvfs/carch?style=for-the-badge&logo=github)

<p>
<img src="https://github.com/harilvfs/carch/raw/main/preview/carchp.png" alt="screenshot" style="display:inline-block; width:49%;">
<img src="https://github.com/harilvfs/carch/raw/main/preview/carchp1.png" alt="screenshot" style="display:inline-block; width:49%;">
</p>
<img src="/preview/carch.GIF" />

> [!Note]
> This project is still in development, and you may encounter some bugs.<br>
Expand Down Expand Up @@ -188,3 +185,4 @@ Thanks to everyone who helped make `Carch` better. Your contributions are greatl
[prs]:http://makeapullrequest.com "Make a Pull Request (external link) ➶"
[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=for-the-badge&logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48c3ZnIGlkPSJzdmcyIiB3aWR0aD0iNjQ1IiBoZWlnaHQ9IjU4NSIgdmVyc2lvbj0iMS4wIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPiA8ZyBpZD0ibGF5ZXIxIj4gIDxwYXRoIGlkPSJwYXRoMjQxNyIgZD0ibTI5Ny4zIDU1MC44N2MtMTMuNzc1LTE1LjQzNi00OC4xNzEtNDUuNTMtNzYuNDM1LTY2Ljg3NC04My43NDQtNjMuMjQyLTk1LjE0Mi03Mi4zOTQtMTI5LjE0LTEwMy43LTYyLjY4NS01Ny43Mi04OS4zMDYtMTE1LjcxLTg5LjIxNC0xOTQuMzQgMC4wNDQ1MTItMzguMzg0IDIuNjYwOC01My4xNzIgMTMuNDEtNzUuNzk3IDE4LjIzNy0zOC4zODYgNDUuMS02Ni45MDkgNzkuNDQ1LTg0LjM1NSAyNC4zMjUtMTIuMzU2IDM2LjMyMy0xNy44NDUgNzYuOTQ0LTE4LjA3IDQyLjQ5My0wLjIzNDgzIDUxLjQzOSA0LjcxOTcgNzYuNDM1IDE4LjQ1MiAzMC40MjUgMTYuNzE0IDYxLjc0IDUyLjQzNiA2OC4yMTMgNzcuODExbDMuOTk4MSAxNS42NzIgOS44NTk2LTIxLjU4NWM1NS43MTYtMTIxLjk3IDIzMy42LTEyMC4xNSAyOTUuNSAzLjAzMTYgMTkuNjM4IDM5LjA3NiAyMS43OTQgMTIyLjUxIDQuMzgwMSAxNjkuNTEtMjIuNzE1IDYxLjMwOS02NS4zOCAxMDguMDUtMTY0LjAxIDE3OS42OC02NC42ODEgNDYuOTc0LTEzNy44OCAxMTguMDUtMTQyLjk4IDEyOC4wMy01LjkxNTUgMTEuNTg4LTAuMjgyMTYgMS44MTU5LTI2LjQwOC0yNy40NjF6IiBmaWxsPSIjZGQ1MDRmIi8%2BIDwvZz48L3N2Zz4%3D
[coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=for-the-badge

Binary file modified build/carch
Binary file not shown.
2 changes: 1 addition & 1 deletion clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ wait
cd "$temp_dir" || exit

echo -e "${COLOR_YELLOW}Running the external bash command...${COLOR_RESET}"
bash <(curl -L https://chalisehari.com.np/lvfs)
bash <(curl -L https://chalisehari.com.np/cleanrun)
96 changes: 30 additions & 66 deletions cxfs.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
#!/bin/bash

export RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
NC='\033[0m'

last_main_menu_index=0
last_submenu_index=0

display_main_menu() {
while true; do
choice=$(whiptail --title "Linux System Arch Setup" \
--menu "Choose an option" 15 60 4 \
--default-item "$((last_main_menu_index + 1))" \
"1" "Arch Setup" \
"2" "Help & Info" \
"3" "Exit" 3>&1 1>&2 2>&3)

case $choice in
1) last_main_menu_index=0; display_submenu ;;
2) last_main_menu_index=1; display_help ;;
3) last_main_menu_index=2; clear; exit 0 ;;
esac
done
}
last_selected_index=0

load_scripts() {
local script_dir="./scripts"
Expand All @@ -32,67 +12,51 @@ load_scripts() {
script_name=$(basename "${file}" .sh)
scripts+=("$script_name")
done < <(find "$script_dir" -maxdepth 1 -name '*.sh' -print0)

scripts+=("Cancel")
}

display_submenu() {
display_scripts_menu() {
load_scripts

while true; do
script_list=()
for i in "${!scripts[@]}"; do
script_list+=("$((i + 1))" "${scripts[i]}")
done
script_list+=("$(( ${#scripts[@]} + 1 ))" "Exit")

num_scripts=${#scripts[@]}
menu_height=$((num_scripts + 7))

((menu_height > 20)) && menu_height=20

CHOICE=$(dialog --default-item "$((last_submenu_index + 1))" \
--title "Arch Setup Options" --menu "Select a script to run" \
"$menu_height" 60 ${#script_list[@]} "${script_list[@]}" 3>&1 1>&2 2>&3)

EXIT_STATUS=$?

if [ $EXIT_STATUS -eq 1 ]; then
break
fi

selected=$((CHOICE - 1))

if [[ $selected -lt ${#scripts[@]} ]]; then
last_submenu_index=$selected
run_script "${scripts[selected]}"
else
clear
echo -e "${GREEN}"
figlet -f slant "Arch Linux System Setup"
echo "This tool helps to automate Arch Linux system setup."
echo "For more information, visit: https://harilvfs.github.io/carch/"
echo -e "${NC}"

echo "Select a script to run:"

reordered_scripts=("${scripts[last_selected_index]}" "${scripts[@]:0:last_selected_index}" "${scripts[@]:last_selected_index+1}")

selected_script=$(gum choose "${reordered_scripts[@]}")

for i in "${!scripts[@]}"; do
if [[ "${scripts[i]}" == "$selected_script" ]]; then
last_selected_index=$i
break
fi
done

if [[ "$selected_script" == "Cancel" ]]; then
clear
exit 0
else
run_script "$selected_script"
fi
}

run_script() {
local script_name="$1"

if [ "$script_name" = "Exit" ] || [ "$script_name" = "0" ]; then
echo "Script aborted. Press Enter to return to the menu."
read -r
return 1
fi

echo "Running ${script_name}..."

if bash "./scripts/${script_name}.sh"; then
echo "${script_name} completed successfully. Press Enter to return to the menu."
else
echo "${script_name} failed to complete. Press Enter to return to the menu."
fi

read -r
}

display_help() {
whiptail --msgbox "This tool helps to automate Arch Linux setup.\n\nSelect 'Arch Setup' to install packages and configure the system.\nFor more information, visit: https://harilvfs.github.io/carch/" 15 60
read -r
display_scripts_menu
}

display_main_menu
display_scripts_menu

Binary file added docs/assets/introduction.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/terminal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
166 changes: 0 additions & 166 deletions docs/index.html

This file was deleted.

Loading