最終更新 2 weeks ago

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

修正履歴 bdfffd02e380d0b156b79932c217743c0171a91e

README.md Raw

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