only kink is, that it doesnt have going back on the keyboard input as your used to, but its a small thing, annoying, but small bug, needs a folder and file

[root@sharyng SHARE]# cat share  
#!/bin/bash

spleens_folder="./spleens"
streams_file="./Streams"

display_spleens() {
	echo "You can add spleens in the /spleens folder."
    echo "Spleens available:"
	echo
    ls "$spleens_folder"
}

assemble_command() {
    echo
    echo "Available tools (spleens):"
    ls "$spleens_folder"
    echo
    echo "Hint: Assemble your command using pipes. Example: cat spleen1 | grep 'pattern'"
    read -p "Enter your command: " user_command
    echo "You entered: $user_command"
    echo

    read -p "Do you want to save this command to Streams? (y/n): " save_choice
    if [[ "$save_choice" == "y" ]]; then
        echo "$user_command" >> "$streams_file"
        echo "Command saved."

        read -p "Do you want to execute this command now? (y/n): " exec_choice
        if [[ "$exec_choice" == "y" ]]; then
            echo "Executing command..."
            eval $user_command
        fi
    fi
}

display_streams() {
    echo
    echo "Saved streams:"
    cat -n "$streams_file"
    read -p "Enter the number of the stream to execute or 'q' to return to the menu: " choice
    if [[ "$choice" =~ ^[0-9]+$ ]]; then
        selected_command=$(sed "${choice}q;d" "$streams_file")
        echo "Executing selected command: $selected_command"
        eval $selected_command
    elif [[ "$choice" == "q" ]]; then
        return
    else
        echo "Invalid selection."
    fi
}

main_menu() {
    while true; do
        echo
        echo "Main Menu:"
        echo "1. Spleens"
        echo "2. Stream Editor"
        echo "3. Display and Execute Streams"
        echo "4. Quit"
        read -p "Select an option: " option
        echo

        case "$option" in
            1) 
                display_spleens
                ;;
            2) 
                assemble_command
                ;;
            3)
                display_streams
                ;;
            4) 
                echo "Exiting."
                exit 0
                ;;
            *) 
                echo "Invalid option. Please try again."
                ;;
        esac
        echo 
    done
}

# Check if spleens folder exists, create if not
mkdir -p "$spleens_folder"

# Check if Streams file exists, create if not
touch "$streams_file"

# Run the main menu
main_menu

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *