Skip to content

Commit 3e3ee07

Browse files
committed
feat(bootstrap): add machine role selection and DOTFILES_ENV
Prompt for personal/work role during bootstrap, write it to ~/.dotfilesenv, and load it as DOTFILES_ENV in fish config. Also reorganizes the prompt flow to show configuration summary before confirmation.
1 parent e08ded0 commit 3e3ee07

File tree

2 files changed

+40
-17
lines changed

2 files changed

+40
-17
lines changed

bootstrap.sh

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,52 @@ echo "=================="
99
echo
1010

1111
# Configuration
12+
DEFAULT_DOTFILES_ENV="personal"
1213
DEFAULT_DOTFILES_DIR="$HOME/git/dotfiles"
1314
DOTFILES_REPO="https://github.com/cpplain/dotfiles.git"
1415

15-
# Show plan and get confirmation
16+
# Show plan
1617
echo "This script will:"
17-
echo " 1. Install Homebrew"
18-
echo " 2. Install lnk via Homebrew"
19-
echo " 3. Clone the dotfiles repository"
20-
echo " 4. Create configuration symlinks"
21-
echo " 5. Install Homebrew packages from Brewfile"
18+
echo " 1. Set machine role (personal or work)"
19+
echo " 2. Install Homebrew"
20+
echo " 3. Install lnk via Homebrew"
21+
echo " 4. Clone the dotfiles repository"
22+
echo " 5. Create configuration symlinks"
23+
echo " 6. Install Homebrew packages from Brewfile"
2224
echo
2325

26+
# Ask for machine role
27+
while true; do
28+
read -p "Machine role (personal/work)? [DEFAULT_DOTFILES_ENV] " DOTFILES_ENV │
29+
DOTFILES_ENV=${DOTFILES_ENV:-$DEFAULT_DOTFILES_ENV}
30+
if [[ "$DOTFILES_ENV" == "personal" || "$DOTFILES_ENV" == "work" ]]; then
31+
break
32+
fi
33+
echo "Invalid role. Please enter 'personal' or 'work'."
34+
done
35+
echo
36+
37+
# Ask for dotfiles directory
38+
read -p "Where should dotfiles be cloned? [$DEFAULT_DOTFILES_DIR] " DOTFILES_DIR
39+
DOTFILES_DIR=${DOTFILES_DIR:-$DEFAULT_DOTFILES_DIR}
40+
echo
41+
42+
# Confirm
43+
echo "Configuration:"
44+
echo " Machine role: $DOTFILES_ENV"
45+
echo " Dotfiles directory: $DOTFILES_DIR"
46+
echo
2447
read -p "Continue? [Y/n] " -n 1 -r
2548
echo
2649
if [[ ! $REPLY =~ ^[Yy]$ ]] && [[ ! -z $REPLY ]]; then
2750
echo "Bootstrap cancelled."
2851
exit 0
2952
fi
30-
31-
# Ask for dotfiles directory
32-
echo
33-
read -p "Where should dotfiles be cloned? [$DEFAULT_DOTFILES_DIR] " DOTFILES_DIR
34-
DOTFILES_DIR=${DOTFILES_DIR:-$DEFAULT_DOTFILES_DIR}
35-
echo "Dotfiles will be cloned to: $DOTFILES_DIR"
3653
echo
3754

38-
# Step 1: Install Homebrew
55+
echo "$DOTFILES_ENV" >"$HOME/.dotfilesenv"
56+
57+
# Install Homebrew
3958
echo "Installing Homebrew..."
4059
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
4160

@@ -44,11 +63,11 @@ if [[ -d "/opt/homebrew" ]]; then
4463
eval "$(/opt/homebrew/bin/brew shellenv)"
4564
fi
4665

47-
# Step 2: Install lnk
66+
# Install lnk
4867
echo "Installing lnk..."
4968
brew install cpplain/tap/lnk
5069

51-
# Step 3: Clone dotfiles repository
70+
# Clone dotfiles repository
5271
if [[ -d "$DOTFILES_DIR/.git" ]]; then
5372
echo "✓ Repository already exists at $DOTFILES_DIR"
5473
else
@@ -57,13 +76,13 @@ else
5776
git clone --recurse-submodules "$DOTFILES_REPO" "$DOTFILES_DIR"
5877
fi
5978

60-
# Step 4: Create configuration symlinks
79+
# Create configuration symlinks
6180
echo
6281
echo "Creating configuration symlinks..."
6382
cd "$DOTFILES_DIR"
6483
lnk --config "$DOTFILES_DIR/home/.config/lnk/config.json" create
6584

66-
# Step 5: Install Homebrew packages
85+
# Install Homebrew packages
6786
echo
6887
echo "Installing Homebrew packages from Brewfile..."
6988
brew update && brew bundle --global --verbose --force

home/.config/fish/config.fish

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ set -gx XDG_RUNTIME_DIR $TMPDIR
66

77
set -gx EDITOR nvim
88

9+
if test -f ~/.dotfilesenv
10+
set -gx DOTFILES_ENV (string trim (cat ~/.dotfilesenv))
11+
end
12+
913
set -g fish_greeting # disable fish greeting
1014
set -g fish_prompt_pwd_dir_length 0
1115
set -g fish_transient_prompt 1

0 commit comments

Comments
 (0)