Skip to content

Instantly share code, notes, and snippets.

@clschnei
Last active March 9, 2026 15:38
Show Gist options
  • Select an option

  • Save clschnei/07c4a694414912990d4a8d43bb52f102 to your computer and use it in GitHub Desktop.

Select an option

Save clschnei/07c4a694414912990d4a8d43bb52f102 to your computer and use it in GitHub Desktop.
`phx-new-interactive` is a lightweight, TUI-based interactive wrapper for the Elixir Phoenix project generator (mix phx.new)

Overview

phx-new-interactive is a TUI-based interactive wrapper for the Elixir Phoenix project generator (mix phx.new). It simplifies the process of creating new Phoenix applications by providing a guided interface for configuring database types, features (LiveView, Ecto, Assets, etc.), and other flags using gum.

"Stack"

  • Bash: The scripting language.
  • Gum: A tool for styling shell scripts (TUI elements).

Prerequisites

  • Elixir & Phoenix: Ensure mix phx.new is available on your system.
  • Gum: Install via brew install gum or your preferred package manager.
#!/bin/bash
# Bash Strict Mode
set -euo pipefail
# Check if gum is installed
if ! command -v gum &> /dev/null; then
echo "Gum is not installed. Install instructions: https://github.com/charmbracelet/gum?tab=readme-ov-file#installation"
exit 1
fi
# Check if mix phx.new is available
if ! mix help phx.new &> /dev/null; then
echo "Phoenix generator (mix phx.new) is not installed."
echo "Install it with: mix archive.install hex phx_new"
exit 1
fi
# Handle exit signals
trap "echo -e '\nAborted by user.'; exit 1" SIGINT SIGTERM
gum style \
--border double \
--align center \
--width 50 \
"Phoenix New Generator"
# 1. Project Name/Path
PROJECT_PATH=$(gum input --placeholder "Project name (e.g., my_app)" --value "my_app")
# 2. Database Selection
echo "Select database (Default: postgres):"
DB_TYPE=$(gum choose "sqlite3" "postgres" "mysql" "mssql")
# 3. HTTP Adapter Selection
echo "Select HTTP adapter (Default: bandit):"
ADAPTER=$(gum choose "bandit" "cowboy")
# 4. Feature Flags (Multi-select)
# Using 'gum choose --no-limit' to let you toggle multiple options at once
echo "Select additional features (Space to toggle, Enter to confirm):"
FEATURES=$(gum choose --no-limit --selected="LiveView,Assets,Ecto,HTML,Mailer,Dashboard,Gettext,Agents.md" \
"LiveView" "Assets" "Ecto" "HTML" "Mailer" "Dashboard" "Gettext" "Agents.md" "BinaryID" "Umbrella")
# Build the command string
CMD="mix phx.new $PROJECT_PATH --database $DB_TYPE --adapter $ADAPTER"
# Logic to add/remove flags based on selection
if [[ ! $FEATURES =~ "LiveView" ]]; then CMD="$CMD --no-live"; fi
if [[ ! $FEATURES =~ "Assets" ]]; then CMD="$CMD --no-assets"; fi
if [[ ! $FEATURES =~ "Ecto" ]]; then CMD="$CMD --no-ecto"; fi
if [[ ! $FEATURES =~ "HTML" ]]; then CMD="$CMD --no-html"; fi
if [[ ! $FEATURES =~ "Mailer" ]]; then CMD="$CMD --no-mailer"; fi
if [[ ! $FEATURES =~ "Dashboard" ]]; then CMD="$CMD --no-dashboard"; fi
if [[ ! $FEATURES =~ "Gettext" ]]; then CMD="$CMD --no-gettext"; fi
if [[ ! $FEATURES =~ "Agents.md" ]]; then CMD="$CMD --no-agents-md"; fi
if [[ $FEATURES =~ "BinaryID" ]]; then CMD="$CMD --binary-id"; fi
if [[ $FEATURES =~ "Umbrella" ]]; then CMD="$CMD --umbrella"; fi
# 5. Dependency Installation
echo "Install dependencies automatically?"
if gum confirm; then
CMD="$CMD --install"
else
CMD="$CMD --no-install"
fi
# 6. Final Confirmation
gum style --foreground 77 "Ready to run:"
gum style --italic "$CMD"
if gum confirm "Proceed with generation?"; then
gum style --foreground 82 "Generating Phoenix project..."
$CMD
gum style --foreground 82 "Successfully created $PROJECT_PATH!"
else
echo "Aborted."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment