Utoljára aktív 2 weeks ago

Cross-platform Zsh setup scripts and managed dotfiles with Oh My Zsh framework, Starship prompt, aliases, functions, and path configuration.

Revízió a1dd92bbc0d9dcc12f418d4e0a8950d92a459f14

README.md Eredeti

Bash Script Installer for Zsh

The "Bash Script Installer" simplifies the setup of Zsh.

Zsh

Ubuntu

bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_ubuntu.sh)"

WSL

bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_wsl.sh)"

MacOS

bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_macos.sh)"
zsh_macos.sh Eredeti
1#!/bin/bash
2set -euo pipefail
3
4# =============================
5# COLORS & LOGGING
6# =============================
7RED='\033[0;31m'
8GREEN='\033[0;32m'
9YELLOW='\033[1;33m'
10BLUE='\033[0;34m'
11NC='\033[0m'
12
13log() { echo -e "${BLUE}[INFO]${NC} $*"; }
14ok() { echo -e "${GREEN}[OK]${NC} $*"; }
15warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
16err() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
17
18# =============================
19# CONFIG
20# =============================
21GIST_RAW_BASE="https://gist.githubusercontent.com/weehong/c430fefc6e90428dfe6811e0766decf4/raw"
22
23CONFIG_FILES=(
24 ".alias"
25 ".func"
26 ".pathrc"
27 ".sourcerc"
28 ".vimrc"
29 ".zshrc"
30)
31
32# =============================
33# REQUIREMENTS
34# =============================
35check_requirements() {
36 if [[ $EUID -eq 0 ]]; then
37 err "Do not run as root on macOS"
38 exit 1
39 fi
40}
41
42# =============================
43# INSTALLATION FUNCTIONS
44# =============================
45configure_git() {
46 log "Configuring Git..."
47 read -p "Git name (leave empty to skip): " name
48 read -p "Git email (leave empty to skip): " email
49
50 if [[ -n "$name" ]]; then
51 git config --global user.name "$name"
52 fi
53 if [[ -n "$email" ]]; then
54 git config --global user.email "$email"
55 fi
56 ok "Git configured"
57}
58
59install_oh_my_zsh() {
60 if [[ -d "$HOME/.oh-my-zsh" ]]; then
61 ok "Oh My Zsh already installed"
62 return
63 fi
64
65 log "Installing Oh My Zsh..."
66 RUNZSH=no CHSH=no KEEP_ZSHRC=yes \
67 sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
68 ok "Oh My Zsh installed"
69}
70
71install_plugins() {
72 log "Installing plugins..."
73 local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins"
74 mkdir -p "$dir"
75
76 [[ -d "$dir/zsh-autosuggestions" ]] || \
77 git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions"
78
79 [[ -d "$dir/zsh-syntax-highlighting" ]] || \
80 git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting"
81
82 ok "Plugins installed"
83}
84
85install_theme() {
86 log "Installing Spaceship theme..."
87 local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes"
88 local dir="$themes/spaceship-prompt"
89
90 mkdir -p "$themes"
91 [[ -d "$dir" ]] || \
92 git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1
93
94 ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme"
95 ok "Theme installed"
96}
97
98download_configs() {
99 log "Downloading custom config files..."
100 local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)"
101 mkdir -p "$backup"
102
103 for f in "${CONFIG_FILES[@]}"; do
104 local url="$GIST_RAW_BASE/$f"
105 local target="$HOME/$f"
106 local tmp="${target}.tmp.$$"
107
108 if [[ -f "$target" ]]; then
109 cp "$target" "$backup/"
110 fi
111
112 log "Fetching $f ..."
113 if curl -fsSL "$url" -o "$tmp"; then
114 mv "$tmp" "$target"
115 else
116 rm -f "$tmp"
117 warn "Failed to download $f"
118 fi
119 done
120
121 ok "Configs downloaded (Backup at $backup)"
122}
123
124update_zshrc() {
125 local zshrc="$HOME/.zshrc"
126 log "Checking .zshrc..."
127
128 if [[ ! -f "$zshrc" ]]; then
129 warn ".zshrc not found. Run option 5 first."
130 return 1
131 fi
132
133 ok ".zshrc already comes from the managed gist."
134 ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias"
135}
136
137switch_shell() {
138 log "Starting Zsh session..."
139 echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}"
140 echo "----------------------------------------"
141 zsh -l
142 echo "----------------------------------------"
143 ok "Returned from Zsh session"
144}
145
146# =============================
147# INTERACTIVE MENU
148# =============================
149show_menu() {
150 echo "==========================================="
151 echo "macOS Zsh Setup - Choose what to do"
152 echo "==========================================="
153 echo " 0) Run ALL steps (1-7)"
154 echo " 1) Configure Git"
155 echo " 2) Install Oh My Zsh"
156 echo " 3) Install plugins (autosuggestions, syntax highlighting)"
157 echo " 4) Install Spaceship theme"
158 echo " 5) Download custom configs (~/.alias, .func, .vimrc, etc.)"
159 echo " 6) Check ~/.zshrc load order"
160 echo " 7) Switch to Zsh (Temporary Sub-shell)"
161 echo " 8) Quit"
162 echo "==========================================="
163}
164
165run_choices() {
166 local input
167 read -p "Select: " input
168 input="${input//,/ }"
169
170 local -a to_run=()
171 local -a to_exclude=()
172
173 for item in $input; do
174 if [[ "$item" == !* ]]; then
175 to_exclude+=("${item:1}")
176 elif [[ "$item" == "0" ]]; then
177 to_run+=(1 2 3 4 5 6 7)
178 else
179 to_run+=("$item")
180 fi
181 done
182
183 if [[ ${#to_run[@]} -gt 0 ]]; then
184 for choice in "${to_run[@]}"; do
185 local skip=false
186
187 if [[ ${#to_exclude[@]} -gt 0 ]]; then
188 for ex in "${to_exclude[@]}"; do
189 if [[ "$choice" == "$ex" ]]; then
190 skip=true
191 break
192 fi
193 done
194 fi
195
196 $skip && continue
197
198 case "$choice" in
199 1) configure_git ;;
200 2) install_oh_my_zsh ;;
201 3) install_plugins ;;
202 4) install_theme ;;
203 5) download_configs ;;
204 6) update_zshrc ;;
205 7) switch_shell ;;
206 8) exit 0 ;;
207 *) warn "Skipping invalid option: $choice" ;;
208 esac
209 echo
210 done
211 fi
212}
213
214# =============================
215# MAIN
216# =============================
217main() {
218 check_requirements
219 while true; do
220 show_menu
221 run_choices
222 read -p "Do you want to run more options? (y/n): " again
223 [[ "$again" =~ ^[Yy]$ ]] || break
224 done
225 ok "macOS configuration complete!"
226}
227
228main "$@"
229
zsh_ubuntu.sh Eredeti
1#!/bin/bash
2set -euo pipefail
3
4# =============================
5# COLORS & LOGGING
6# =============================
7RED='\033[0;31m'
8GREEN='\033[0;32m'
9YELLOW='\033[1;33m'
10BLUE='\033[0;34m'
11NC='\033[0m'
12
13log() { echo -e "${BLUE}[INFO]${NC} $*"; }
14ok() { echo -e "${GREEN}[OK]${NC} $*"; }
15warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
16err() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
17
18# =============================
19# FLAGS & CONFIG
20# =============================
21SKIP_PACKAGES=false
22SKIP_GIT_CONFIG=false
23SKIP_SHELL_CHANGE=false
24SKIP_XCLIP=false
25INSTALL_HOMEBREW=false
26
27GIST_RAW_BASE="https://gist.githubusercontent.com/weehong/c430fefc6e90428dfe6811e0766decf4/raw"
28CONFIG_FILES=(
29 ".alias"
30 ".func"
31 ".pathrc"
32 ".sourcerc"
33 ".vimrc"
34 ".zshrc"
35)
36
37# =============================
38# OS DETECTION
39# =============================
40detect_os() {
41 if [ -f /etc/os-release ]; then
42 . /etc/os-release
43 echo "$ID"
44 else
45 echo "unknown"
46 fi
47}
48
49# =============================
50# REQUIREMENTS
51# =============================
52check_requirements() {
53 if [[ $EUID -eq 0 ]]; then
54 err "Do not run as root"
55 exit 1
56 fi
57 if ! command -v sudo >/dev/null 2>&1; then
58 err "sudo required"
59 exit 1
60 fi
61}
62
63# =============================
64# INSTALLATION FUNCTIONS
65# =============================
66update_system() {
67 $SKIP_PACKAGES && return
68 log "Updating system..."
69 sudo apt-get update -y
70 sudo apt-get upgrade -y
71 ok "System updated"
72}
73
74install_packages() {
75 $SKIP_PACKAGES && return
76 log "Installing core packages..."
77 sudo apt-get install -y \
78 zsh git vim curl wget unzip zip build-essential xz-utils
79 ok "Packages installed"
80}
81
82set_timezone() {
83 log "Setting timezone to Asia/Singapore..."
84 sudo timedatectl set-timezone Asia/Singapore
85 ok "Timezone set to Asia/Singapore"
86}
87
88install_xclip() {
89 local os
90 os="$(detect_os)"
91 [[ "$os" != "ubuntu" && "$os" != "debian" ]] && return 0
92 $SKIP_XCLIP && return 0
93 command -v xclip >/dev/null 2>&1 && ok "xclip already installed" && return 0
94
95 read -r -p "Install xclip? (y/N): " r
96 case "$r" in
97 [Yy]) sudo apt-get install -y xclip; ok "xclip installed" ;;
98 *) log "Skipping xclip installation" ;;
99 esac
100}
101
102configure_git() {
103 $SKIP_GIT_CONFIG && return
104 log "Configuring Git..."
105 read -p "Git name (leave empty to skip): " name
106 read -p "Git email (leave empty to skip): " email
107 [[ -n "$name" ]] && git config --global user.name "$name"
108 [[ -n "$email" ]] && git config --global user.email "$email"
109 ok "Git configured"
110}
111
112install_homebrew() {
113 ! $INSTALL_HOMEBREW && return
114 command -v brew >/dev/null 2>&1 && ok "Homebrew already installed" && return
115 log "Installing Homebrew..."
116 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
117 ok "Homebrew installed"
118}
119
120configure_shell() {
121 $SKIP_SHELL_CHANGE && return
122 log "Changing default shell to zsh..."
123 local zsh_path
124 zsh_path="$(command -v zsh)"
125 grep -qx "$zsh_path" /etc/shells || echo "$zsh_path" | sudo tee -a /etc/shells >/dev/null
126 chsh -s "$zsh_path"
127 ok "Shell changed (requires logout/login to take effect)"
128}
129
130install_oh_my_zsh() {
131 [[ -d "$HOME/.oh-my-zsh" ]] && ok "Oh My Zsh already installed" && return
132 log "Installing Oh My Zsh..."
133 RUNZSH=no CHSH=no KEEP_ZSHRC=yes \
134 sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
135 ok "Oh My Zsh installed"
136}
137
138install_plugins() {
139 log "Installing plugins..."
140 local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins"
141 mkdir -p "$dir"
142 [[ -d "$dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions"
143 [[ -d "$dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting"
144 ok "Plugins installed"
145}
146
147install_theme() {
148 log "Installing Spaceship theme..."
149 local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes"
150 local dir="$themes/spaceship-prompt"
151 mkdir -p "$themes"
152 [[ -d "$dir" ]] || git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1
153 ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme"
154 ok "Theme installed"
155}
156
157download_configs() {
158 log "Downloading custom config files..."
159 local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)"
160 mkdir -p "$backup"
161
162 for f in "${CONFIG_FILES[@]}"; do
163 local url="$GIST_RAW_BASE/$f"
164 local target="$HOME/$f"
165 local tmp="${target}.tmp.$$"
166
167 if [[ -f "$target" ]]; then
168 cp "$target" "$backup/"
169 fi
170
171 log "Fetching $f ..."
172 if curl -fsSL "$url" -o "$tmp"; then
173 mv "$tmp" "$target"
174 else
175 rm -f "$tmp"
176 warn "Failed to download $f"
177 fi
178 done
179
180 ok "Configs downloaded (Backup at $backup)"
181}
182
183update_zshrc() {
184 local zshrc="$HOME/.zshrc"
185 log "Checking .zshrc..."
186
187 if [[ ! -f "$zshrc" ]]; then
188 warn ".zshrc not found. Run option 11 first."
189 return 1
190 fi
191
192 ok ".zshrc already comes from the managed gist."
193 ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias"
194}
195
196switch_shell() {
197 log "Starting Zsh session..."
198 echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}"
199 echo "----------------------------------------"
200 zsh -l
201 echo "----------------------------------------"
202 ok "Returned from Zsh session"
203}
204
205# =============================
206# INTERACTIVE MENU
207# =============================
208show_menu() {
209 echo "==========================================="
210 echo "Zsh Installer - Choose what to do"
211 echo "==========================================="
212 echo " 0) Run ALL steps (1-13)"
213 echo " 1) Update system packages"
214 echo " 2) Install core packages (zsh, git, vim, etc.)"
215 echo " 3) Set Timezone (Asia/Singapore)"
216 echo " 4) Install xclip"
217 echo " 5) Configure Git"
218 echo " 6) Install Homebrew"
219 echo " 7) Configure shell (chsh - sets default shell)"
220 echo " 8) Install Oh My Zsh"
221 echo " 9) Install plugins (autosuggestions, syntax highlighting)"
222 echo "10) Install Spaceship theme"
223 echo "11) Download custom configs (~/.alias, .vimrc, etc.)"
224 echo "12) Check ~/.zshrc load order"
225 echo "13) Switch to Zsh (Temporary Sub-shell)"
226 echo "14) Quit"
227 echo "==========================================="
228}
229
230run_choices() {
231 local input
232 read -p "Select: " input
233 input="${input//,/ }"
234
235 local -a to_run=()
236 local -a to_exclude=()
237
238 for item in $input; do
239 if [[ "$item" == !* ]]; then
240 to_exclude+=("${item:1}")
241 elif [[ "$item" == "0" ]]; then
242 to_run+=(1 2 3 4 5 6 7 8 9 10 11 12 13)
243 else
244 to_run+=("$item")
245 fi
246 done
247
248 for choice in "${to_run[@]}"; do
249 local skip=false
250
251 for ex in "${to_exclude[@]}"; do
252 if [[ "$choice" == "$ex" ]]; then
253 skip=true
254 break
255 fi
256 done
257
258 $skip && continue
259
260 case "$choice" in
261 1) update_system ;;
262 2) install_packages ;;
263 3) set_timezone ;;
264 4) install_xclip ;;
265 5) configure_git ;;
266 6) install_homebrew ;;
267 7) configure_shell ;;
268 8) install_oh_my_zsh ;;
269 9) install_plugins ;;
270 10) install_theme ;;
271 11) download_configs ;;
272 12) update_zshrc ;;
273 13) switch_shell ;;
274 14) log "Exiting..."; exit 0 ;;
275 *) warn "Skipping invalid option: $choice" ;;
276 esac
277 echo
278 done
279}
280
281# =============================
282# MAIN
283# =============================
284main() {
285 check_requirements
286 while true; do
287 show_menu
288 run_choices
289 read -p "Do you want to run more options? (y/n): " again
290 [[ "$again" =~ ^[Yy]$ ]] || break
291 done
292 ok "Zsh installation/configuration complete!"
293}
294
295main "$@"
296
zsh_wsl.sh Eredeti
1#!/bin/bash
2set -euo pipefail
3
4# =============================
5# COLORS & LOGGING
6# =============================
7RED='\033[0;31m'
8GREEN='\033[0;32m'
9YELLOW='\033[1;33m'
10BLUE='\033[0;34m'
11NC='\033[0m'
12
13log() { echo -e "${BLUE}[INFO]${NC} $*"; }
14ok() { echo -e "${GREEN}[OK]${NC} $*"; }
15warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
16err() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
17
18# =============================
19# FLAGS & CONFIG
20# =============================
21SKIP_PACKAGES=false
22SKIP_GIT_CONFIG=false
23SKIP_SHELL_CHANGE=false
24SKIP_XCLIP=false
25INSTALL_HOMEBREW=false
26
27GIST_RAW_BASE="https://gist.githubusercontent.com/weehong/c430fefc6e90428dfe6811e0766decf4/raw"
28CONFIG_FILES=(
29 ".alias"
30 ".func"
31 ".pathrc"
32 ".sourcerc"
33 ".vimrc"
34 ".zshrc"
35)
36
37# =============================
38# PLATFORM DETECTION
39# =============================
40detect_os() {
41 if [ -f /etc/os-release ]; then
42 . /etc/os-release
43 echo "$ID"
44 else
45 echo "unknown"
46 fi
47}
48
49is_wsl() {
50 grep -qi "microsoft" /proc/version 2>/dev/null
51}
52
53# =============================
54# REQUIREMENTS
55# =============================
56check_requirements() {
57 if [[ $EUID -eq 0 ]]; then
58 err "Do not run as root"
59 exit 1
60 fi
61 if ! command -v sudo >/dev/null 2>&1; then
62 err "sudo required"
63 exit 1
64 fi
65 if ! is_wsl; then
66 err "This installer is intended for WSL"
67 exit 1
68 fi
69}
70
71# =============================
72# INSTALLATION FUNCTIONS
73# =============================
74update_system() {
75 $SKIP_PACKAGES && return
76 log "Updating system..."
77 sudo apt-get update -y
78 sudo apt-get upgrade -y
79 ok "System updated"
80}
81
82install_packages() {
83 $SKIP_PACKAGES && return
84 log "Installing core packages..."
85 sudo apt-get install -y \
86 zsh git vim curl wget unzip zip build-essential xz-utils
87 ok "Packages installed"
88}
89
90set_timezone() {
91 log "Checking timezone configuration..."
92 if command -v timedatectl >/dev/null 2>&1 && timedatectl status >/dev/null 2>&1; then
93 sudo timedatectl set-timezone Asia/Singapore
94 ok "Timezone set to Asia/Singapore"
95 return
96 fi
97
98 warn "Skipping timezone change: timedatectl is not available in this WSL environment"
99}
100
101install_xclip() {
102 local os
103 os="$(detect_os)"
104 [[ "$os" != "ubuntu" && "$os" != "debian" ]] && return 0
105 $SKIP_XCLIP && return 0
106 command -v xclip >/dev/null 2>&1 && ok "xclip already installed" && return 0
107
108 read -r -p "Install xclip for Linux/X11 clipboard support? (y/N): " r
109 case "$r" in
110 [Yy]) sudo apt-get install -y xclip; ok "xclip installed" ;;
111 *) log "Skipping xclip installation" ;;
112 esac
113}
114
115configure_git() {
116 $SKIP_GIT_CONFIG && return
117 log "Configuring Git..."
118 read -p "Git name (leave empty to skip): " name
119 read -p "Git email (leave empty to skip): " email
120 [[ -n "$name" ]] && git config --global user.name "$name"
121 [[ -n "$email" ]] && git config --global user.email "$email"
122 ok "Git configured"
123}
124
125install_homebrew() {
126 ! $INSTALL_HOMEBREW && return
127 command -v brew >/dev/null 2>&1 && ok "Homebrew already installed" && return
128 log "Installing Homebrew..."
129 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
130 ok "Homebrew installed"
131}
132
133configure_shell() {
134 $SKIP_SHELL_CHANGE && return
135 log "Changing default shell to zsh..."
136 local zsh_path
137 zsh_path="$(command -v zsh)"
138 grep -qx "$zsh_path" /etc/shells || echo "$zsh_path" | sudo tee -a /etc/shells >/dev/null
139 chsh -s "$zsh_path"
140 ok "Shell changed (open a new WSL session for it to take effect)"
141}
142
143install_oh_my_zsh() {
144 [[ -d "$HOME/.oh-my-zsh" ]] && ok "Oh My Zsh already installed" && return
145 log "Installing Oh My Zsh..."
146 RUNZSH=no CHSH=no KEEP_ZSHRC=yes \
147 sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
148 ok "Oh My Zsh installed"
149}
150
151install_plugins() {
152 log "Installing plugins..."
153 local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins"
154 mkdir -p "$dir"
155 [[ -d "$dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions"
156 [[ -d "$dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting"
157 ok "Plugins installed"
158}
159
160install_theme() {
161 log "Installing Spaceship theme..."
162 local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes"
163 local dir="$themes/spaceship-prompt"
164 mkdir -p "$themes"
165 [[ -d "$dir" ]] || git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1
166 ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme"
167 ok "Theme installed"
168}
169
170download_configs() {
171 log "Downloading custom config files..."
172 local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)"
173 mkdir -p "$backup"
174
175 for f in "${CONFIG_FILES[@]}"; do
176 local url="$GIST_RAW_BASE/$f"
177 local target="$HOME/$f"
178 local tmp="${target}.tmp.$$"
179
180 if [[ -f "$target" ]]; then
181 cp "$target" "$backup/"
182 fi
183
184 log "Fetching $f ..."
185 if curl -fsSL "$url" -o "$tmp"; then
186 mv "$tmp" "$target"
187 else
188 rm -f "$tmp"
189 warn "Failed to download $f"
190 fi
191 done
192
193 ok "Configs downloaded (Backup at $backup)"
194}
195
196update_zshrc() {
197 local zshrc="$HOME/.zshrc"
198 log "Checking .zshrc..."
199
200 if [[ ! -f "$zshrc" ]]; then
201 warn ".zshrc not found. Run option 11 first."
202 return 1
203 fi
204
205 ok ".zshrc already comes from the managed gist."
206 ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias"
207}
208
209switch_shell() {
210 log "Starting Zsh session..."
211 echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}"
212 echo "----------------------------------------"
213 zsh -l
214 echo "----------------------------------------"
215 ok "Returned from Zsh session"
216}
217
218# =============================
219# INTERACTIVE MENU
220# =============================
221show_menu() {
222 echo "==========================================="
223 echo "WSL Zsh Installer - Choose what to do"
224 echo "==========================================="
225 echo " 0) Run ALL steps (1-13)"
226 echo " 1) Update system packages"
227 echo " 2) Install core packages (zsh, git, vim, etc.)"
228 echo " 3) Set Timezone (best effort)"
229 echo " 4) Install xclip"
230 echo " 5) Configure Git"
231 echo " 6) Install Homebrew"
232 echo " 7) Configure shell (chsh - sets default shell)"
233 echo " 8) Install Oh My Zsh"
234 echo " 9) Install plugins (autosuggestions, syntax highlighting)"
235 echo "10) Install Spaceship theme"
236 echo "11) Download custom configs (~/.alias, .vimrc, etc.)"
237 echo "12) Check ~/.zshrc load order"
238 echo "13) Switch to Zsh (Temporary Sub-shell)"
239 echo "14) Quit"
240 echo "==========================================="
241}
242
243run_choices() {
244 local input
245 read -p "Select: " input
246 input="${input//,/ }"
247
248 local -a to_run=()
249 local -a to_exclude=()
250
251 for item in $input; do
252 if [[ "$item" == !* ]]; then
253 to_exclude+=("${item:1}")
254 elif [[ "$item" == "0" ]]; then
255 to_run+=(1 2 3 4 5 6 7 8 9 10 11 12 13)
256 else
257 to_run+=("$item")
258 fi
259 done
260
261 for choice in "${to_run[@]}"; do
262 local skip=false
263
264 for ex in "${to_exclude[@]}"; do
265 if [[ "$choice" == "$ex" ]]; then
266 skip=true
267 break
268 fi
269 done
270
271 $skip && continue
272
273 case "$choice" in
274 1) update_system ;;
275 2) install_packages ;;
276 3) set_timezone ;;
277 4) install_xclip ;;
278 5) configure_git ;;
279 6) install_homebrew ;;
280 7) configure_shell ;;
281 8) install_oh_my_zsh ;;
282 9) install_plugins ;;
283 10) install_theme ;;
284 11) download_configs ;;
285 12) update_zshrc ;;
286 13) switch_shell ;;
287 14) log "Exiting..."; exit 0 ;;
288 *) warn "Skipping invalid option: $choice" ;;
289 esac
290 echo
291 done
292}
293
294# =============================
295# MAIN
296# =============================
297main() {
298 check_requirements
299 while true; do
300 show_menu
301 run_choices
302 read -p "Do you want to run more options? (y/n): " again
303 [[ "$again" =~ ^[Yy]$ ]] || break
304 done
305 ok "WSL Zsh installation/configuration complete!"
306}
307
308main "$@"
309