Last active 2 weeks ago

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

weehong revised this gist 1 month ago. Go to revision

3 files changed, 15 insertions, 9 deletions

zsh_macos.sh

@@ -87,7 +87,9 @@ download_configs() {
87 87 mkdir -p "$backup"
88 88
89 89 for f in "${CONFIG_FILES[@]}"; do
90 - local url="$GIST_RAW_BASE/$f"
90 + # Strip the leading dot for the download URL
91 + local remote_file="${f#.}"
92 + local url="$GIST_RAW_BASE/$remote_file"
91 93 local target="$HOME/$f"
92 94 local tmp="${target}.tmp.$$"
93 95
@@ -95,12 +97,12 @@ download_configs() {
95 97 cp "$target" "$backup/"
96 98 fi
97 99
98 - log "Fetching $f ..."
100 + log "Fetching $remote_file -> $f ..."
99 101 if curl -fsSL "$url" -o "$tmp"; then
100 102 mv "$tmp" "$target"
101 103 else
102 104 rm -f "$tmp"
103 - warn "Failed to download $f"
105 + warn "Failed to download $remote_file"
104 106 fi
105 107 done
106 108

zsh_ubuntu.sh

@@ -134,7 +134,9 @@ download_configs() {
134 134 mkdir -p "$backup"
135 135
136 136 for f in "${CONFIG_FILES[@]}"; do
137 - local url="$GIST_RAW_BASE/$f"
137 + # Strip the leading dot for the download URL
138 + local remote_file="${f#.}"
139 + local url="$GIST_RAW_BASE/$remote_file"
138 140 local target="$HOME/$f"
139 141 local tmp="${target}.tmp.$$"
140 142
@@ -142,12 +144,12 @@ download_configs() {
142 144 cp "$target" "$backup/"
143 145 fi
144 146
145 - log "Fetching $f ..."
147 + log "Fetching $remote_file -> $f ..."
146 148 if curl -fsSL "$url" -o "$tmp"; then
147 149 mv "$tmp" "$target"
148 150 else
149 151 rm -f "$tmp"
150 - warn "Failed to download $f"
152 + warn "Failed to download $remote_file"
151 153 fi
152 154 done
153 155

zsh_wsl.sh

@@ -147,7 +147,9 @@ download_configs() {
147 147 mkdir -p "$backup"
148 148
149 149 for f in "${CONFIG_FILES[@]}"; do
150 - local url="$GIST_RAW_BASE/$f"
150 + # Strip the leading dot for the download URL
151 + local remote_file="${f#.}"
152 + local url="$GIST_RAW_BASE/$remote_file"
151 153 local target="$HOME/$f"
152 154 local tmp="${target}.tmp.$$"
153 155
@@ -155,12 +157,12 @@ download_configs() {
155 157 cp "$target" "$backup/"
156 158 fi
157 159
158 - log "Fetching $f ..."
160 + log "Fetching $remote_file -> $f ..."
159 161 if curl -fsSL "$url" -o "$tmp"; then
160 162 mv "$tmp" "$target"
161 163 else
162 164 rm -f "$tmp"
163 - warn "Failed to download $f"
165 + warn "Failed to download $remote_file"
164 166 fi
165 167 done
166 168

weehong revised this gist 1 month ago. Go to revision

3 files changed, 4 insertions, 4 deletions

zsh_macos.sh

@@ -18,7 +18,7 @@ err() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
18 18 # =============================
19 19 # CONFIG
20 20 # =============================
21 - GIST_RAW_BASE="https://gist.githubusercontent.com/weehong/c430fefc6e90428dfe6811e0766decf4/raw"
21 + GIST_RAW_BASE="https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD"
22 22
23 23 CONFIG_FILES=(
24 24 ".alias"
@@ -209,4 +209,4 @@ main() {
209 209 ok "macOS configuration complete!"
210 210 }
211 211
212 - main "$@"
212 + main "$@"

zsh_ubuntu.sh

@@ -22,7 +22,7 @@ SKIP_PACKAGES=false
22 22 SKIP_SHELL_CHANGE=false
23 23 INSTALL_HOMEBREW=false
24 24
25 - GIST_RAW_BASE="https://gist.githubusercontent.com/weehong/c430fefc6e90428dfe6811e0766decf4/raw"
25 + GIST_RAW_BASE="https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD"
26 26 CONFIG_FILES=(
27 27 ".alias"
28 28 ".func"

zsh_wsl.sh

@@ -22,7 +22,7 @@ SKIP_PACKAGES=false
22 22 SKIP_SHELL_CHANGE=false
23 23 INSTALL_HOMEBREW=false
24 24
25 - GIST_RAW_BASE="https://gist.githubusercontent.com/weehong/c430fefc6e90428dfe6811e0766decf4/raw"
25 + GIST_RAW_BASE="https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD"
26 26 CONFIG_FILES=(
27 27 ".alias"
28 28 ".func"

weehong revised this gist 1 month ago. Go to revision

6 files changed, 0 insertions, 0 deletions

.alias renamed to alias

File renamed without changes

.func renamed to func

File renamed without changes

.pathrc renamed to pathrc

File renamed without changes

.sourcerc renamed to sourcerc

File renamed without changes

.vimrc renamed to vimrc

File renamed without changes

.zshrc renamed to zshrc

File renamed without changes

weehong revised this gist 1 month ago. Go to revision

6 files changed, 702 insertions

.alias(file created)

@@ -0,0 +1,28 @@
1 + # =============================================================================
2 + # OS-SPECIFIC ALIASES
3 + # =============================================================================
4 + if [[ "$OSTYPE" == "linux-gnu"* ]] && command -v apt-get >/dev/null 2>&1; then
5 + # Linux Only System update & cleanup
6 + alias uu='sudo apt-get update && \
7 + sudo apt-get upgrade -y && \
8 + sudo apt-get full-upgrade -y && \
9 + sudo apt-get autoremove -y && \
10 + sudo apt-get autoclean -y && \
11 + sudo apt-get clean'
12 + elif [[ "$OSTYPE" == "darwin"* ]]; then
13 + # macOS Only
14 + alias flushdns='sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder'
15 + fi
16 +
17 + # =============================================================================
18 + # UNIVERSAL GIT ALIASES (Fixed: Removed broken "$@" from aliases)
19 + # =============================================================================
20 + alias gph='git push'
21 + alias gco='git checkout'
22 + alias gbh='git branch'
23 + alias gmt='git commit'
24 + alias gpl='git pull'
25 + alias grb='git rebase'
26 + alias grt='git reset'
27 + alias gst='git status'
28 + alias grmrf='git checkout -- . && git clean -fd'

.func(file created)

@@ -0,0 +1,231 @@
1 + # =============================================================================
2 + # CUSTOM FUNCTIONS
3 + # =============================================================================
4 +
5 + # -----------------------------------------------------------------------------
6 + # Function: clip
7 + # -----------------------------------------------------------------------------
8 + clip() {
9 + local cmd
10 + local args=()
11 +
12 + if command -v pbcopy >/dev/null 2>&1; then
13 + cmd="pbcopy" # macOS
14 + elif grep -qi "microsoft" /proc/version 2>/dev/null && command -v clip.exe >/dev/null 2>&1; then
15 + cmd="clip.exe" # WSL
16 + elif [ "$XDG_SESSION_TYPE" = "wayland" ] && command -v wl-copy >/dev/null 2>&1; then
17 + cmd="wl-copy" # Linux Wayland
18 + elif command -v xclip >/dev/null 2>&1; then
19 + cmd="xclip" # Linux X11 (Fallback 1)
20 + args=("-selection" "clipboard")
21 + elif command -v xsel >/dev/null 2>&1; then
22 + cmd="xsel" # Linux X11 (Fallback 2)
23 + args=("--clipboard" "--input")
24 + else
25 + printf "Error: No supported clipboard utility found.\n" >&2
26 + return 1
27 + fi
28 +
29 + if [ $# -gt 0 ]; then
30 + if [ -f "$1" ]; then
31 + "$cmd" "${args[@]}" < "$1"
32 + echo "Copied contents of '$1' to clipboard."
33 + else
34 + printf "Error: File '%s' not found.\n" "$1" >&2
35 + return 1
36 + fi
37 + else
38 + "$cmd" "${args[@]}"
39 + fi
40 + }
41 +
42 + # -----------------------------------------------------------------------------
43 + # Function: open_file (Cross-platform file/directory opener)
44 + # -----------------------------------------------------------------------------
45 + open_file() {
46 + local target="${1:-.}"
47 +
48 + if [[ "$OSTYPE" == "darwin"* ]]; then
49 + # Use native macOS open
50 + command open "$target"
51 + elif grep -qi "microsoft" /proc/version 2>/dev/null; then
52 + # Use WSL Explorer
53 + if command -v wslpath >/dev/null 2>&1 && command -v explorer.exe >/dev/null 2>&1; then
54 + explorer.exe "$(wslpath -w "$target")"
55 + else
56 + printf "Error: 'wslpath' or 'explorer.exe' not found. Windows interop might be disabled.\n" >&2
57 + return 1
58 + fi
59 + elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
60 + # Use Linux xdg-open
61 + if command -v xdg-open >/dev/null 2>&1; then
62 + xdg-open "$target"
63 + else
64 + printf "Error: 'xdg-open' not found.\n" >&2
65 + return 1
66 + fi
67 + fi
68 + }
69 + alias open='open_file'
70 +
71 + # -----------------------------------------------------------------------------
72 + # Function: clear_history
73 + # -----------------------------------------------------------------------------
74 + clear_history() {
75 + # Clears the history file and reloads the current session's history for Zsh
76 + >| "$HISTFILE" && fc -R
77 + echo "History cleared."
78 + }
79 +
80 + # -----------------------------------------------------------------------------
81 + # Function: claude
82 + # -----------------------------------------------------------------------------
83 + claude() {
84 + # Run the check in a subshell, unsetting the function first so it only finds the binary
85 + if ! whence -p claude >/dev/null 2>&1; then
86 + printf "Error: 'claude' CLI is not installed or not in your PATH.\n" >&2
87 + return 1
88 + fi
89 +
90 + if [[ "$1" == "--yolo" ]]; then
91 + shift
92 + command claude --dangerously-skip-permissions "$@"
93 + return $?
94 + fi
95 +
96 + command claude "$@"
97 + }
98 +
99 + # -----------------------------------------------------------------------------
100 + # Function: create
101 + # -----------------------------------------------------------------------------
102 + create() {
103 + if ! command -v install >/dev/null 2>&1; then
104 + printf "Error: 'install' coreutil is not available on this system.\n" >&2
105 + return 1
106 + fi
107 +
108 + if [ $# -eq 0 ]; then
109 + printf "Usage: create <file> [file ...]\n" >&2
110 + return 2
111 + fi
112 +
113 + for p in "$@"; do
114 + if [ "${p#\~}" != "$p" ]; then
115 + p="${HOME}${p#\~}"
116 + fi
117 +
118 + if [ -z "$p" ] || [ "$p" = "/" ]; then
119 + printf "create: refusing to operate on '%s'\n" "$p" >&2
120 + return 1
121 + fi
122 +
123 + if [ -e "$p" ]; then
124 + printf "create: '%s' already exists. Skipping.\n" "$p" >&2
125 + continue
126 + fi
127 +
128 + if ! install -D /dev/null "$p"; then
129 + printf "create: failed to create '%s'\n" "$p" >&2
130 + return 1
131 + fi
132 + done
133 + return 0
134 + }
135 +
136 + # -----------------------------------------------------------------------------
137 + # Function: check_port
138 + # -----------------------------------------------------------------------------
139 + check_port() {
140 + local PORT=$1
141 +
142 + if [ -z "$PORT" ]; then
143 + printf "Usage: check_port <port_number>\n" >&2
144 + return 1
145 + fi
146 +
147 + if [[ "$OSTYPE" == "darwin"* ]]; then
148 + if lsof -i :"$PORT" >/dev/null 2>&1; then
149 + echo "Port $PORT is IN USE"
150 + lsof -i :"$PORT"
151 + else
152 + echo "Port $PORT is FREE"
153 + fi
154 + else
155 + if ! command -v ss >/dev/null 2>&1; then
156 + printf "Error: 'ss' command not found. This function requires Linux iproute2 utilities.\n" >&2
157 + return 1
158 + fi
159 +
160 + if sudo ss -tulnp | grep -q ":$PORT "; then
161 + echo "Port $PORT is IN USE"
162 + sudo ss -tulnp | grep ":$PORT "
163 + else
164 + echo "Port $PORT is FREE"
165 + fi
166 + fi
167 + }
168 +
169 + # -----------------------------------------------------------------------------
170 + # Function: append_path
171 + # -----------------------------------------------------------------------------
172 + append_path() {
173 + local dir="$1"
174 + if [ -d "$dir" ]; then
175 + case ":$PATH:" in
176 + *":$dir:"*) ;; # Already in PATH
177 + *) PATH="$PATH:$dir" ;;
178 + esac
179 + elif [ "${SUPPRESS_WARNINGS:-0}" -ne 1 ]; then
180 + echo "Warning: $dir does not exist." >&2
181 + fi
182 + }
183 +
184 + # -----------------------------------------------------------------------------
185 + # Function: add_path_to_config
186 + # -----------------------------------------------------------------------------
187 + add_path_to_config() {
188 + local new_path="$1"
189 + local config_file="$HOME/.bashrc"
190 +
191 + if [[ "$SHELL" == *"zsh"* ]]; then
192 + config_file="$HOME/.zshrc"
193 + fi
194 +
195 + if [ -z "$new_path" ]; then
196 + printf "Usage: addpath <directory>\n" >&2
197 + return 1
198 + fi
199 +
200 + new_path="${new_path/#\~/$HOME}"
201 +
202 + if [ ! -d "$new_path" ]; then
203 + printf "Warning: '%s' does not exist.\n" "$new_path" >&2
204 + printf "Do you still want to add it to your config? (y/N) "
205 + read -r -k 1 REPLY
206 + echo
207 + if [[ ! $REPLY =~ ^[Yy]$ ]]; then
208 + return 1
209 + fi
210 + fi
211 +
212 + if grep -Fq "append_path \"$new_path\"" "$config_file" || grep -Fq "append_path '$new_path'" "$config_file"; then
213 + printf "Notice: '%s' is already in your %s.\n" "$new_path" "$config_file"
214 + return 0
215 + fi
216 +
217 + if grep -q "^export PATH" "$config_file"; then
218 + awk -v new_cmd="append_path \"$new_path\"" '/^export PATH/{print new_cmd}1' "$config_file" > "${config_file}.tmp" && mv "${config_file}.tmp" "$config_file"
219 + else
220 + echo "append_path \"$new_path\"" >> "$config_file"
221 + echo "export PATH" >> "$config_file"
222 + fi
223 +
224 + printf "✅ Success: Added '%s' to %s\n" "$new_path" "$config_file"
225 +
226 + if type append_path >/dev/null 2>&1; then
227 + append_path "$new_path"
228 + export PATH
229 + printf "🚀 Path is now active in your current session!\n"
230 + fi
231 + }

.pathrc(file created)

@@ -0,0 +1,230 @@
1 + # =============================================================================
2 + # CUSTOM FUNCTIONS
3 + # =============================================================================
4 +
5 + # -----------------------------------------------------------------------------
6 + # Function: clip
7 + # -----------------------------------------------------------------------------
8 + clip() {
9 + local cmd
10 + local args=()
11 +
12 + if command -v pbcopy >/dev/null 2>&1; then
13 + cmd="pbcopy" # macOS
14 + elif grep -qi "microsoft" /proc/version 2>/dev/null && command -v clip.exe >/dev/null 2>&1; then
15 + cmd="clip.exe" # WSL
16 + elif [ "$XDG_SESSION_TYPE" = "wayland" ] && command -v wl-copy >/dev/null 2>&1; then
17 + cmd="wl-copy" # Linux Wayland
18 + elif command -v xclip >/dev/null 2>&1; then
19 + cmd="xclip" # Linux X11 (Fallback 1)
20 + args=("-selection" "clipboard")
21 + elif command -v xsel >/dev/null 2>&1; then
22 + cmd="xsel" # Linux X11 (Fallback 2)
23 + args=("--clipboard" "--input")
24 + else
25 + printf "Error: No supported clipboard utility found.\n" >&2
26 + return 1
27 + fi
28 +
29 + if [ $# -gt 0 ]; then
30 + if [ -f "$1" ]; then
31 + "$cmd" "${args[@]}" < "$1"
32 + echo "Copied contents of '$1' to clipboard."
33 + else
34 + printf "Error: File '%s' not found.\n" "$1" >&2
35 + return 1
36 + fi
37 + else
38 + "$cmd" "${args[@]}"
39 + fi
40 + }
41 +
42 + # -----------------------------------------------------------------------------
43 + # Function: open (Cross-platform file/directory opener)
44 + # -----------------------------------------------------------------------------
45 + open_file() {
46 + local target="${1:-.}"
47 +
48 + if [[ "$OSTYPE" == "darwin"* ]]; then
49 + # Use native macOS open
50 + command open "$target"
51 + elif grep -qi "microsoft" /proc/version 2>/dev/null; then
52 + # Use WSL Explorer
53 + if command -v wslpath >/dev/null 2>&1 && command -v explorer.exe >/dev/null 2>&1; then
54 + explorer.exe "$(wslpath -w "$target")"
55 + else
56 + printf "Error: 'wslpath' or 'explorer.exe' not found. Windows interop might be disabled.\n" >&2
57 + return 1
58 + fi
59 + elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
60 + # Use Linux xdg-open
61 + if command -v xdg-open >/dev/null 2>&1; then
62 + xdg-open "$target"
63 + else
64 + printf "Error: 'xdg-open' not found.\n" >&2
65 + return 1
66 + fi
67 + fi
68 + }
69 + alias open='open_file'
70 +
71 + # -----------------------------------------------------------------------------
72 + # Function: clear_history
73 + # -----------------------------------------------------------------------------
74 + clear_history() {
75 + history -p
76 + }
77 +
78 + # -----------------------------------------------------------------------------
79 + # Function: claude
80 + # -----------------------------------------------------------------------------
81 + claude() {
82 + if ! command -v claude >/dev/null 2>&1; then
83 + printf "Error: 'claude' CLI is not installed or not in your PATH.\n" >&2
84 + return 1
85 + fi
86 +
87 + if [[ "$1" == "--yolo" ]]; then
88 + shift
89 + command claude --dangerously-skip-permissions "$@"
90 + return $?
91 + fi
92 +
93 + command claude "$@"
94 + }
95 +
96 + # -----------------------------------------------------------------------------
97 + # Function: create
98 + # -----------------------------------------------------------------------------
99 + create() {
100 + if ! command -v install >/dev/null 2>&1; then
101 + printf "Error: 'install' coreutil is not available on this system.\n" >&2
102 + return 1
103 + fi
104 +
105 + if [ $# -eq 0 ]; then
106 + printf "Usage: create <file> [file ...]\n" >&2
107 + return 2
108 + fi
109 +
110 + for p in "$@"; do
111 + if [ "${p#\~}" != "$p" ]; then
112 + p="${HOME}${p#\~}"
113 + fi
114 +
115 + if [ -z "$p" ] || [ "$p" = "/" ]; then
116 + printf "create: refusing to operate on '%s'\n" "$p" >&2
117 + return 1
118 + fi
119 +
120 + if [ -e "$p" ]; then
121 + printf "create: '%s' already exists. Skipping.\n" "$p" >&2
122 + continue
123 + fi
124 +
125 + if ! install -D /dev/null "$p"; then
126 + printf "create: failed to create '%s'\n" "$p" >&2
127 + return 1
128 + fi
129 + done
130 + return 0
131 + }
132 +
133 + # -----------------------------------------------------------------------------
134 + # Function: check_port
135 + # -----------------------------------------------------------------------------
136 + check_port() {
137 + local PORT=$1
138 +
139 + if [ -z "$PORT" ]; then
140 + printf "Usage: check_port <port_number>\n" >&2
141 + return 1
142 + fi
143 +
144 + if [[ "$OSTYPE" == "darwin"* ]]; then
145 + if lsof -i :"$PORT" >/dev/null 2>&1; then
146 + echo "Port $PORT is IN USE"
147 + lsof -i :"$PORT"
148 + else
149 + echo "Port $PORT is FREE"
150 + fi
151 + else
152 + if ! command -v ss >/dev/null 2>&1; then
153 + printf "Error: 'ss' command not found. This function requires Linux iproute2 utilities.\n" >&2
154 + return 1
155 + fi
156 +
157 + if sudo ss -tulnp | grep -q ":$PORT "; then
158 + echo "Port $PORT is IN USE"
159 + sudo ss -tulnp | grep ":$PORT "
160 + else
161 + echo "Port $PORT is FREE"
162 + fi
163 + fi
164 + }
165 +
166 + # -----------------------------------------------------------------------------
167 + # Function: append_path
168 + # -----------------------------------------------------------------------------
169 + append_path() {
170 + local dir="$1"
171 + if [ -d "$dir" ]; then
172 + case ":$PATH:" in
173 + *":$dir:"*) ;; # Already in PATH
174 + *) PATH="$PATH:$dir" ;;
175 + esac
176 + elif [ "${SUPPRESS_WARNINGS:-0}" -ne 1 ]; then
177 + echo "Warning: $dir does not exist." >&2
178 + fi
179 + }
180 +
181 + # -----------------------------------------------------------------------------
182 + # Function: add_path_to_config
183 + # -----------------------------------------------------------------------------
184 + add_path_to_config() {
185 + local new_path="$1"
186 + local config_file="$HOME/.bashrc"
187 +
188 + if [[ "$SHELL" == *"zsh"* ]]; then
189 + config_file="$HOME/.zshrc"
190 + fi
191 +
192 + if [ -z "$new_path" ]; then
193 + printf "Usage: addpath <directory>\n" >&2
194 + return 1
195 + fi
196 +
197 + new_path="${new_path/#\~/$HOME}"
198 +
199 + if [ ! -d "$new_path" ]; then
200 + printf "Warning: '%s' does not exist.\n" "$new_path" >&2
201 + read -p "Do you still want to add it to your config? (y/N) " -n 1 -r
202 + echo
203 + if [[ ! $REPLY =~ ^[Yy]$ ]]; then
204 + return 1
205 + fi
206 + fi
207 +
208 + if grep -Fq "append_path \"$new_path\"" "$config_file" || grep -Fq "append_path '$new_path'" "$config_file"; then
209 + printf "Notice: '%s' is already in your %s.\n" "$new_path" "$config_file"
210 + return 0
211 + fi
212 +
213 + if grep -q "^export PATH" "$config_file"; then
214 + awk -v new_cmd="append_path \"$new_path\"" '/^export PATH/{print new_cmd}1' "$config_file" > "${config_file}.tmp" && mv "${config_file}.tmp" "$config_file"
215 + else
216 + echo "append_path \"$new_path\"" >> "$config_file"
217 + echo "export PATH" >> "$config_file"
218 + fi
219 +
220 + printf "✅ Success: Added '%s' to %s\n" "$new_path" "$config_file"
221 +
222 + if type append_path >/dev/null 2>&1; then
223 + append_path "$new_path"
224 + export PATH
225 + printf "🚀 Path is now active in your current session!\n"
226 + fi
227 + }
228 +
229 + append_path "$HOME/.local/bin"
230 + export PATH

.sourcerc(file created)

@@ -0,0 +1,33 @@
1 + # =============================================================================
2 + # FILE: ~/.sourcerc
3 + # Description: Initializes third-party package managers and Oh My Zsh.
4 + # =============================================================================
5 +
6 + # Source the SDKMAN initialization script if it exists and is not empty
7 + if [[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]]; then
8 + source "$HOME/.sdkman/bin/sdkman-init.sh"
9 + fi
10 +
11 + # Source the NVM initialization script if it exists and is not empty
12 + if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
13 + source "$HOME/.nvm/nvm.sh"
14 + fi
15 +
16 + # ==========================================
17 + # CLAUDE CODE / AI GATEWAY
18 + # ==========================================
19 + export ANTHROPIC_BASE_URL="https://gateway.ai.cloudflare.com/v1/9a71825e3842e918e0dff9ad84f50484/claude-code-gateway/anthropic"
20 +
21 + # Source Oh My Zsh if it exists and is not empty
22 + # NOTE: ZSH_THEME and plugins must be defined before this runs!
23 + if [[ -s "$HOME/.oh-my-zsh/oh-my-zsh.sh" ]]; then
24 + source "$HOME/.oh-my-zsh/oh-my-zsh.sh"
25 + else
26 + echo "Warning: Oh My Zsh not found or is empty."
27 + fi
28 + # ==========================================
29 + # NVM (Node Version Manager)
30 + # ==========================================
31 + export NVM_DIR="$HOME/.nvm"
32 + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
33 + [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

.vimrc(file created)

@@ -0,0 +1,146 @@
1 + " Enable line numbers
2 + set number
3 +
4 + " Enable relative line numbers
5 + set relativenumber
6 +
7 + " Enable syntax highlighting
8 + syntax on
9 +
10 + " Set colorscheme
11 + colorscheme slate
12 +
13 + " Enable file type detection and plugins
14 + filetype plugin indent on
15 +
16 + " Set the tab width to 4 spaces
17 + set tabstop=4
18 + set shiftwidth=4
19 + set expandtab
20 +
21 + " Enable auto-indentation
22 + set autoindent
23 + set smartindent
24 +
25 + " Highlight current line
26 + set cursorline
27 +
28 + " Show matching parentheses
29 + set showmatch
30 +
31 + " Enable line wrapping
32 + set wrap
33 +
34 + " Enable mouse support
35 + set mouse=a
36 +
37 + " Enable clipboard access
38 + set clipboard=unnamedplus
39 +
40 + " Disable swap file
41 + set noswapfile
42 +
43 + " Enable incremental search
44 + set incsearch
45 +
46 + " Ignore case in search
47 + set ignorecase
48 +
49 + " Override ignorecase if search contains capital letters
50 + set smartcase
51 +
52 + " Display line and column number of the cursor position
53 + set ruler
54 +
55 + " Set the status line at the bottom
56 + set laststatus=2
57 +
58 + " Show command in bottom bar
59 + set showcmd
60 +
61 + " Set command height
62 + set cmdheight=2
63 +
64 + " Set history lines
65 + set history=1000
66 +
67 + " Disable backup file
68 + set nobackup
69 +
70 + " Enable persistent undo
71 + set undofile
72 +
73 + " Set maximum number of undo levels
74 + set undolevels=1000
75 +
76 + " Set undo directory
77 + if has("persistent_undo")
78 + silent !mkdir ~/.vim/undodir > /dev/null 2>&1
79 + set undodir=~/.vim/undodir
80 + endif
81 +
82 + " Set search highlighting
83 + set hlsearch
84 +
85 + " Enable visual bell
86 + set visualbell
87 +
88 + " Set default file encoding
89 + set encoding=utf-8
90 +
91 + " Set the leader key to space
92 + let mapleader = " "
93 +
94 + " Map <Leader>w to save the file
95 + nnoremap <Leader>w :w<CR>
96 +
97 + " Map <Leader>q to quit
98 + nnoremap <Leader>q :q<CR>
99 +
100 + " Map <Leader>x to save and quit
101 + nnoremap <Leader>x :wq<CR>
102 +
103 + " Enable folding
104 + set foldmethod=syntax
105 + set foldlevelstart=99
106 +
107 + " Enable line wrapping at 80 characters
108 + set textwidth=80
109 + set colorcolumn=80
110 +
111 + " Add some basic key mappings
112 + " Map jj to escape insert mode
113 + inoremap jj <Esc>
114 +
115 + " Map <Leader>n to toggle line numbers
116 + nnoremap <Leader>n :set number!<CR>
117 +
118 + " Map <Leader>r to toggle relative line numbers
119 + nnoremap <Leader>r :set relativenumber!<CR>
120 +
121 + " Configure plugins (if you use a plugin manager like vim-plug)
122 + " Example with vim-plug:
123 + " call plug#begin('~/.vim/plugged')
124 + " Plug 'tpope/vim-sensible'
125 + " Plug 'preservim/nerdtree'
126 + " Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
127 + " Plug 'airblade/vim-gitgutter'
128 + " call plug#end()
129 +
130 + " NERDTree key mappings
131 + " nnoremap <C-n> :NERDTreeToggle<CR>
132 +
133 + " Enable automatic hard wrapping at textwidth (80 chars)
134 + set formatoptions+=t " Auto-wrap text using textwidth
135 + set formatoptions+=c " Auto-wrap comments using textwidth
136 + set formatoptions+=r " Continue comments when pressing Enter
137 + set formatoptions+=o " Continue comments when using 'o' or 'O'
138 + set formatoptions+=q " Allow formatting of comments with 'gq'
139 + set formatoptions+=n " Recognize numbered lists
140 + set formatoptions+=l " Don't break lines that were already long
141 +
142 + " Enable syntax highlighting
143 + syntax on
144 +
145 + " Increase memory limit for complex syntax parsing (Prevents E363)
146 + set maxmempattern=20000

.zshrc(file created)

@@ -0,0 +1,34 @@
1 + # =============================================================================
2 + # 1. ZSH THEME & PLUGINS (Must be defined before Oh My Zsh loads)
3 + # =============================================================================
4 + export ZSH="$HOME/.oh-my-zsh"
5 + ZSH_THEME="spaceship"
6 +
7 + SPACESHIP_PROMPT_ORDER=( user dir git exec_time line_sep jobs exit_code char )
8 + SPACESHIP_USER_SHOW=always
9 + SPACESHIP_PROMPT_SEPARATE_LINE=true
10 + SPACESHIP_PROMPT_ADD_NEWLINE=true
11 + SPACESHIP_CHAR_SYMBOL="❯"
12 + SPACESHIP_CHAR_SUFFIX=" "
13 +
14 + plugins=(git zsh-syntax-highlighting zsh-autosuggestions)
15 +
16 + # =============================================================================
17 + # 2. THIRD-PARTY INITIALIZATION (SDKMAN, NVM, Oh My Zsh)
18 + # =============================================================================
19 + [[ -s "$HOME/.sourcerc" ]] && source "$HOME/.sourcerc"
20 +
21 + # =============================================================================
22 + # 3. CUSTOM OVERRIDES (Functions must load before Path Management)
23 + # =============================================================================
24 + [[ -s "$HOME/.func" ]] && source "$HOME/.func"
25 +
26 + # =============================================================================
27 + # 4. PATH MANAGEMENT (Relies on append_path from .func)
28 + # =============================================================================
29 + [[ -s "$HOME/.pathrc" ]] && source "$HOME/.pathrc"
30 +
31 + # =============================================================================
32 + # 5. ALIASES (Loaded dead last so YOUR code always wins over Oh My Zsh)
33 + # =============================================================================
34 + [[ -s "$HOME/.alias" ]] && source "$HOME/.alias"

weehong revised this gist 1 month ago. Go to revision

3 files changed, 57 insertions, 99 deletions

zsh_macos.sh

@@ -42,20 +42,6 @@ check_requirements() {
42 42 # =============================
43 43 # INSTALLATION FUNCTIONS
44 44 # =============================
45 - configure_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 -
59 45 install_oh_my_zsh() {
60 46 if [[ -d "$HOME/.oh-my-zsh" ]]; then
61 47 ok "Oh My Zsh already installed"
@@ -151,14 +137,13 @@ show_menu() {
151 137 echo "macOS Zsh Setup - Choose what to do"
152 138 echo "==========================================="
153 139 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"
140 + echo " 1) Install Oh My Zsh"
141 + echo " 2) Install plugins (autosuggestions, syntax highlighting)"
142 + echo " 3) Install Spaceship theme"
143 + echo " 4) Download custom configs (~/.alias, .func, .vimrc, etc.)"
144 + echo " 5) Check ~/.zshrc load order"
145 + echo " 6) Switch to Zsh (Temporary Sub-shell)"
146 + echo " 7) Quit"
162 147 echo "==========================================="
163 148 }
164 149
@@ -174,7 +159,7 @@ run_choices() {
174 159 if [[ "$item" == !* ]]; then
175 160 to_exclude+=("${item:1}")
176 161 elif [[ "$item" == "0" ]]; then
177 - to_run+=(1 2 3 4 5 6 7)
162 + to_run+=(1 2 3 4 5 6)
178 163 else
179 164 to_run+=("$item")
180 165 fi
@@ -196,14 +181,13 @@ run_choices() {
196 181 $skip && continue
197 182
198 183 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 ;;
184 + 1) install_oh_my_zsh ;;
185 + 2) install_plugins ;;
186 + 3) install_theme ;;
187 + 4) download_configs ;;
188 + 5) update_zshrc ;;
189 + 6) switch_shell ;;
190 + 7) exit 0 ;;
207 191 *) warn "Skipping invalid option: $choice" ;;
208 192 esac
209 193 echo

zsh_ubuntu.sh

@@ -19,7 +19,6 @@ err() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
19 19 # FLAGS & CONFIG
20 20 # =============================
21 21 SKIP_PACKAGES=false
22 - SKIP_GIT_CONFIG=false
23 22 SKIP_SHELL_CHANGE=false
24 23 INSTALL_HOMEBREW=false
25 24
@@ -84,16 +83,6 @@ set_timezone() {
84 83 ok "Timezone set to Asia/Singapore"
85 84 }
86 85
87 - configure_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 -
97 86 install_homebrew() {
98 87 ! $INSTALL_HOMEBREW && return
99 88 command -v brew >/dev/null 2>&1 && ok "Homebrew already installed" && return
@@ -170,7 +159,7 @@ update_zshrc() {
170 159 log "Checking .zshrc..."
171 160
172 161 if [[ ! -f "$zshrc" ]]; then
173 - warn ".zshrc not found. Run option 10 first."
162 + warn ".zshrc not found. Run option 9 first."
174 163 return 1
175 164 fi
176 165
@@ -194,20 +183,19 @@ show_menu() {
194 183 echo "==========================================="
195 184 echo "Zsh Installer - Choose what to do"
196 185 echo "==========================================="
197 - echo " 0) Run ALL steps (1-12)"
186 + echo " 0) Run ALL steps (1-11)"
198 187 echo " 1) Update system packages"
199 188 echo " 2) Install core packages (zsh, git, vim, etc.)"
200 189 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"
190 + echo " 4) Install Homebrew"
191 + echo " 5) Configure shell (chsh - sets default shell)"
192 + echo " 6) Install Oh My Zsh"
193 + echo " 7) Install plugins (autosuggestions, syntax highlighting)"
194 + echo " 8) Install Spaceship theme"
195 + echo " 9) Download custom configs (~/.alias, .vimrc, etc.)"
196 + echo "10) Check ~/.zshrc load order"
197 + echo "11) Switch to Zsh (Temporary Sub-shell)"
198 + echo "12) Quit"
211 199 echo "==========================================="
212 200 }
213 201
@@ -223,7 +211,7 @@ run_choices() {
223 211 if [[ "$item" == !* ]]; then
224 212 to_exclude+=("${item:1}")
225 213 elif [[ "$item" == "0" ]]; then
226 - to_run+=(1 2 3 4 5 6 7 8 9 10 11 12)
214 + to_run+=(1 2 3 4 5 6 7 8 9 10 11)
227 215 else
228 216 to_run+=("$item")
229 217 fi
@@ -245,16 +233,15 @@ run_choices() {
245 233 1) update_system ;;
246 234 2) install_packages ;;
247 235 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 ;;
236 + 4) install_homebrew ;;
237 + 5) configure_shell ;;
238 + 6) install_oh_my_zsh ;;
239 + 7) install_plugins ;;
240 + 8) install_theme ;;
241 + 9) download_configs ;;
242 + 10) update_zshrc ;;
243 + 11) switch_shell ;;
244 + 12) log "Exiting..."; exit 0 ;;
258 245 *) warn "Skipping invalid option: $choice" ;;
259 246 esac
260 247 echo

