-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·143 lines (127 loc) · 5.28 KB
/
install.sh
File metadata and controls
executable file
·143 lines (127 loc) · 5.28 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
#!/usr/bin/env zsh
set -euo pipefail
DOTFILES="${DOTFILES:-$HOME/.dotfiles}"
ZSH_PATH="$(command -v zsh || echo /bin/zsh)"
# ---------------- OS detect ----------------
case "$OSTYPE" in
darwin*) IS_MAC=1 ;;
linux*) IS_LINUX=1 ;;
*) echo "Unsupported OS: $OSTYPE" >&2; exit 1 ;;
esac
# ---------- 0) Minimal bootstrap ----------
if [[ -n "${IS_MAC:-}" ]]; then
if ! command -v brew >/dev/null 2>&1; then
echo "• Installing Homebrew…"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
[[ -x /opt/homebrew/bin/brew ]] && eval "$(/opt/homebrew/bin/brew shellenv)"
[[ -x /usr/local/bin/brew ]] && eval "$(/usr/local/bin/brew shellenv)"
fi
echo "• Installing base packages (mac)…"
brew install zsh git curl vim fzf
elif [[ -n "${IS_LINUX:-}" ]]; then
if ! command -v apt >/dev/null 2>&1; then
echo "This script expects apt (Ubuntu/Debian)." >&2; exit 1
fi
echo "• Installing base packages (apt)…"
export DEBIAN_FRONTEND=noninteractive
sudo apt update
sudo apt install -y zsh git curl vim fzf ca-certificates
fi
# ---------- 1) Make zsh default ----------
if [[ "${SHELL:-}" != "$ZSH_PATH" ]]; then
if [[ -n "${IS_LINUX:-}" ]] && ! grep -q "$ZSH_PATH" /etc/shells 2>/dev/null; then
echo "• Adding $ZSH_PATH to /etc/shells (sudo)…"
echo "$ZSH_PATH" | sudo tee -a /etc/shells >/dev/null
fi
echo "• Changing login shell to zsh…"
chsh -s "$ZSH_PATH" || echo " (chsh may need logout/login or sudo)"
fi
# ---------- 2) Remove old dotfiles (unsafe) ----------
echo "• Removing old dotfiles (unsafe)…"
rm -f "$HOME/.gitconfig" \
"$HOME/.gitignore_global" \
"$HOME/.vimrc" \
"$HOME/.zshrc" \
"$HOME/.dircolors" \
"$HOME/.tmux.conf"
# ---------- 3) Link new dotfiles ----------
echo "• Linking new dotfiles…"
mkdir -p "$HOME/.vim/colors" "$HOME/.vim/autoload"
ln -snf "$DOTFILES/dots/home/gitconfig" "$HOME/.gitconfig"
ln -snf "$DOTFILES/dots/home/gitignore_global" "$HOME/.gitignore_global"
ln -snf "$DOTFILES/dots/home/vimrc" "$HOME/.vimrc"
ln -snf "$DOTFILES/dots/home/zshrc" "$HOME/.zshrc"
ln -snf "$DOTFILES/dots/home/dircolors" "$HOME/.dircolors"
ln -snf "$DOTFILES/dots/home/tmux" "$HOME/.tmux.conf"
# Ensure Vim state directories exist
mkdir -p "$HOME/.vim/undo" "$HOME/.vim/backup" "$HOME/.vim/swap"
# Optional color scheme
if [[ -f "$DOTFILES/colors/gruvbox.vim" ]]; then
ln -snf "$DOTFILES/colors/gruvbox.vim" "$HOME/.vim/colors/gruvbox.vim"
fi
# ---------- 4) Git identity ----------
if [[ ! -f "$HOME/.gitconfig.user" ]]; then
echo "• Setting up your Git identity (~/.gitconfig.user)"
read -r "?Enter your full name: " GIT_NAME
read -r "?Enter your email address: " GIT_EMAIL
cat > "$HOME/.gitconfig.user" <<EOF
[user]
name = $GIT_NAME
email = $GIT_EMAIL
EOF
if [[ -n "${IS_MAC:-}" ]]; then
cat >> "$HOME/.gitconfig.user" <<'EOF'
[difftool "sourcetree"]
cmd = opendiff "$LOCAL" "$REMOTE"
path =
[mergetool "sourcetree"]
cmd = /Applications/SourceTree.app/Contents/Resources/opendiff-w.sh "$LOCAL" "$REMOTE" -ancestor "$BASE" -merge "$MERGED"
trustExitCode = true
EOF
fi
echo "→ Created ~/.gitconfig.user"
fi
# ---------- 5) Oh My Zsh ----------
if [[ ! -d "$HOME/.oh-my-zsh" ]]; then
echo "• Installing Oh My Zsh…"
export RUNZSH=no CHSH=no KEEP_ZSHRC=yes
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
fi
ZSH_CUSTOM="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"
# ---------- 6) OMZ plugins & theme ----------
echo "• Ensuring OMZ plugins/theme…"
clone_or_update() {
local repo="$1" dest="$2"
if [[ -d "$dest/.git" ]]; then
git -C "$dest" pull --ff-only || true
else
rm -rf "$dest"
git clone --depth=1 "$repo" "$dest"
fi
}
clone_or_update https://github.com/zsh-users/zsh-syntax-highlighting.git \
"$ZSH_CUSTOM/plugins/zsh-syntax-highlighting"
clone_or_update https://github.com/zsh-users/zsh-autosuggestions \
"$ZSH_CUSTOM/plugins/zsh-autosuggestions"
clone_or_update https://github.com/romkatv/powerlevel10k.git \
"$ZSH_CUSTOM/themes/powerlevel10k"
# ---------- 7) vim-plug ----------
echo "• Installing vim-plug and plugins…"
curl -fLo "$HOME/.vim/autoload/plug.vim" --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
if command -v vim >/dev/null 2>&1; then
vim +PlugInstall +qall || true
fi
# ---------- 8) OS essentials ----------
echo "• Installing essentials for this OS…"
if [[ -n "${IS_MAC:-}" ]]; then
[[ -x "/opt/homebrew/opt/fzf/install" ]] && /opt/homebrew/opt/fzf/install --key-bindings --completion --no-update-rc --no-bash --no-fish || true
brew install --cask font-jetbrains-mono || true
[[ -x /opt/homebrew/bin/brew ]] && eval "$(/opt/homebrew/bin/brew shellenv)" || true
[[ -x /usr/local/bin/brew ]] && eval "$(/usr/local/bin/brew shellenv)" || true
zsh -i -c 'source ~/.zshrc >/dev/null 2>&1; command -v brew >/dev/null && type brew-essentials >/dev/null && brew-essentials || true'
elif [[ -n "${IS_LINUX:-}" ]]; then
sudo apt install -y git-credential-libsecret fonts-jetbrains-mono || true
zsh -i -c 'source ~/.zshrc >/dev/null 2>&1; type apt-essentials >/dev/null && apt-essentials || true'
fi
echo "✅ All done. Open a new terminal or run: exec zsh"