Remember Forgejo URL and key label across runs

Persist the last-entered values to ~/.config/travel-bootstrap/config
and offer them as the prompt default, so a re-run only needs Enter
instead of retyping the same values every time.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Tommy Rantti 2026-09-26 20:08:28 +03:00
parent d52d1060ce
commit 079c3e4f10

View file

@ -50,17 +50,38 @@ preflight_env() {
gather_config() {
section "config"
local config_file="$HOME/.config/travel-bootstrap/config"
mkdir -p "$(dirname "$config_file")"
local DEFAULT_FORGEJO_URL="" DEFAULT_KEY_NAME=""
if [ -f "$config_file" ]; then
# shellcheck disable=SC1090
source "$config_file"
fi
if [ -z "${FORGEJO_URL:-}" ]; then
read -rp "Forgejo instance URL (e.g. https://git.example.com): " FORGEJO_URL
if [ -n "$DEFAULT_FORGEJO_URL" ]; then
read -rp "Forgejo instance URL [$DEFAULT_FORGEJO_URL]: " FORGEJO_URL
FORGEJO_URL="${FORGEJO_URL:-$DEFAULT_FORGEJO_URL}"
else
read -rp "Forgejo instance URL (e.g. https://git.example.com): " FORGEJO_URL
fi
fi
FORGEJO_URL="${FORGEJO_URL%/}"
if [ -z "${KEY_NAME:-}" ]; then
read -rp "Label for this device's SSH key [travel-laptop]: " KEY_NAME
local key_default="${DEFAULT_KEY_NAME:-travel-laptop}"
read -rp "Label for this device's SSH key [$key_default]: " KEY_NAME
KEY_NAME="${KEY_NAME:-$key_default}"
fi
KEY_NAME="${KEY_NAME:-travel-laptop}"
KEYFILE="$HOME/.ssh/id_ed25519_${KEY_NAME}"
cat > "$config_file" <<EOF
DEFAULT_FORGEJO_URL="$FORGEJO_URL"
DEFAULT_KEY_NAME="$KEY_NAME"
EOF
chmod 600 "$config_file"
step_ok "config gathered" "FORGEJO_URL=$FORGEJO_URL KEY_NAME=$KEY_NAME"
}