zsh_wsl.sh

@@ -19,7 +19,6 @@ err() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
19 19 # FLAGS & CONFIG
20 20 # =============================
21 21 SKIP_PACKAGES=false
22 - SKIP_GIT_CONFIG=false
23 22 SKIP_SHELL_CHANGE=false
24 23 INSTALL_HOMEBREW=false
25 24
@@ -97,16 +96,6 @@ set_timezone() {
97 96 warn "Skipping timezone change: timedatectl is not available in this WSL environment"
98 97 }
99 98
100 - configure_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 -
110 99 install_homebrew() {
111 100 ! $INSTALL_HOMEBREW && return
112 101 command -v brew >/dev/null 2>&1 && ok "Homebrew already installed" && return
@@ -183,7 +172,7 @@ update_zshrc() {
183 172 log "Checking .zshrc..."
184 173
185 174 if [[ ! -f "$zshrc" ]]; then
186 - warn ".zshrc not found. Run option 10 first."
175 + warn ".zshrc not found. Run option 9 first."
187 176 return 1
188 177 fi
189 178
@@ -207,20 +196,19 @@ show_menu() {
207 196 echo "==========================================="
208 197 echo "WSL Zsh Installer - Choose what to do"
209 198 echo "==========================================="
210 - echo " 0) Run ALL steps (1-12)"
199 + echo " 0) Run ALL steps (1-11)"
211 200 echo " 1) Update system packages"
212 201 echo " 2) Install core packages (zsh, git, vim, etc.)"
213 202 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"
203 + echo " 4) Install Homebrew"
204 + echo " 5) Configure shell (chsh - sets default shell)"
205 + echo " 6) Install Oh My Zsh"
206 + echo " 7) Install plugins (autosuggestions, syntax highlighting)"
207 + echo " 8) Install Spaceship theme"
208 + echo " 9) Download custom configs (~/.alias, .vimrc, etc.)"
209 + echo "10) Check ~/.zshrc load order"
210 + echo "11) Switch to Zsh (Temporary Sub-shell)"
211 + echo "12) Quit"
224 212 echo "==========================================="
225 213 }
226 214
@@ -236,7 +224,7 @@ run_choices() {
236 224 if [[ "$item" == !* ]]; then
237 225 to_exclude+=("${item:1}")
238 226 elif [[ "$item" == "0" ]]; then
239 - to_run+=(1 2 3 4 5 6 7 8 9 10 11 12)
227 + to_run+=(1 2 3 4 5 6 7 8 9 10 11)
240 228 else
241 229 to_run+=("$item")
242 230 fi
@@ -258,16 +246,15 @@ run_choices() {
258 246 1) update_system ;;
259 247 2) install_packages ;;
260 248 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 ;;
249 + 4) install_homebrew ;;
250 + 5) configure_shell ;;
251 + 6) install_oh_my_zsh ;;
252 + 7) install_plugins ;;
253 + 8) install_theme ;;
254 + 9) download_configs ;;
255 + 10) update_zshrc ;;
256 + 11) switch_shell ;;
257 + 12) log "Exiting..."; exit 0 ;;
271 258 *) warn "Skipping invalid option: $choice" ;;
272 259 esac
273 260 echo

