From ba06819221edb0194ef1252e78b4b1a55dda93cc Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Wed, 5 Nov 2025 19:56:35 -0500 Subject: [PATCH] feat: Adds hpa-create helper script. --- env/.local/scripts/hpa | 25 ++++++++++++------------- env/.local/scripts/hpa-create | 31 +++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 13 deletions(-) create mode 100755 env/.local/scripts/hpa-create diff --git a/env/.local/scripts/hpa b/env/.local/scripts/hpa index 16bb267..dcd19ba 100755 --- a/env/.local/scripts/hpa +++ b/env/.local/scripts/hpa @@ -88,8 +88,17 @@ create() { [[ -z $project ]] && echoerr "Must supply a project name." && exit 1 project_container_name="$(run create --quiet "/consults/$(date '+%Y.%m.%d').$project")" - dir_name="$(basename "$project_container_name")" - echo "$CONSULTS_DIR/$dir_name" + dir_name="$CONSULTS_DIR/$(basename "$project_container_name")" + + # Initialize git repo in the project and the initial commit. + pushd "$(echo "$dir_name" | tr -d '\r' | head -1)" &>/dev/null || exit 1 + ( + git init + git add . + git commit --all --message="Initial commit" + ) &>/dev/null + popd &>/dev/null + echo "$dir_name" } ############################## MAIN ############################## @@ -101,17 +110,7 @@ if [[ $first_arg == "init" ]]; then init "$@" elif [[ $first_arg == "create" ]]; then shift - dir=$(create "$@") - # Initialize project as a git repo. - pushd "$(echo "$dir" | tr -d '\r' | head -1)" &>/dev/null || exit 1 - ( - git init - git add . - git commit --all --message="Initial commit" - ) >&/dev/null - popd &>/dev/null - # Echo the project directory. - echo "$dir" + echo "$(create "$@")" else run "$@" fi diff --git a/env/.local/scripts/hpa-create b/env/.local/scripts/hpa-create new file mode 100755 index 0000000..e79eb3a --- /dev/null +++ b/env/.local/scripts/hpa-create @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +# NB: This wrapper script is required for the spinner to work, otherwise if declared in +# the 'hpa' (container wrapper script) then it doesn't work. +# https://github.com/charmbracelet/gum/issues/419 + +usage() { + cat <<'EOF' + +Create a home performance assesment project directory. This handles creating the project using +the preferred directory name (example '25.11.05.McTestface'). + +It show's a spinner while the project is being created and supresses all output except for the +generated directory. This allows the command to be called using `cd $(hpa-create McTestface)` to +cd into the directory once it's created and get to work! + +USAGE: + $ hpa-create + +FLAGS: + -h | --help: Show this help page. + +EOF +} + +first_arg=${1:-""} +if [[ $first_arg == "-h" ]] || [[ $first_arg == "--help" ]]; then + usage && exit 0 +else + gum spin --show-output --title "Creating project..." -- bash -c "hpa create $*" | tr -d '\r' | head -1 +fi