-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·178 lines (157 loc) · 5.78 KB
/
setup.sh
File metadata and controls
executable file
·178 lines (157 loc) · 5.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/dotfiles.conf"
# =============================================================================
# Helper Functions
# =============================================================================
# Prompt with default Y - returns 0 (true) if yes, 1 (false) if no
prompt_yes() {
local message="$1"
read -p "$message [Y/n]: " -n 1 -r
echo
[[ ! $REPLY =~ ^[Nn]$ ]]
}
# Prompt with default N - returns 0 (true) if yes, 1 (false) if no
prompt_no() {
local message="$1"
read -p "$message [y/N]: " -n 1 -r
echo
[[ $REPLY =~ ^[Yy]$ ]]
}
# Check if symlink already points to correct target
# Returns 0 (true) if already correct, 1 (false) otherwise
is_correct_symlink() {
local target="$1"
local expected="$2"
[[ -L "$target" ]] && [[ "$(readlink "$target")" == "$expected" ]]
}
# Handle existing file/directory/symlink before creating symlink
# Returns 0 if we should proceed with symlink, 1 if we should skip
handle_existing() {
local target="$1"
if [[ -e "$target" || -L "$target" ]]; then
if [[ -L "$target" ]]; then
echo " Symlink already exists: $target -> $(readlink "$target")"
elif [[ -d "$target" ]]; then
echo " Directory already exists: $target"
else
echo " File already exists: $target"
fi
if prompt_yes " Delete it?"; then
rm -rf "$target"
return 0
fi
return 1
fi
return 0
}
# =============================================================================
# Home Directory Dotfiles
# =============================================================================
echo "=== Home Directory Dotfiles ==="
for dotfile in "${home_dotfiles[@]}"; do
if is_correct_symlink "$HOME/$dotfile" "$DOTFILES_PATH/$dotfile"; then
echo "Already linked: ~/$dotfile"
continue
fi
if ! handle_existing "$HOME/$dotfile"; then
echo " Skipped: ~/$dotfile"
continue
fi
if prompt_yes "Symlink ~/$dotfile?"; then
ln -s "$DOTFILES_PATH/$dotfile" "$HOME/$dotfile"
echo " Created: ~/$dotfile -> $DOTFILES_PATH/$dotfile"
fi
done
# =============================================================================
# Config Directory Symlinks
# =============================================================================
echo ""
echo "=== Config Directory Symlinks ==="
mkdir -p ~/.config
for config_dir in "${config_dirs[@]}"; do
if is_correct_symlink "$HOME/.config/$config_dir" "$DOTFILES_PATH/.config/$config_dir"; then
echo "Already linked: ~/.config/$config_dir"
continue
fi
if ! handle_existing "$HOME/.config/$config_dir"; then
echo " Skipped: ~/.config/$config_dir"
continue
fi
if prompt_yes "Symlink ~/.config/$config_dir?"; then
ln -s "$DOTFILES_PATH/.config/$config_dir" "$HOME/.config/$config_dir"
echo " Created: ~/.config/$config_dir -> $DOTFILES_PATH/.config/$config_dir"
fi
done
# =============================================================================
# Special Setups
# =============================================================================
echo ""
echo "=== Special Setups ==="
# Neovim config
if is_correct_symlink "$HOME/.config/nvim" "$DOTFILES_PATH/.vim"; then
echo "Already linked: ~/.config/nvim"
elif ! handle_existing "$HOME/.config/nvim"; then
echo " Skipped: ~/.config/nvim"
elif prompt_yes "Setup Neovim config (~/.config/nvim -> ~/.dotfiles/.vim)?"; then
ln -s "$DOTFILES_PATH/.vim" "$HOME/.config/nvim"
echo " Created: ~/.config/nvim -> $DOTFILES_PATH/.vim"
fi
# Personal git config
if prompt_yes "Setup personal git config (~/.gitconfig.local)?"; then
if [[ -f "$HOME/.gitconfig.local" ]]; then
echo " File already exists: ~/.gitconfig.local"
if prompt_yes " Overwrite it?"; then
cp "$DOTFILES_PATH/.gitconfig.personal" "$HOME/.gitconfig.local"
echo " Copied: ~/.gitconfig.local"
else
echo " Skipped: ~/.gitconfig.local"
fi
else
cp "$DOTFILES_PATH/.gitconfig.personal" "$HOME/.gitconfig.local"
echo " Copied: ~/.gitconfig.local"
fi
fi
# Vim local config (before/after)
for suffix in before after; do
local_file="$HOME/.vimrc.$suffix.local"
example_file="$DOTFILES_PATH/.vimrc.$suffix.local.example"
if [[ ! -f "$local_file" ]]; then
if prompt_yes "Setup vim local config (~/.vimrc.$suffix.local from example)?"; then
cp "$example_file" "$local_file"
echo " Copied: ~/.vimrc.$suffix.local"
fi
else
echo "Skipping ~/.vimrc.$suffix.local (already exists)"
fi
done
# Intelephense license (optional - for PHP development)
if prompt_no "Setup Intelephense license (PHP LSP)?"; then
mkdir -p ~/intelephense
read -p "Enter Intelephense license key: " -r intelephense_license
echo
if [[ -n "$intelephense_license" ]]; then
echo "$intelephense_license" > ~/intelephense/license.txt
echo " Created: ~/intelephense/license.txt"
else
echo " Skipped: No license key provided"
fi
fi
# Sudoers timeout (optional - requires sudo)
if prompt_no "Setup sudoers timeout (extends sudo timeout to 60min, requires sudo)?"; then
sudo cp "$DOTFILES_PATH/private/etc/sudoers.d/timeout" /private/etc/sudoers.d/timeout
sudo chmod 440 /private/etc/sudoers.d/timeout
sudo chown root:wheel /private/etc/sudoers.d/timeout
echo " Installed: /private/etc/sudoers.d/timeout"
fi
# Git aliases
if prompt_yes "Download GitAlias (extended git aliases)?"; then
curl -fsSL https://raw.githubusercontent.com/GitAlias/gitalias/main/gitalias.txt -o "$DOTFILES_PATH/.gitalias"
echo " Downloaded: $DOTFILES_PATH/.gitalias"
fi
# =============================================================================
# Done
# =============================================================================
echo ""
echo "=== Setup Complete ==="
echo "You may need to restart your shell or run 'source ~/.zshrc' for changes to take effect."