weehong revised this gist 1 month ago. Go to revision

2 files changed, 48 insertions, 82 deletions

zsh_ubuntu.sh

@@ -21,7 +21,6 @@ err() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
21 21 SKIP_PACKAGES=false
22 22 SKIP_GIT_CONFIG=false
23 23 SKIP_SHELL_CHANGE=false
24 - SKIP_XCLIP=false
25 24 INSTALL_HOMEBREW=false
26 25
27 26 GIST_RAW_BASE="https://gist.githubusercontent.com/weehong/c430fefc6e90428dfe6811e0766decf4/raw"
@@ -85,20 +84,6 @@ set_timezone() {
85 84 ok "Timezone set to Asia/Singapore"
86 85 }
87 86
88 - install_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 -
102 87 configure_git() {
103 88 $SKIP_GIT_CONFIG && return
104 89 log "Configuring Git..."
@@ -185,7 +170,7 @@ update_zshrc() {
185 170 log "Checking .zshrc..."
186 171
187 172 if [[ ! -f "$zshrc" ]]; then
188 - warn ".zshrc not found. Run option 11 first."
173 + warn ".zshrc not found. Run option 10 first."
189 174 return 1
190 175 fi
191 176
@@ -209,21 +194,20 @@ show_menu() {
209 194 echo "==========================================="
210 195 echo "Zsh Installer - Choose what to do"
211 196 echo "==========================================="
212 - echo " 0) Run ALL steps (1-13)"
197 + echo " 0) Run ALL steps (1-12)"
213 198 echo " 1) Update system packages"
214 199 echo " 2) Install core packages (zsh, git, vim, etc.)"
215 200 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"
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"
227 211 echo "==========================================="
228 212 }
229 213
@@ -239,7 +223,7 @@ run_choices() {
239 223 if [[ "$item" == !* ]]; then
240 224 to_exclude+=("${item:1}")
241 225 elif [[ "$item" == "0" ]]; then
242 - to_run+=(1 2 3 4 5 6 7 8 9 10 11 12 13)
226 + to_run+=(1 2 3 4 5 6 7 8 9 10 11 12)
243 227 else
244 228 to_run+=("$item")
245 229 fi
@@ -261,17 +245,16 @@ run_choices() {
261 245 1) update_system ;;
262 246 2) install_packages ;;
263 247 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 ;;
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 ;;
275 258 *) warn "Skipping invalid option: $choice" ;;
276 259 esac
277 260 echo
@@ -292,4 +275,4 @@ main() {
292 275 ok "Zsh installation/configuration complete!"
293 276 }
294 277
295 - main "$@"
278 + main "$@"

zsh_wsl.sh

@@ -21,7 +21,6 @@ err() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
21 21 SKIP_PACKAGES=false
22 22 SKIP_GIT_CONFIG=false
23 23 SKIP_SHELL_CHANGE=false
24 - SKIP_XCLIP=false
25 24 INSTALL_HOMEBREW=false
26 25
27 26 GIST_RAW_BASE="https://gist.githubusercontent.com/weehong/c430fefc6e90428dfe6811e0766decf4/raw"
@@ -98,20 +97,6 @@ set_timezone() {
98 97 warn "Skipping timezone change: timedatectl is not available in this WSL environment"
99 98 }
100 99
101 - install_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 -
115 100 configure_git() {
116 101 $SKIP_GIT_CONFIG && return
117 102 log "Configuring Git..."
@@ -198,7 +183,7 @@ update_zshrc() {
198 183 log "Checking .zshrc..."
199 184
200 185 if [[ ! -f "$zshrc" ]]; then
201 - warn ".zshrc not found. Run option 11 first."
186 + warn ".zshrc not found. Run option 10 first."
202 187 return 1
203 188 fi
204 189
@@ -222,21 +207,20 @@ show_menu() {
222 207 echo "==========================================="
223 208 echo "WSL Zsh Installer - Choose what to do"
224 209 echo "==========================================="
225 - echo " 0) Run ALL steps (1-13)"
210 + echo " 0) Run ALL steps (1-12)"
226 211 echo " 1) Update system packages"
227 212 echo " 2) Install core packages (zsh, git, vim, etc.)"
228 213 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"
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"
240 224 echo "==========================================="
241 225 }
242 226
@@ -252,7 +236,7 @@ run_choices() {
252 236 if [[ "$item" == !* ]]; then
253 237 to_exclude+=("${item:1}")
254 238 elif [[ "$item" == "0" ]]; then
255 - to_run+=(1 2 3 4 5 6 7 8 9 10 11 12 13)
239 + to_run+=(1 2 3 4 5 6 7 8 9 10 11 12)
256 240 else
257 241 to_run+=("$item")
258 242 fi
@@ -274,17 +258,16 @@ run_choices() {
274 258 1) update_system ;;
275 259 2) install_packages ;;
276 260 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 ;;
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 ;;
288 271 *) warn "Skipping invalid option: $choice" ;;
289 272 esac
290 273 echo
@@ -305,4 +288,4 @@ main() {
305 288 ok "WSL Zsh installation/configuration complete!"
306 289 }
307 290
308 - main "$@"
291 + main "$@"

weehong revised this gist 1 month ago. Go to revision

No changes

weehong revised this gist 1 month ago. Go to revision

No changes

weehong revised this gist 1 month ago. Go to revision

3 files changed, 159 insertions, 155 deletions

zsh_macos.sh

@@ -18,13 +18,15 @@ err() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
18 18 # =============================
19 19 # CONFIG
20 20 # =============================
21 + GIST_RAW_BASE="https://gist.githubusercontent.com/weehong/c430fefc6e90428dfe6811e0766decf4/raw"
22 +
21 23 CONFIG_FILES=(
22 - ".alias|https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/alias"
23 - ".func|https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/func"
24 - ".pathrc|https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/pathrc"
25 - ".sourcerc|https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/sourcerc"
26 - ".vimrc|https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/vimrc"
27 - ".zshrc|https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/zshrc"
24 + ".alias"
25 + ".func"
26 + ".pathrc"
27 + ".sourcerc"
28 + ".vimrc"
29 + ".zshrc"
28 30 )
29 31
30 32 # =============================
@@ -44,7 +46,7 @@ configure_git() {
44 46 log "Configuring Git..."
45 47 read -p "Git name (leave empty to skip): " name
46 48 read -p "Git email (leave empty to skip): " email
47 -
49 +
48 50 if [[ -n "$name" ]]; then
49 51 git config --global user.name "$name"
50 52 fi
@@ -59,7 +61,7 @@ install_oh_my_zsh() {
59 61 ok "Oh My Zsh already installed"
60 62 return
61 63 fi
62 -
64 +
63 65 log "Installing Oh My Zsh..."
64 66 RUNZSH=no CHSH=no KEEP_ZSHRC=yes \
65 67 sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
@@ -69,8 +71,14 @@ install_oh_my_zsh() {
69 71 install_plugins() {
70 72 log "Installing plugins..."
71 73 local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins"
72 - [[ -d "$dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions"
73 - [[ -d "$dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting"
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 +
74 82 ok "Plugins installed"
75 83 }
76 84
@@ -78,74 +86,52 @@ install_theme() {
78 86 log "Installing Spaceship theme..."
79 87 local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes"
80 88 local dir="$themes/spaceship-prompt"
81 - [[ -d "$dir" ]] || git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1
82 - ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme"
83 - ok "Theme installed"
84 - }
85 89
86 - clean_macos_aliases() {
87 - local alias_file="$HOME/.alias"
88 - if [[ -f "$alias_file" ]]; then
89 - log "Patching .alias for macOS..."
90 - sed -i '' '/# System update & cleanup/,/sudo apt-get clean/d' "$alias_file"
91 - sed -i '' '/# xclip shortcuts/,/xclip -selection clipboard/d' "$alias_file"
92 - sed -i '' '/./,$!d' "$alias_file"
93 - ok "macOS incompatibilities removed from .alias"
94 - fi
95 - }
90 + mkdir -p "$themes"
91 + [[ -d "$dir" ]] || \
92 + git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1
96 93
97 - clean_func_file() {
98 - local func_file="$HOME/.func"
99 - if [[ -f "$func_file" ]]; then
100 - log "Patching .func to remove 'open' function (WSL/Explorer specific)..."
101 -
102 - # Deletes from the comment line containing 'Function: open' down to the closing brace }
103 - # This preserves the native macOS 'open' command.
104 - sed -i '' '/# Function: open/,/^}/d' "$func_file"
105 -
106 - # Trim leading blank lines that might remain at the top
107 - sed -i '' '/./,$!d' "$func_file"
108 -
109 - ok "'open' function removed from .func"
110 - fi
94 + ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme"
95 + ok "Theme installed"
111 96 }
112 97
113 98 download_configs() {
114 99 log "Downloading custom config files..."
115 100 local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)"
116 101 mkdir -p "$backup"
117 -
118 - for entry in "${CONFIG_FILES[@]}"; do
119 - local f="${entry%%|*}"
120 - local url="${entry##*|}"
121 -
122 - if [[ -f "$HOME/$f" ]]; then
123 - cp "$HOME/$f" "$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/"
124 110 fi
111 +
125 112 log "Fetching $f ..."
126 - curl -fsSL "$url" -o "$HOME/$f" || warn "Failed to download $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
127 119 done
128 -
129 - # Run cleanup patches
130 - clean_macos_aliases
131 - clean_func_file
132 -
120 +
133 121 ok "Configs downloaded (Backup at $backup)"
134 122 }
135 123
136 124 update_zshrc() {
137 125 local zshrc="$HOME/.zshrc"
138 - log "Updating .zshrc..."
139 -
126 + log "Checking .zshrc..."
127 +
140 128 if [[ ! -f "$zshrc" ]]; then
141 - warn ".zshrc not found, creating new one..."
142 - touch "$zshrc"
129 + warn ".zshrc not found. Run option 5 first."
130 + return 1
143 131 fi
144 132
145 - grep -q 'ZSH_THEME="spaceship"' "$zshrc" || sed -i '' 's/ZSH_THEME=".*"/ZSH_THEME="spaceship"/' "$zshrc"
146 - grep -q 'zsh-autosuggestions' "$zshrc" || sed -i '' 's/plugins=(/plugins=(zsh-autosuggestions /' "$zshrc"
147 - grep -q 'zsh-syntax-highlighting' "$zshrc" || sed -i '' 's/plugins=(/plugins=(zsh-syntax-highlighting /' "$zshrc"
148 - ok ".zshrc updated with plugins and theme"
133 + ok ".zshrc already comes from the managed gist."
134 + ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias"
149 135 }
150 136
151 137 switch_shell() {
@@ -170,7 +156,7 @@ show_menu() {
170 156 echo " 3) Install plugins (autosuggestions, syntax highlighting)"
171 157 echo " 4) Install Spaceship theme"
172 158 echo " 5) Download custom configs (~/.alias, .func, .vimrc, etc.)"
173 - echo " 6) Update ~/.zshrc for plugins & theme"
159 + echo " 6) Check ~/.zshrc load order"
174 160 echo " 7) Switch to Zsh (Temporary Sub-shell)"
175 161 echo " 8) Quit"
176 162 echo "==========================================="
@@ -179,7 +165,7 @@ show_menu() {
179 165 run_choices() {
180 166 local input
181 167 read -p "Select: " input
182 - input="${input//,/ }"
168 + input="${input//,/ }"
183 169
184 170 local -a to_run=()
185 171 local -a to_exclude=()
@@ -197,16 +183,16 @@ run_choices() {
197 183 if [[ ${#to_run[@]} -gt 0 ]]; then
198 184 for choice in "${to_run[@]}"; do
199 185 local skip=false
200 -
201 - # Array empty-check for older Bash versions (Fixes 'unbound variable' error)
186 +
202 187 if [[ ${#to_exclude[@]} -gt 0 ]]; then
203 188 for ex in "${to_exclude[@]}"; do
204 189 if [[ "$choice" == "$ex" ]]; then
205 - skip=true; break
190 + skip=true
191 + break
206 192 fi
207 193 done
208 194 fi
209 -
195 +
210 196 $skip && continue
211 197
212 198 case "$choice" in
@@ -239,4 +225,4 @@ main() {
239 225 ok "macOS configuration complete!"
240 226 }
241 227
242 - main "$@"
228 + main "$@"

zsh_ubuntu.sh

@@ -21,17 +21,17 @@ err() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
21 21 SKIP_PACKAGES=false
22 22 SKIP_GIT_CONFIG=false
23 23 SKIP_SHELL_CHANGE=false
24 - CUSTOM_CONFIG=false
25 24 SKIP_XCLIP=false
26 25 INSTALL_HOMEBREW=false
27 26
28 - declare -A CONFIG_FILES=(
29 - [".alias"]="https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/alias"
30 - [".func"]="https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/func"
31 - [".pathrc"]="https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/pathrc"
32 - [".sourcerc"]="https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/sourcerc"
33 - [".vimrc"]="https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/vimrc"
34 - [".zshrc"]="https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/zshrc"
27 + GIST_RAW_BASE="https://gist.githubusercontent.com/weehong/c430fefc6e90428dfe6811e0766decf4/raw"
28 + CONFIG_FILES=(
29 + ".alias"
30 + ".func"
31 + ".pathrc"
32 + ".sourcerc"
33 + ".vimrc"
34 + ".zshrc"
35 35 )
36 36
37 37 # =============================
@@ -54,7 +54,7 @@ check_requirements() {
54 54 err "Do not run as root"
55 55 exit 1
56 56 fi
57 - if ! command -v sudo >/dev/null; then
57 + if ! command -v sudo >/dev/null 2>&1; then
58 58 err "sudo required"
59 59 exit 1
60 60 fi
@@ -87,10 +87,10 @@ set_timezone() {
87 87
88 88 install_xclip() {
89 89 local os
90 - os=$(detect_os)
90 + os="$(detect_os)"
91 91 [[ "$os" != "ubuntu" && "$os" != "debian" ]] && return 0
92 92 $SKIP_XCLIP && return 0
93 - command -v xclip >/dev/null && ok "xclip already installed" && return 0
93 + command -v xclip >/dev/null 2>&1 && ok "xclip already installed" && return 0
94 94
95 95 read -r -p "Install xclip? (y/N): " r
96 96 case "$r" in
@@ -111,7 +111,7 @@ configure_git() {
111 111
112 112 install_homebrew() {
113 113 ! $INSTALL_HOMEBREW && return
114 - command -v brew >/dev/null && ok "Homebrew already installed" && return
114 + command -v brew >/dev/null 2>&1 && ok "Homebrew already installed" && return
115 115 log "Installing Homebrew..."
116 116 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
117 117 ok "Homebrew installed"
@@ -121,9 +121,9 @@ configure_shell() {
121 121 $SKIP_SHELL_CHANGE && return
122 122 log "Changing default shell to zsh..."
123 123 local zsh_path
124 - zsh_path=$(command -v zsh)
124 + zsh_path="$(command -v zsh)"
125 125 grep -qx "$zsh_path" /etc/shells || echo "$zsh_path" | sudo tee -a /etc/shells >/dev/null
126 - sudo chsh -s "$zsh_path" "$USER"
126 + chsh -s "$zsh_path"
127 127 ok "Shell changed (requires logout/login to take effect)"
128 128 }
129 129
@@ -138,6 +138,7 @@ install_oh_my_zsh() {
138 138 install_plugins() {
139 139 log "Installing plugins..."
140 140 local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins"
141 + mkdir -p "$dir"
141 142 [[ -d "$dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions"
142 143 [[ -d "$dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting"
143 144 ok "Plugins installed"
@@ -147,6 +148,7 @@ install_theme() {
147 148 log "Installing Spaceship theme..."
148 149 local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes"
149 150 local dir="$themes/spaceship-prompt"
151 + mkdir -p "$themes"
150 152 [[ -d "$dir" ]] || git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1
151 153 ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme"
152 154 ok "Theme installed"
@@ -156,40 +158,42 @@ download_configs() {
156 158 log "Downloading custom config files..."
157 159 local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)"
158 160 mkdir -p "$backup"
159 - for f in "${!CONFIG_FILES[@]}"; do
160 - if [[ -f "$HOME/$f" ]]; then
161 - cp "$HOME/$f" "$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/"
162 169 fi
163 - log "Fetching $f ..."
164 - curl -fsSL "${CONFIG_FILES[$f]}" -o "$HOME/$f" || warn "Failed to download $f"
165 170
166 - # --- Logic to remove the open function from .func ---
167 - if [[ "$f" == ".func" ]]; then
168 - # Removes the block starting with open() { and ending with }
169 - sed -i '/^open[[:space:]]*()[[:space:]]*{/,/^}/d' "$HOME/$f"
170 - ok "Stripped 'open' function from .func to prevent system conflicts"
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"
171 177 fi
172 178 done
179 +
173 180 ok "Configs downloaded (Backup at $backup)"
174 181 }
175 182
176 183 update_zshrc() {
177 184 local zshrc="$HOME/.zshrc"
178 - log "Updating .zshrc..."
179 -
185 + log "Checking .zshrc..."
186 +
180 187 if [[ ! -f "$zshrc" ]]; then
181 - warn ".zshrc not found, creating new one..."
182 - touch "$zshrc"
188 + warn ".zshrc not found. Run option 11 first."
189 + return 1
183 190 fi
184 191
185 - grep -q 'ZSH_THEME="spaceship"' "$zshrc" || sed -i 's/ZSH_THEME=".*"/ZSH_THEME="spaceship"/' "$zshrc"
186 - grep -q 'zsh-autosuggestions' "$zshrc" || sed -i 's/plugins=(/plugins=(zsh-autosuggestions /' "$zshrc"
187 - grep -q 'zsh-syntax-highlighting' "$zshrc" || sed -i 's/plugins=(/plugins=(zsh-syntax-highlighting /' "$zshrc"
188 - ok ".zshrc updated with plugins and theme"
192 + ok ".zshrc already comes from the managed gist."
193 + ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias"
189 194 }
190 195
191 196 switch_shell() {
192 - $SKIP_SHELL_CHANGE && return
193 197 log "Starting Zsh session..."
194 198 echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}"
195 199 echo "----------------------------------------"
@@ -217,7 +221,7 @@ show_menu() {
217 221 echo " 9) Install plugins (autosuggestions, syntax highlighting)"
218 222 echo "10) Install Spaceship theme"
219 223 echo "11) Download custom configs (~/.alias, .vimrc, etc.)"
220 - echo "12) Update ~/.zshrc for plugins & theme"
224 + echo "12) Check ~/.zshrc load order"
221 225 echo "13) Switch to Zsh (Temporary Sub-shell)"
222 226 echo "14) Quit"
223 227 echo "==========================================="
@@ -243,13 +247,14 @@ run_choices() {
243 247
244 248 for choice in "${to_run[@]}"; do
245 249 local skip=false
250 +
246 251 for ex in "${to_exclude[@]}"; do
247 252 if [[ "$choice" == "$ex" ]]; then
248 253 skip=true
249 254 break
250 255 fi
251 256 done
252 -
257 +
253 258 $skip && continue
254 259
255 260 case "$choice" in
@@ -287,4 +292,4 @@ main() {
287 292 ok "Zsh installation/configuration complete!"
288 293 }
289 294
290 - main "$@"
295 + main "$@"

zsh_wsl.sh

@@ -21,21 +21,21 @@ err() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
21 21 SKIP_PACKAGES=false
22 22 SKIP_GIT_CONFIG=false
23 23 SKIP_SHELL_CHANGE=false
24 - CUSTOM_CONFIG=false
25 24 SKIP_XCLIP=false
26 25 INSTALL_HOMEBREW=false
27 26
28 - declare -A CONFIG_FILES=(
29 - [".alias"]="https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/alias"
30 - [".func"]="https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/func"
31 - [".pathrc"]="https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/pathrc"
32 - [".sourcerc"]="https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/sourcerc"
33 - [".vimrc"]="https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/vimrc"
34 - [".zshrc"]="https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/zshrc"
27 + GIST_RAW_BASE="https://gist.githubusercontent.com/weehong/c430fefc6e90428dfe6811e0766decf4/raw"
28 + CONFIG_FILES=(
29 + ".alias"
30 + ".func"
31 + ".pathrc"
32 + ".sourcerc"
33 + ".vimrc"
34 + ".zshrc"
35 35 )
36 36
37 37 # =============================
38 - # OS DETECTION
38 + # PLATFORM DETECTION
39 39 # =============================
40 40 detect_os() {
41 41 if [ -f /etc/os-release ]; then
@@ -46,19 +46,26 @@ detect_os() {
46 46 fi
47 47 }
48 48
49 + is_wsl() {
50 + grep -qi "microsoft" /proc/version 2>/dev/null
51 + }
52 +
49 53 # =============================
50 54 # REQUIREMENTS
51 55 # =============================
52 56 check_requirements() {
53 - # Fixed to prevent silent failure with 'set -e'
54 57 if [[ $EUID -eq 0 ]]; then
55 58 err "Do not run as root"
56 59 exit 1
57 60 fi
58 - if ! command -v sudo >/dev/null; then
61 + if ! command -v sudo >/dev/null 2>&1; then
59 62 err "sudo required"
60 63 exit 1
61 64 fi
65 + if ! is_wsl; then
66 + err "This installer is intended for WSL"
67 + exit 1
68 + fi
62 69 }
63 70
64 71 # =============================
@@ -81,19 +88,24 @@ install_packages() {
81 88 }
82 89
83 90 set_timezone() {
84 - log "Setting timezone to Asia/Singapore..."
85 - sudo timedatectl set-timezone Asia/Singapore
86 - ok "Timezone set to Asia/Singapore"
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"
87 99 }
88 100
89 101 install_xclip() {
90 102 local os
91 - os=$(detect_os)
103 + os="$(detect_os)"
92 104 [[ "$os" != "ubuntu" && "$os" != "debian" ]] && return 0
93 105 $SKIP_XCLIP && return 0
94 - command -v xclip >/dev/null && ok "xclip already installed" && return 0
106 + command -v xclip >/dev/null 2>&1 && ok "xclip already installed" && return 0
95 107
96 - read -r -p "Install xclip? (y/N): " r
108 + read -r -p "Install xclip for Linux/X11 clipboard support? (y/N): " r
97 109 case "$r" in
98 110 [Yy]) sudo apt-get install -y xclip; ok "xclip installed" ;;
99 111 *) log "Skipping xclip installation" ;;
@@ -112,7 +124,7 @@ configure_git() {
112 124
113 125 install_homebrew() {
114 126 ! $INSTALL_HOMEBREW && return
115 - command -v brew >/dev/null && ok "Homebrew already installed" && return
127 + command -v brew >/dev/null 2>&1 && ok "Homebrew already installed" && return
116 128 log "Installing Homebrew..."
117 129 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
118 130 ok "Homebrew installed"
@@ -122,16 +134,15 @@ configure_shell() {
122 134 $SKIP_SHELL_CHANGE && return
123 135 log "Changing default shell to zsh..."
124 136 local zsh_path
125 - zsh_path=$(command -v zsh)
137 + zsh_path="$(command -v zsh)"
126 138 grep -qx "$zsh_path" /etc/shells || echo "$zsh_path" | sudo tee -a /etc/shells >/dev/null
127 - sudo chsh -s "$zsh_path" "$USER"
128 - ok "Shell changed (requires logout/login to take effect)"
139 + chsh -s "$zsh_path"
140 + ok "Shell changed (open a new WSL session for it to take effect)"
129 141 }
130 142
131 143 install_oh_my_zsh() {
132 144 [[ -d "$HOME/.oh-my-zsh" ]] && ok "Oh My Zsh already installed" && return
133 145 log "Installing Oh My Zsh..."
134 - # Keep zshrc ensures we don't blow away configs if they exist
135 146 RUNZSH=no CHSH=no KEEP_ZSHRC=yes \
136 147 sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
137 148 ok "Oh My Zsh installed"
@@ -140,6 +151,7 @@ install_oh_my_zsh() {
140 151 install_plugins() {
141 152 log "Installing plugins..."
142 153 local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins"
154 + mkdir -p "$dir"
143 155 [[ -d "$dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions"
144 156 [[ -d "$dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting"
145 157 ok "Plugins installed"
@@ -149,6 +161,7 @@ install_theme() {
149 161 log "Installing Spaceship theme..."
150 162 local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes"
151 163 local dir="$themes/spaceship-prompt"
164 + mkdir -p "$themes"
152 165 [[ -d "$dir" ]] || git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1
153 166 ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme"
154 167 ok "Theme installed"
@@ -158,43 +171,46 @@ download_configs() {
158 171 log "Downloading custom config files..."
159 172 local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)"
160 173 mkdir -p "$backup"
161 - for f in "${!CONFIG_FILES[@]}"; do
162 - if [[ -f "$HOME/$f" ]]; then
163 - cp "$HOME/$f" "$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/"
164 182 fi
183 +
165 184 log "Fetching $f ..."
166 - curl -fsSL "${CONFIG_FILES[$f]}" -o "$HOME/$f" || warn "Failed to download $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
167 191 done
192 +
168 193 ok "Configs downloaded (Backup at $backup)"
169 194 }
170 195
171 196 update_zshrc() {
172 197 local zshrc="$HOME/.zshrc"
173 - log "Updating .zshrc..."
174 -
175 - # Create zshrc if missing to prevent errors
198 + log "Checking .zshrc..."
199 +
176 200 if [[ ! -f "$zshrc" ]]; then
177 - warn ".zshrc not found, creating new one..."
178 - touch "$zshrc"
201 + warn ".zshrc not found. Run option 11 first."
202 + return 1
179 203 fi
180 204
181 - # Use || true to prevent 'set -e' from exiting if grep finds nothing
182 - grep -q 'ZSH_THEME="spaceship"' "$zshrc" || sed -i 's/ZSH_THEME=".*"/ZSH_THEME="spaceship"/' "$zshrc"
183 - grep -q 'zsh-autosuggestions' "$zshrc" || sed -i 's/plugins=(/plugins=(zsh-autosuggestions /' "$zshrc"
184 - grep -q 'zsh-syntax-highlighting' "$zshrc" || sed -i 's/plugins=(/plugins=(zsh-syntax-highlighting /' "$zshrc"
185 - ok ".zshrc updated with plugins and theme"
205 + ok ".zshrc already comes from the managed gist."
206 + ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias"
186 207 }
187 208
188 209 switch_shell() {
189 - $SKIP_SHELL_CHANGE && return
190 -
191 210 log "Starting Zsh session..."
192 211 echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}"
193 212 echo "----------------------------------------"
194 -
195 - # Run zsh as a subprocess, not exec
196 213 zsh -l
197 -
198 214 echo "----------------------------------------"
199 215 ok "Returned from Zsh session"
200 216 }
@@ -204,12 +220,12 @@ switch_shell() {
204 220 # =============================
205 221 show_menu() {
206 222 echo "==========================================="
207 - echo "Zsh Installer - Choose what to do"
223 + echo "WSL Zsh Installer - Choose what to do"
208 224 echo "==========================================="
209 225 echo " 0) Run ALL steps (1-13)"
210 226 echo " 1) Update system packages"
211 227 echo " 2) Install core packages (zsh, git, vim, etc.)"
212 - echo " 3) Set Timezone (Asia/Singapore)"
228 + echo " 3) Set Timezone (best effort)"
213 229 echo " 4) Install xclip"
214 230 echo " 5) Configure Git"
215 231 echo " 6) Install Homebrew"
@@ -218,25 +234,23 @@ show_menu() {
218 234 echo " 9) Install plugins (autosuggestions, syntax highlighting)"
219 235 echo "10) Install Spaceship theme"
220 236 echo "11) Download custom configs (~/.alias, .vimrc, etc.)"
221 - echo "12) Update ~/.zshrc for plugins & theme"
237 + echo "12) Check ~/.zshrc load order"
222 238 echo "13) Switch to Zsh (Temporary Sub-shell)"
223 239 echo "14) Quit"
224 240 echo "==========================================="
225 - echo "Inputs: '0' (All), '2 3 7' (Specific), '0 !4 !6' (All except 4 and 6)"
226 241 }
227 242
228 243 run_choices() {
229 244 local input
230 245 read -p "Select: " input
231 - input="${input//,/ }" # replace commas with spaces
246 + input="${input//,/ }"
232 247
233 248 local -a to_run=()
234 249 local -a to_exclude=()
235 250
236 - # Parse positive selections and negative exclusions
237 251 for item in $input; do
238 252 if [[ "$item" == !* ]]; then
239 - to_exclude+=("${item:1}") # Strip the '!' character
253 + to_exclude+=("${item:1}")
240 254 elif [[ "$item" == "0" ]]; then
241 255 to_run+=(1 2 3 4 5 6 7 8 9 10 11 12 13)
242 256 else
@@ -244,17 +258,16 @@ run_choices() {
244 258 fi
245 259 done
246 260
247 - # Loop through intended runs and apply exclusions
248 261 for choice in "${to_run[@]}"; do
249 -
250 262 local skip=false
263 +
251 264 for ex in "${to_exclude[@]}"; do
252 265 if [[ "$choice" == "$ex" ]]; then
253 266 skip=true
254 267 break
255 268 fi
256 269 done
257 -
270 +
258 271 $skip && continue
259 272
260 273 case "$choice" in
@@ -289,7 +302,7 @@ main() {
289 302 read -p "Do you want to run more options? (y/n): " again
290 303 [[ "$again" =~ ^[Yy]$ ]] || break
291 304 done
292 - ok "Zsh installation/configuration complete!"
305 + ok "WSL Zsh installation/configuration complete!"
293 306 }
294 307
295 - main "$@"
308 + main "$@"

weehong revised this gist 3 months ago. Go to revision

1 file changed, 4 insertions

README.md

@@ -6,6 +6,10 @@ The "Bash Script Installer" simplifies the setup of Zsh.
6 6 ```zsh
7 7 bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_ubuntu.sh)"
8 8 ```
9 + ### WSL
10 + ```zsh
11 + bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_wsl.sh)"
12 + ```
9 13 ### MacOS
10 14 ```zsh
11 15 bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_macos.sh)"