BASH
Interactive Bash Menu for Common Developer Tasks
Enhance your development workflow with an interactive Bash menu script, allowing you to select and execute common project tasks like testing or building with ease.
#!/bin/bash
function start_dev_server() {
echo "Starting development server..."
npm start || echo "Failed to start server."
}
function run_tests() {
echo "Running tests..."
npm test || echo "Tests failed."
}
function build_project() {
echo "Building project..."
npm run build || echo "Build failed."
}
function show_status() {
echo "Checking project status..."
git status -s
}
PS3='Select an action: '
options=("Start Dev Server" "Run Tests" "Build Project" "Show Git Status" "Quit")
select opt in "${options[@]}"
do
case $opt in
"Start Dev Server")
start_dev_server
;;
"Run Tests")
run_tests
;;
"Build Project")
build_project
;;
"Show Git Status")
show_status
;;
"Quit")
echo "Exiting."
break
;;
*)
echo "Invalid option $REPLY"
;;
esac
done
How it works: This script creates a user-friendly interactive menu for common development tasks using Bash's `select` command. It presents a list of options (e.g., start server, run tests, build project, show Git status), and upon user selection, executes the corresponding predefined function. This simplifies project management by consolidating frequently used commands into a single, navigable interface.