-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
Β·148 lines (120 loc) Β· 4.24 KB
/
setup.sh
File metadata and controls
executable file
Β·148 lines (120 loc) Β· 4.24 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
#!/bin/bash
echo "π Setting up your Mac..."
# 1οΈβ£ Install Homebrew
if ! command -v brew &>/dev/null; then
echo "πΊ Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
brew update && brew upgrade
# 2οΈβ£ Install Brewfile dependencies
if [ -f "$HOME/.dotfiles/Brewfile" ]; then
echo "π¦ Installing packages from Brewfile..."
brew bundle --file="$HOME/.dotfiles/Brewfile"
else
echo "β Brewfile not found! Skipping package installation."
fi
# 3οΈβ£ Symlink dotfiles
echo "π Creating symlinks..."
# Define the source and target paths
dotfiles=(
"$HOME/.dotfiles/zsh/zshrc:$HOME/.zshrc"
"$HOME/.dotfiles/zsh/functions/:$HOME/.zsh/functions"
"$HOME/.dotfiles/gitconfig:$HOME/.gitconfig"
"$HOME/.dotfiles/tmux/tmux.conf:$HOME/.tmux.conf"
"$HOME/.dotfiles/nvim:$HOME/.config/nvim"
)
link_path() {
local source_path="$1"
local target_path="$2"
local backup_path=""
mkdir -p "$(dirname "$target_path")"
if [ -L "$target_path" ] && [ "$(readlink "$target_path")" = "$source_path" ]; then
echo "β
Symlink for $(basename "$target_path") already correct"
return
fi
if [ -e "$target_path" ] || [ -L "$target_path" ]; then
backup_path="${target_path}.bak.$(date +%Y%m%d%H%M%S)"
echo "π¦ Backing up existing $(basename "$target_path") to $backup_path"
mv "$target_path" "$backup_path"
fi
echo "π Linking $(basename "$target_path")..."
ln -s "$source_path" "$target_path"
}
# Link custom functions
mkdir -p "$HOME/.zsh/functions"
for f in "$HOME/.dotfiles/zsh/functions/"*.zsh; do
ln -sf "$f" "$HOME/.zsh/functions/$(basename "$f")"
done
# Loop through each file and create symlink
for entry in "${dotfiles[@]}"; do
source_path="${entry%%:*}"
target_path="${entry##*:}"
link_path "$source_path" "$target_path"
done
# 4οΈβ£ Configure Zsh
echo "π Configuring Zsh & Plugins..."
if [ "$SHELL" != "$(brew --prefix)/bin/zsh" ]; then
echo "β‘ Changing default shell to Zsh... (You may be asked for your password)"
sudo chsh -s $(brew --prefix)/bin/zsh "$USER"
else
echo "β
Zsh is already the default shell."
fi
# 5οΈβ£ Enable fzf Key Bindings
echo "β¨οΈ Enabling fzf key bindings..."
yes | $(brew --prefix)/opt/fzf/install --key-bindings --completion --no-update-rc
# Add Zsh plugins to ~/.zshrc (if not already added)
if ! grep -q 'source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh' "$HOME/.zshrc"; then
echo "βοΈ Configuring Zsh Plugins in ~/.zshrc..."
cat <<EOF >>"$HOME/.zshrc"
# Zsh Plugins
source \$(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh
source \$(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# Starship Prompt
eval "\$(starship init zsh)"
EOF
echo "β
Zsh Plugins and Starship added to ~/.zshrc"
else
echo "β
Zsh Plugins and Starship already configured in ~/.zshrc"
fi
# 6οΈβ£ Install & Configure NVM
if [ ! -d "$HOME/.nvm" ]; then
echo "π’ Installing NVM..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
else
echo "β
NVM is already installed."
fi
# Add NVM setup to ~/.zshrc (if not already present)
echo "βοΈ Configuring NVM in ~/.zshrc..."
if ! grep -q 'export NVM_DIR="$HOME/.nvm"' "$HOME/.zshrc"; then
cat <<EOF >>"$HOME/.zshrc"
# NVM Configuration
export NVM_DIR="\$HOME/.nvm"
[ -s "\$NVM_DIR/nvm.sh" ] && \. "\$NVM_DIR/nvm.sh"
[ -s "\$NVM_DIR/bash_completion" ] && \. "\$NVM_DIR/bash_completion"
EOF
echo "β
NVM configuration added to ~/.zshrc"
else
echo "β
NVM already configured in ~/.zshrc"
fi
# 7οΈβ£ Install Node.js LTS via NVM
echo "π’ Installing latest LTS version of Node.js..."
if [ -s "$HOME/.nvm/nvm.sh" ]; then
. "$HOME/.nvm/nvm.sh"
nvm install --lts
nvm use --lts
nvm alias default lts/*
else
echo "β NVM installation failed. Please check your installation."
fi
# 8οΈβ£ Optimize macOS settings
echo "β‘ Optimizing macOS settings..."
# Set fast key repeat rate
defaults write -g KeyRepeat -int 1
defaults write -g InitialKeyRepeat -int 10
# Show hidden files by default in Finder
defaults write com.apple.Finder AppleShowAllFiles YES
killall Finder
# 10 Reload shell configuration
echo "π Reloading ~/.zshrc..."
exec zsh
echo "β
Setup complete!"