Skip to content

Commit 3161a7d

Browse files
committed
feat(install): add Starship cloud-module picker to onboarding
install/customize-starship.sh uses fzf --multi (with a y/n fallback when fzf isn't installed yet) to let the user pick aws/azure/gcloud modules for the prompt. Toggles the `disabled` flag in xdg/starship.toml in place, preserving format/symbol/style lines, and appends the [gcloud] section when absent. Wired into install-macos.sh and install-linux.sh as an optional step after oh-my-zsh, defaulting to No so the unattended path stays clean. Script is re-runnable anytime: bash install/customize-starship.sh
1 parent 03e5f2a commit 3161a7d

3 files changed

Lines changed: 91 additions & 0 deletions

File tree

install/customize-starship.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env bash
2+
# Interactive selector for cloud-provider modules in the Starship prompt.
3+
# Edits xdg/starship.toml in place (which is symlinked into ~/.config/).
4+
# Safe to re-run: currently-enabled modules are pre-selected.
5+
#
6+
# Invoked optionally at the end of install/install-{macos,linux}.sh, or run
7+
# standalone from the repo root: bash install/customize-starship.sh
8+
set -euo pipefail
9+
10+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
11+
CONFIG="$(cd "$SCRIPT_DIR/.." && pwd)/xdg/starship.toml"
12+
[ -f "$CONFIG" ] || { echo "starship.toml not found at $CONFIG" >&2; exit 1; }
13+
14+
MODULES=(aws azure gcloud)
15+
16+
currently_enabled() {
17+
awk '
18+
/^\[/ { gsub(/[][]/, "", $0); section=$0; next }
19+
section ~ /^(aws|azure|gcloud)$/ && $0 ~ /^disabled[[:space:]]*=[[:space:]]*false/ {
20+
print section
21+
}
22+
' "$CONFIG"
23+
}
24+
25+
enabled_before="$(currently_enabled | paste -sd, - || true)"
26+
27+
if command -v fzf >/dev/null 2>&1; then
28+
chosen="$(
29+
printf '%s\n' "${MODULES[@]}" | fzf \
30+
--multi --height='~30%' --reverse \
31+
--prompt='Enable cloud modules> ' \
32+
--header=$'Tab: toggle · Enter: confirm · currently enabled: '"${enabled_before:-none}" \
33+
|| true
34+
)"
35+
else
36+
echo "fzf not installed — falling back to y/n prompts."
37+
chosen=""
38+
for m in "${MODULES[@]}"; do
39+
default="n"; currently_enabled | grep -qxF "$m" && default="y"
40+
read -r -p "Enable $m? [y/n] (current: $default) " reply </dev/tty || reply=""
41+
reply="${reply:-$default}"
42+
case "$reply" in [Yy]*) chosen+="$m"$'\n' ;; esac
43+
done
44+
fi
45+
46+
toggle_section() {
47+
local mod="$1" val="$2" tmp
48+
if grep -q "^\[$mod\]" "$CONFIG"; then
49+
tmp="$(mktemp)"
50+
awk -v section="[$mod]" -v value="$val" '
51+
/^\[/ { in_s = ($0 == section) ? 1 : 0 }
52+
in_s && /^disabled[[:space:]]*=/ { print "disabled = " value; next }
53+
{ print }
54+
' "$CONFIG" >"$tmp" && mv "$tmp" "$CONFIG"
55+
else
56+
printf '\n[%s]\ndisabled = %s\n' "$mod" "$val" >>"$CONFIG"
57+
fi
58+
}
59+
60+
for m in "${MODULES[@]}"; do
61+
if printf '%s\n' "$chosen" | grep -qxF "$m"; then
62+
toggle_section "$m" false
63+
else
64+
toggle_section "$m" true
65+
fi
66+
done
67+
68+
echo
69+
echo "Starship cloud modules now enabled:"
70+
enabled_now="$(currently_enabled | paste -sd, - || true)"
71+
echo " ${enabled_now:-none}"
72+
if [ "$enabled_before" != "$enabled_now" ]; then
73+
echo
74+
echo "xdg/starship.toml was modified. Review with: git -C \"$(cd "$SCRIPT_DIR/.." && pwd)\" diff xdg/starship.toml"
75+
fi

install/install-linux.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ run_setup_symlinks
7373
# 4. oh-my-zsh + zsh-autosuggestions
7474
install_oh_my_zsh
7575

76+
# 5. Optional: pick cloud-provider modules for the Starship prompt.
77+
step "Starship prompt customization (optional)"
78+
if prompt_yes_no "Pick which cloud modules (aws/azure/gcloud) show in the prompt?" N; then
79+
bash "$DOTFILES_DIR/install/customize-starship.sh"
80+
else
81+
ok "skipped (edit xdg/starship.toml or re-run install/customize-starship.sh anytime)"
82+
fi
83+
7684
cat <<EOF
7785
7886
${c_green}Core automated steps complete.${c_reset}

install/install-macos.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ ok "Brewfile installed"
7979
# 6. oh-my-zsh + zsh-autosuggestions
8080
install_oh_my_zsh
8181

82+
# 7. Optional: pick cloud-provider modules for the Starship prompt.
83+
step "Starship prompt customization (optional)"
84+
if prompt_yes_no "Pick which cloud modules (aws/azure/gcloud) show in the prompt?" N; then
85+
bash "$DOTFILES_DIR/install/customize-starship.sh"
86+
else
87+
ok "skipped (edit xdg/starship.toml or re-run install/customize-starship.sh anytime)"
88+
fi
89+
8290
cat <<EOF
8391
8492
${c_green}All automated steps complete.${c_reset}

0 commit comments

Comments
 (0)