Última atividade 2 weeks ago

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

weehong revisou este gist 2 weeks ago. Ir para a revisão

2 files changed, 31 insertions, 9 deletions

zsh_ubuntu.sh

@@ -70,13 +70,25 @@ update_system() {
70 70 local os=$(detect_os)
71 71
72 72 case "$os" in
73 - macos) brew update ;;
74 - ubuntu|debian) sudo apt-get update -y && sudo apt-get upgrade -y ;;
75 - fedora) sudo dnf upgrade -y ;;
76 - arch) sudo pacman -Syu --noconfirm ;;
73 + macos)
74 + brew update || warn "Homebrew update failed; continuing installer"
75 + ;;
76 + ubuntu|debian)
77 + sudo apt-get update -y
78 + if ! sudo apt-get upgrade -y; then
79 + warn "System upgrade did not complete. This can happen when apt wants to downgrade a package."
80 + warn "Continuing because the Zsh setup does not require OS package upgrades to finish."
81 + fi
82 + ;;
83 + fedora)
84 + sudo dnf upgrade -y || warn "System upgrade failed; continuing installer"
85 + ;;
86 + arch)
87 + sudo pacman -Syu --noconfirm || warn "System upgrade failed; continuing installer"
88 + ;;
77 89 *) warn "Auto-update not supported for OS: $os" ;;
78 90 esac
79 - ok "System updated"
91 + ok "System update step finished"
80 92 }
81 93
82 94 install_packages() {

zsh_wsl.sh

@@ -76,12 +76,22 @@ update_system() {
76 76 local os=$(detect_os)
77 77
78 78 case "$os" in
79 - ubuntu|debian) sudo apt-get update -y && sudo apt-get upgrade -y ;;
80 - fedora) sudo dnf upgrade -y ;;
81 - arch) sudo pacman -Syu --noconfirm ;;
79 + ubuntu|debian)
80 + sudo apt-get update -y
81 + if ! sudo apt-get upgrade -y; then
82 + warn "System upgrade did not complete. This can happen when apt wants to downgrade a package."
83 + warn "Continuing because the Zsh setup does not require OS package upgrades to finish."
84 + fi
85 + ;;
86 + fedora)
87 + sudo dnf upgrade -y || warn "System upgrade failed; continuing installer"
88 + ;;
89 + arch)
90 + sudo pacman -Syu --noconfirm || warn "System upgrade failed; continuing installer"
91 + ;;
82 92 *) warn "Auto-update not supported for OS: $os" ;;
83 93 esac
84 - ok "System updated"
94 + ok "System update step finished"
85 95 }
86 96
87 97 install_packages() {

weehong revisou este gist 2 weeks ago. Ir para a revisão

5 files changed, 242 insertions, 134 deletions

README.md

@@ -20,5 +20,13 @@ bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996
20 20 bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/config.sh)"
21 21 ```
22 22
23 - ### Prompt theme
24 - Run the installer theme option and select either Spaceship or Starship. Starship uses the Catppuccin Powerline preset from the managed config at `~/.config/starship.toml`. A Nerd Font is required for the Powerline symbols.
23 + ### Shell framework and prompt
24 + The installers use Oh My Zsh for framework features and plugins, with the OMZ theme disabled:
25 +
26 + ```zsh
27 + ZSH_THEME=""
28 + source "$ZSH/oh-my-zsh.sh"
29 + eval "$(starship init zsh)"
30 + ```
31 +
32 + Starship owns the prompt and loads after Oh My Zsh. The managed Starship config is installed at `~/.config/starship.toml`. A Nerd Font is required for the Powerline symbols.

zsh_macos.sh

@@ -43,18 +43,29 @@ check_requirements() {
43 43 # =============================
44 44 # INSTALLATION FUNCTIONS
45 45 # =============================
46 - install_plugins() {
47 - log "Installing manual Zsh plugins..."
48 - local dir="$HOME/.zsh"
49 - mkdir -p "$dir"
46 + install_oh_my_zsh() {
47 + log "Installing Oh My Zsh and plugins..."
48 + export RUNZSH=no
49 + export CHSH=no
50 + export KEEP_ZSHRC=yes
51 +
52 + if [[ ! -d "$HOME/.oh-my-zsh" ]]; then
53 + sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" --unattended
54 + else
55 + ok "Oh My Zsh already installed"
56 + fi
57 +
58 + local custom="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"
59 + local plugin_dir="$custom/plugins"
60 + mkdir -p "$plugin_dir"
50 61
51 - [[ -d "$dir/zsh-autosuggestions" ]] || \
52 - git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions"
62 + [[ -d "$plugin_dir/zsh-autosuggestions" ]] || \
63 + git clone https://github.com/zsh-users/zsh-autosuggestions "$plugin_dir/zsh-autosuggestions"
53 64
54 - [[ -d "$dir/zsh-syntax-highlighting" ]] || \
55 - git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting"
65 + [[ -d "$plugin_dir/zsh-syntax-highlighting" ]] || \
66 + git clone https://github.com/zsh-users/zsh-syntax-highlighting "$plugin_dir/zsh-syntax-highlighting"
56 67
57 - ok "Plugins installed directly to $dir"
68 + ok "Oh My Zsh plugins installed to $plugin_dir"
58 69 }
59 70
60 71 install_starship() {
@@ -105,43 +116,61 @@ download_configs() {
105 116
106 117 configure_zshrc() {
107 118 local zshrc="$HOME/.zshrc"
108 - log "Configuring .zshrc for plugins and Starship..."
119 + log "Configuring .zshrc for Oh My Zsh and Starship..."
109 120
110 121 touch "$zshrc"
111 -
112 - # CRITICAL FIX: Purge old corrupted multi-line/plaintext starship lines
113 - if [[ -f "$zshrc" ]]; then
114 - sed -i '' '/starship init zsh/d' "$zshrc" 2>/dev/null || true
115 - sed -i '' '/firing,/d' "$zshrc" 2>/dev/null || true
122 + cp "$zshrc" "$HOME/.zshrc.backup_$(date +%Y%m%d_%H%M%S)"
123 +
124 + cat > "$zshrc" <<'EOF'
125 + # =============================================================================
126 + # 1. HELPER FUNCTIONS & PATH
127 + # =============================================================================
128 + source_if_readable() {
129 + local file="$1"
130 + if [[ -f "$file" && -r "$file" ]]; then
131 + source "$file"
116 132 fi
133 + }
117 134
118 - # Ensure local binary path is explicitly loaded first
119 - if ! grep -q '\.local/bin' "$zshrc"; then
120 - # macOS sed requires an empty string argument with -i
121 - sed -i '' '1i\
122 135 export PATH="$HOME/.local/bin:$PATH"
123 - ' "$zshrc" 2>/dev/null || echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$zshrc"
124 - fi
125 136
126 - # Cleanly inject one-line safe evaluator
127 - if ! grep -q 'starship init zsh' "$zshrc"; then
128 - echo -e '\n# Initialize Starship' >> "$zshrc"
129 - echo 'if command -v starship >/dev/null 2>&1; then eval "$(starship init zsh)"; else eval "$($HOME/.local/bin/starship init zsh)"; fi' >> "$zshrc"
130 - fi
131 -
132 - # Add autosuggestions if not present
133 - if ! grep -q 'zsh-autosuggestions.zsh' "$zshrc"; then
134 - echo -e '\n# Load Plugins' >> "$zshrc"
135 - echo 'source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh' >> "$zshrc"
136 - fi
137 + # =============================================================================
138 + # 2. OH MY ZSH FRAMEWORK
139 + # =============================================================================
140 + export ZSH="${ZSH:-$HOME/.oh-my-zsh}"
141 + ZSH_THEME=""
137 142
138 - # Add syntax highlighting if not present (MUST be last)
139 - if ! grep -q 'zsh-syntax-highlighting.zsh' "$zshrc"; then
140 - echo 'source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh' >> "$zshrc"
141 - fi
143 + plugins=(
144 + git
145 + zsh-autosuggestions
146 + zsh-syntax-highlighting
147 + )
142 148
143 - ok ".zshrc configured cleanly for zero-framework setup!"
144 - ok "Load order is preserved: .sourcerc -> .func -> .pathrc -> .alias"
149 + source_if_readable "$ZSH/oh-my-zsh.sh"
150 +
151 + # =============================================================================
152 + # 3. THIRD-PARTY INITIALIZATION & CUSTOM CONFIGS
153 + # =============================================================================
154 + source_if_readable "$HOME/.sourcerc"
155 + source_if_readable "$HOME/.func"
156 + source_if_readable "$HOME/.pathrc"
157 + source_if_readable "$HOME/.alias"
158 +
159 + # =============================================================================
160 + # 4. STARSHIP PROMPT
161 + # =============================================================================
162 + if [[ -z "${STARSHIP_CONFIG:-}" && -f "$HOME/.config/starship.toml" ]]; then
163 + export STARSHIP_CONFIG="$HOME/.config/starship.toml"
164 + fi
165 +
166 + if command -v starship >/dev/null 2>&1; then
167 + eval "$(starship init zsh)"
168 + elif [[ -x "$HOME/.local/bin/starship" ]]; then
169 + eval "$("$HOME/.local/bin/starship" init zsh)"
170 + fi
171 + EOF
172 +
173 + ok ".zshrc configured for Oh My Zsh framework with Starship prompt"
145 174 }
146 175
147 176 switch_shell() {
@@ -161,10 +190,10 @@ show_menu() {
161 190 echo "macOS Minimal Zsh Setup - Choose what to do"
162 191 echo "==========================================="
163 192 echo " 0) Run ALL steps (1-5)"
164 - echo " 1) Install manual Zsh plugins (autosuggestions, syntax highlighting)"
193 + echo " 1) Install Oh My Zsh + plugins"
165 194 echo " 2) Install Starship prompt"
166 195 echo " 3) Download custom configs (~/.alias, .func, .vimrc, etc.)"
167 - echo " 4) Configure ~/.zshrc (Inject Starship & Plugins)"
196 + echo " 4) Configure ~/.zshrc (Oh My Zsh + Starship)"
168 197 echo " 5) Switch to Zsh (Temporary Sub-shell)"
169 198 echo " 6) Quit"
170 199 echo "==========================================="
@@ -204,7 +233,7 @@ run_choices() {
204 233 $skip && continue
205 234
206 235 case "$choice" in
207 - 1) install_plugins ;;
236 + 1) install_oh_my_zsh ;;
208 237 2) install_starship ;;
209 238 3) download_configs ;;
210 239 4) configure_zshrc ;;

zsh_ubuntu.sh

@@ -126,15 +126,26 @@ configure_shell() {
126 126 ok "Shell changed (requires logout/login to take effect)"
127 127 }
128 128
129 - install_plugins() {
130 - log "Installing manual Zsh plugins..."
131 - local dir="$HOME/.zsh"
132 - mkdir -p "$dir"
133 -
134 - [[ -d "$dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions"
135 - [[ -d "$dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting"
136 -
137 - ok "Plugins installed directly to $dir"
129 + install_oh_my_zsh() {
130 + log "Installing Oh My Zsh and plugins..."
131 + export RUNZSH=no
132 + export CHSH=no
133 + export KEEP_ZSHRC=yes
134 +
135 + if [[ ! -d "$HOME/.oh-my-zsh" ]]; then
136 + sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" --unattended
137 + else
138 + ok "Oh My Zsh already installed"
139 + fi
140 +
141 + local custom="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"
142 + local plugin_dir="$custom/plugins"
143 + mkdir -p "$plugin_dir"
144 +
145 + [[ -d "$plugin_dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$plugin_dir/zsh-autosuggestions"
146 + [[ -d "$plugin_dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$plugin_dir/zsh-syntax-highlighting"
147 +
148 + ok "Oh My Zsh plugins installed to $plugin_dir"
138 149 }
139 150
140 151 install_starship() {
@@ -184,39 +195,61 @@ download_configs() {
184 195
185 196 configure_zshrc() {
186 197 local zshrc="$HOME/.zshrc"
187 - log "Configuring .zshrc for plugins and Starship..."
198 + log "Configuring .zshrc for Oh My Zsh and Starship..."
188 199
189 200 touch "$zshrc"
190 -
191 - # CRITICAL FIX: Purge old corrupted multi-line/plaintext starship lines that broke preexec
192 - if [[ -f "$zshrc" ]]; then
193 - sed -i '/starship init zsh/d' "$zshrc" 2>/dev/null || true
194 - sed -i '/firing,/d' "$zshrc" 2>/dev/null || true
201 + cp "$zshrc" "$HOME/.zshrc.backup_$(date +%Y%m%d_%H%M%S)"
202 +
203 + cat > "$zshrc" <<'EOF'
204 + # =============================================================================
205 + # 1. HELPER FUNCTIONS & PATH
206 + # =============================================================================
207 + source_if_readable() {
208 + local file="$1"
209 + if [[ -f "$file" && -r "$file" ]]; then
210 + source "$file"
195 211 fi
212 + }
196 213
197 - # Ensure local binary path is explicitly loaded first
198 - if ! grep -q '\.local/bin' "$zshrc"; then
199 - sed -i '1i\export PATH="$HOME/.local/bin:$PATH"' "$zshrc" 2>/dev/null || echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$zshrc"
200 - fi
214 + export PATH="$HOME/.local/bin:$PATH"
201 215
202 - # Cleanly inject one-line safe evaluator
203 - if ! grep -q 'starship init zsh' "$zshrc"; then
204 - echo -e '\n# Initialize Starship' >> "$zshrc"
205 - echo 'if command -v starship >/dev/null 2>&1; then eval "$(starship init zsh)"; else eval "$($HOME/.local/bin/starship init zsh)"; fi' >> "$zshrc"
206 - fi
216 + # =============================================================================
217 + # 2. OH MY ZSH FRAMEWORK
218 + # =============================================================================
219 + export ZSH="${ZSH:-$HOME/.oh-my-zsh}"
220 + ZSH_THEME=""
207 221
208 - # Add autosuggestions if not present
209 - if ! grep -q 'zsh-autosuggestions.zsh' "$zshrc"; then
210 - echo -e '\n# Load Plugins' >> "$zshrc"
211 - echo 'source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh' >> "$zshrc"
212 - fi
213 -
214 - # Add syntax highlighting if not present (MUST be last line)
215 - if ! grep -q 'zsh-syntax-highlighting.zsh' "$zshrc"; then
216 - echo 'source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh' >> "$zshrc"
217 - fi
222 + plugins=(
223 + git
224 + zsh-autosuggestions
225 + zsh-syntax-highlighting
226 + )
218 227
219 - ok ".zshrc configured cleanly for zero-framework setup!"
228 + source_if_readable "$ZSH/oh-my-zsh.sh"
229 +
230 + # =============================================================================
231 + # 3. THIRD-PARTY INITIALIZATION & CUSTOM CONFIGS
232 + # =============================================================================
233 + source_if_readable "$HOME/.sourcerc"
234 + source_if_readable "$HOME/.func"
235 + source_if_readable "$HOME/.pathrc"
236 + source_if_readable "$HOME/.alias"
237 +
238 + # =============================================================================
239 + # 4. STARSHIP PROMPT
240 + # =============================================================================
241 + if [[ -z "${STARSHIP_CONFIG:-}" && -f "$HOME/.config/starship.toml" ]]; then
242 + export STARSHIP_CONFIG="$HOME/.config/starship.toml"
243 + fi
244 +
245 + if command -v starship >/dev/null 2>&1; then
246 + eval "$(starship init zsh)"
247 + elif [[ -x "$HOME/.local/bin/starship" ]]; then
248 + eval "$("$HOME/.local/bin/starship" init zsh)"
249 + fi
250 + EOF
251 +
252 + ok ".zshrc configured for Oh My Zsh framework with Starship prompt"
220 253 }
221 254
222 255 switch_shell() {
@@ -241,10 +274,10 @@ show_menu() {
241 274 echo " 3) Set Timezone (Asia/Singapore)"
242 275 echo " 4) Install Homebrew"
243 276 echo " 5) Configure shell (chsh - sets default shell)"
244 - echo " 6) Install manual Zsh plugins (Autosuggestions, Syntax Highlighting)"
277 + echo " 6) Install Oh My Zsh + plugins"
245 278 echo " 7) Install Starship prompt"
246 279 echo " 8) Download custom configs (from OpenGist)"
247 - echo " 9) Configure ~/.zshrc (Inject Starship & Plugins)"
280 + echo " 9) Configure ~/.zshrc (Oh My Zsh + Starship)"
248 281 echo "10) Switch to Zsh (Temporary Sub-shell)"
249 282 echo "11) Quit"
250 283 echo "==========================================="
@@ -286,7 +319,7 @@ run_choices() {
286 319 3) set_timezone ;;
287 320 4) install_homebrew ;;
288 321 5) configure_shell ;;
289 - 6) install_plugins ;;
322 + 6) install_oh_my_zsh ;;
290 323 7) install_starship ;;
291 324 8) download_configs ;;
292 325 9) configure_zshrc ;;

zsh_wsl.sh

@@ -130,15 +130,26 @@ configure_shell() {
130 130 ok "Shell changed (open a new WSL session for it to take effect)"
131 131 }
132 132
133 - install_plugins() {
134 - log "Installing manual Zsh plugins..."
135 - local dir="$HOME/.zsh"
136 - mkdir -p "$dir"
137 -
138 - [[ -d "$dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions"
139 - [[ -d "$dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting"
140 -
141 - ok "Plugins installed directly to $dir"
133 + install_oh_my_zsh() {
134 + log "Installing Oh My Zsh and plugins..."
135 + export RUNZSH=no
136 + export CHSH=no
137 + export KEEP_ZSHRC=yes
138 +
139 + if [[ ! -d "$HOME/.oh-my-zsh" ]]; then
140 + sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" --unattended
141 + else
142 + ok "Oh My Zsh already installed"
143 + fi
144 +
145 + local custom="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"
146 + local plugin_dir="$custom/plugins"
147 + mkdir -p "$plugin_dir"
148 +
149 + [[ -d "$plugin_dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$plugin_dir/zsh-autosuggestions"
150 + [[ -d "$plugin_dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$plugin_dir/zsh-syntax-highlighting"
151 +
152 + ok "Oh My Zsh plugins installed to $plugin_dir"
142 153 }
143 154
144 155 install_starship() {
@@ -188,39 +199,61 @@ download_configs() {
188 199
189 200 configure_zshrc() {
190 201 local zshrc="$HOME/.zshrc"
191 - log "Configuring .zshrc for plugins and Starship..."
202 + log "Configuring .zshrc for Oh My Zsh and Starship..."
192 203
193 204 touch "$zshrc"
194 -
195 - # CRITICAL FIX: Purge old corrupted multi-line/plaintext starship lines
196 - if [[ -f "$zshrc" ]]; then
197 - sed -i '/starship init zsh/d' "$zshrc" 2>/dev/null || true
198 - sed -i '/firing,/d' "$zshrc" 2>/dev/null || true
205 + cp "$zshrc" "$HOME/.zshrc.backup_$(date +%Y%m%d_%H%M%S)"
206 +
207 + cat > "$zshrc" <<'EOF'
208 + # =============================================================================
209 + # 1. HELPER FUNCTIONS & PATH
210 + # =============================================================================
211 + source_if_readable() {
212 + local file="$1"
213 + if [[ -f "$file" && -r "$file" ]]; then
214 + source "$file"
199 215 fi
216 + }
200 217
201 - # Ensure local binary path is explicitly loaded first
202 - if ! grep -q '\.local/bin' "$zshrc"; then
203 - sed -i '1i\export PATH="$HOME/.local/bin:$PATH"' "$zshrc" 2>/dev/null || echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$zshrc"
204 - fi
218 + export PATH="$HOME/.local/bin:$PATH"
205 219
206 - # Cleanly inject one-line safe evaluator
207 - if ! grep -q 'starship init zsh' "$zshrc"; then
208 - echo -e '\n# Initialize Starship' >> "$zshrc"
209 - echo 'if command -v starship >/dev/null 2>&1; then eval "$(starship init zsh)"; else eval "$($HOME/.local/bin/starship init zsh)"; fi' >> "$zshrc"
210 - fi
220 + # =============================================================================
221 + # 2. OH MY ZSH FRAMEWORK
222 + # =============================================================================
223 + export ZSH="${ZSH:-$HOME/.oh-my-zsh}"
224 + ZSH_THEME=""
211 225
212 - # Add autosuggestions if not present
213 - if ! grep -q 'zsh-autosuggestions.zsh' "$zshrc"; then
214 - echo -e '\n# Load Plugins' >> "$zshrc"
215 - echo 'source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh' >> "$zshrc"
216 - fi
217 -
218 - # Add syntax highlighting if not present (MUST be last)
219 - if ! grep -q 'zsh-syntax-highlighting.zsh' "$zshrc"; then
220 - echo 'source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh' >> "$zshrc"
221 - fi
226 + plugins=(
227 + git
228 + zsh-autosuggestions
229 + zsh-syntax-highlighting
230 + )
222 231
223 - ok ".zshrc configured cleanly for zero-framework setup!"
232 + source_if_readable "$ZSH/oh-my-zsh.sh"
233 +
234 + # =============================================================================
235 + # 3. THIRD-PARTY INITIALIZATION & CUSTOM CONFIGS
236 + # =============================================================================
237 + source_if_readable "$HOME/.sourcerc"
238 + source_if_readable "$HOME/.func"
239 + source_if_readable "$HOME/.pathrc"
240 + source_if_readable "$HOME/.alias"
241 +
242 + # =============================================================================
243 + # 4. STARSHIP PROMPT
244 + # =============================================================================
245 + if [[ -z "${STARSHIP_CONFIG:-}" && -f "$HOME/.config/starship.toml" ]]; then
246 + export STARSHIP_CONFIG="$HOME/.config/starship.toml"
247 + fi
248 +
249 + if command -v starship >/dev/null 2>&1; then
250 + eval "$(starship init zsh)"
251 + elif [[ -x "$HOME/.local/bin/starship" ]]; then
252 + eval "$("$HOME/.local/bin/starship" init zsh)"
253 + fi
254 + EOF
255 +
256 + ok ".zshrc configured for Oh My Zsh framework with Starship prompt"
224 257 }
225 258
226 259 switch_shell() {
@@ -245,10 +278,10 @@ show_menu() {
245 278 echo " 3) Set Timezone (best effort)"
246 279 echo " 4) Install Homebrew"
247 280 echo " 5) Configure shell (chsh - sets default shell)"
248 - echo " 6) Install manual Zsh plugins (Autosuggestions, Syntax Highlighting)"
281 + echo " 6) Install Oh My Zsh + plugins"
249 282 echo " 7) Install Starship prompt"
250 283 echo " 8) Download custom configs (from OpenGist)"
251 - echo " 9) Configure ~/.zshrc (Inject Starship & Plugins)"
284 + echo " 9) Configure ~/.zshrc (Oh My Zsh + Starship)"
252 285 echo "10) Switch to Zsh (Temporary Sub-shell)"
253 286 echo "11) Quit"
254 287 echo "==========================================="
@@ -290,7 +323,7 @@ run_choices() {
290 323 3) set_timezone ;;
291 324 4) install_homebrew ;;
292 325 5) configure_shell ;;
293 - 6) install_plugins ;;
326 + 6) install_oh_my_zsh ;;
294 327 7) install_starship ;;
295 328 8) download_configs ;;
296 329 9) configure_zshrc ;;

zshrc

@@ -12,7 +12,21 @@ source_if_readable() {
12 12 export PATH="$HOME/.local/bin:$PATH"
13 13
14 14 # =============================================================================
15 - # 2. THIRD-PARTY INITIALIZATION & CUSTOM CONFIGS
15 + # 2. OH MY ZSH FRAMEWORK
16 + # =============================================================================
17 + export ZSH="${ZSH:-$HOME/.oh-my-zsh}"
18 + ZSH_THEME=""
19 +
20 + plugins=(
21 + git
22 + zsh-autosuggestions
23 + zsh-syntax-highlighting
24 + )
25 +
26 + source_if_readable "$ZSH/oh-my-zsh.sh"
27 +
28 + # =============================================================================
29 + # 3. THIRD-PARTY INITIALIZATION & CUSTOM CONFIGS
16 30 # =============================================================================
17 31 # Load external initializers (SDKMAN, NVM, etc.)
18 32 source_if_readable "$HOME/.sourcerc"
@@ -23,28 +37,19 @@ source_if_readable "$HOME/.func"
23 37 # Path Management (Relies on append_path from .func)
24 38 source_if_readable "$HOME/.pathrc"
25 39
26 - # Aliases (Loaded late so they override system defaults)
40 + # Aliases (Loaded late so they override framework/system defaults)
27 41 source_if_readable "$HOME/.alias"
28 42
29 43 # =============================================================================
30 - # 3. STARSHIP PROMPT
44 + # 4. STARSHIP PROMPT
31 45 # =============================================================================
32 46 if [[ -z "${STARSHIP_CONFIG:-}" && -f "$HOME/.config/starship.toml" ]]; then
33 47 export STARSHIP_CONFIG="$HOME/.config/starship.toml"
34 48 fi
35 49
36 - # Cleanly initialize Starship checking both system and local paths
50 + # Starship owns the prompt. It must initialize after Oh My Zsh.
37 51 if command -v starship >/dev/null 2>&1; then
38 52 eval "$(starship init zsh)"
39 - elif [[ -f "$HOME/.local/bin/starship" ]]; then
40 - eval "$($HOME/.local/bin/starship init zsh)"
53 + elif [[ -x "$HOME/.local/bin/starship" ]]; then
54 + eval "$("$HOME/.local/bin/starship" init zsh)"
41 55 fi
42 -
43 - # =============================================================================
44 - # 4. PLUGINS (Loaded directly from ~/.zsh)
45 - # =============================================================================
46 - # Autosuggestions
47 - source_if_readable "$HOME/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh"
48 -
49 - # Syntax Highlighting (CRITICAL: Must be the absolute last thing loaded)
50 - source_if_readable "$HOME/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"

weehong revisou este gist 2 weeks ago. Ir para a revisão

5 files changed, 97 insertions, 116 deletions

sourcerc

@@ -1,35 +1,37 @@
1 1 # =============================================================================
2 2 # FILE: ~/.sourcerc
3 - # Description: Initializes third-party package managers and Oh My Zsh.
3 + # Description: Initializes third-party package managers and external tools.
4 4 # =============================================================================
5 5
6 - # Source the custom environment setup file if it exists and is not empty
6 + # =============================================================================
7 + # GENERAL ENV
8 + # =============================================================================
7 9 if [[ -f "$HOME/.local/bin/env" && -r "$HOME/.local/bin/env" ]]; then
8 10 source "$HOME/.local/bin/env"
9 11 fi
10 12
11 - # Source the SDKMAN initialization script if it exists and is not empty
12 - if [[ -f "$HOME/.sdkman/bin/sdkman-init.sh" && -r "$HOME/.sdkman/bin/sdkman-init.sh" ]]; then
13 - source "$HOME/.sdkman/bin/sdkman-init.sh"
14 - fi
15 -
16 - # Source the NVM initialization script if it exists and is not empty
17 - if [[ -f "$HOME/.nvm/nvm.sh" && -r "$HOME/.nvm/nvm.sh" ]]; then
18 - source "$HOME/.nvm/nvm.sh"
19 - fi
20 -
21 13 # =============================================================================
22 14 # CLAUDE CODE / AI GATEWAY
23 15 # =============================================================================
24 16 export ANTHROPIC_BASE_URL="https://gateway.ai.cloudflare.com/v1/9a71825e3842e918e0dff9ad84f50484/claude-code-gateway/anthropic"
25 17
26 18 # =============================================================================
27 - # OH MY ZSH
19 + # SDKMAN (Java/Kotlin/Scala Version Manager)
20 + # =============================================================================
21 + export SDKMAN_DIR="$HOME/.sdkman"
22 + if [[ -f "$SDKMAN_DIR/bin/sdkman-init.sh" && -r "$SDKMAN_DIR/bin/sdkman-init.sh" ]]; then
23 + source "$SDKMAN_DIR/bin/sdkman-init.sh"
24 + fi
25 +
26 + # =============================================================================
27 + # NVM (Node Version Manager)
28 28 # =============================================================================
29 - if [[ -f "$HOME/.oh-my-zsh/oh-my-zsh.sh" && -r "$HOME/.oh-my-zsh/oh-my-zsh.sh" ]]; then
30 - source "$HOME/.oh-my-zsh/oh-my-zsh.sh"
31 - else
32 - echo "Warning: Oh My Zsh not found or is empty."
29 + export NVM_DIR="$HOME/.nvm"
30 + if [[ -f "$NVM_DIR/nvm.sh" && -r "$NVM_DIR/nvm.sh" ]]; then
31 + source "$NVM_DIR/nvm.sh"
32 + fi
33 + if [[ -f "$NVM_DIR/bash_completion" && -r "$NVM_DIR/bash_completion" ]]; then
34 + source "$NVM_DIR/bash_completion"
33 35 fi
34 36
35 37 # =============================================================================
@@ -41,12 +43,4 @@ fi
41 43
42 44 if [[ -f "$HOME/google-cloud-sdk/completion.zsh.inc" ]]; then
43 45 source "$HOME/google-cloud-sdk/completion.zsh.inc"
44 - fi
45 -
46 - # =============================================================================
47 - # NVM (Node Version Manager)
48 - # =============================================================================
49 - export NVM_DIR="$HOME/.nvm"
50 -
51 - [[ -f "$NVM_DIR/nvm.sh" && -r "$NVM_DIR/nvm.sh" ]] && \. "$NVM_DIR/nvm.sh"
52 - [[ -f "$NVM_DIR/bash_completion" && -r "$NVM_DIR/bash_completion" ]] && \. "$NVM_DIR/bash_completion"
46 + fi

zsh_macos.sh

@@ -58,7 +58,7 @@ install_plugins() {
58 58 }
59 59
60 60 install_starship() {
61 - if command -v starship >/dev/null 2>&1; then
61 + if command -v starship >/dev/null 2>&1 || [[ -f "$HOME/.local/bin/starship" ]]; then
62 62 ok "Starship already installed"
63 63 elif command -v brew >/dev/null 2>&1; then
64 64 log "Installing Starship with Homebrew..."
@@ -109,10 +109,24 @@ configure_zshrc() {
109 109
110 110 touch "$zshrc"
111 111
112 - # Add Starship init if not present
112 + # CRITICAL FIX: Purge old corrupted multi-line/plaintext starship lines
113 + if [[ -f "$zshrc" ]]; then
114 + sed -i '' '/starship init zsh/d' "$zshrc" 2>/dev/null || true
115 + sed -i '' '/firing,/d' "$zshrc" 2>/dev/null || true
116 + fi
117 +
118 + # Ensure local binary path is explicitly loaded first
119 + if ! grep -q '\.local/bin' "$zshrc"; then
120 + # macOS sed requires an empty string argument with -i
121 + sed -i '' '1i\
122 + export PATH="$HOME/.local/bin:$PATH"
123 + ' "$zshrc" 2>/dev/null || echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$zshrc"
124 + fi
125 +
126 + # Cleanly inject one-line safe evaluator
113 127 if ! grep -q 'starship init zsh' "$zshrc"; then
114 128 echo -e '\n# Initialize Starship' >> "$zshrc"
115 - echo 'eval "$(starship init zsh)"' >> "$zshrc"
129 + echo 'if command -v starship >/dev/null 2>&1; then eval "$(starship init zsh)"; else eval "$($HOME/.local/bin/starship init zsh)"; fi' >> "$zshrc"
116 130 fi
117 131
118 132 # Add autosuggestions if not present
@@ -126,7 +140,7 @@ configure_zshrc() {
126 140 echo 'source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh' >> "$zshrc"
127 141 fi
128 142
129 - ok ".zshrc configured for zero-framework setup!"
143 + ok ".zshrc configured cleanly for zero-framework setup!"
130 144 ok "Load order is preserved: .sourcerc -> .func -> .pathrc -> .alias"
131 145 }
132 146

zsh_ubuntu.sh

@@ -138,7 +138,7 @@ install_plugins() {
138 138 }
139 139
140 140 install_starship() {
141 - if command -v starship >/dev/null 2>&1; then
141 + if command -v starship >/dev/null 2>&1 || [[ -f "$HOME/.local/bin/starship" ]]; then
142 142 ok "Starship already installed"
143 143 else
144 144 log "Installing Starship prompt..."
@@ -188,10 +188,21 @@ configure_zshrc() {
188 188
189 189 touch "$zshrc"
190 190
191 - # Add Starship init if not present
191 + # CRITICAL FIX: Purge old corrupted multi-line/plaintext starship lines that broke preexec
192 + if [[ -f "$zshrc" ]]; then
193 + sed -i '/starship init zsh/d' "$zshrc" 2>/dev/null || true
194 + sed -i '/firing,/d' "$zshrc" 2>/dev/null || true
195 + fi
196 +
197 + # Ensure local binary path is explicitly loaded first
198 + if ! grep -q '\.local/bin' "$zshrc"; then
199 + sed -i '1i\export PATH="$HOME/.local/bin:$PATH"' "$zshrc" 2>/dev/null || echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$zshrc"
200 + fi
201 +
202 + # Cleanly inject one-line safe evaluator
192 203 if ! grep -q 'starship init zsh' "$zshrc"; then
193 204 echo -e '\n# Initialize Starship' >> "$zshrc"
194 - echo 'eval "$(starship init zsh)"' >> "$zshrc"
205 + echo 'if command -v starship >/dev/null 2>&1; then eval "$(starship init zsh)"; else eval "$($HOME/.local/bin/starship init zsh)"; fi' >> "$zshrc"
195 206 fi
196 207
197 208 # Add autosuggestions if not present
@@ -200,12 +211,12 @@ configure_zshrc() {
200 211 echo 'source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh' >> "$zshrc"
201 212 fi
202 213
203 - # Add syntax highlighting if not present (MUST be last)
214 + # Add syntax highlighting if not present (MUST be last line)
204 215 if ! grep -q 'zsh-syntax-highlighting.zsh' "$zshrc"; then
205 216 echo 'source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh' >> "$zshrc"
206 217 fi
207 218
208 - ok ".zshrc configured for zero-framework setup!"
219 + ok ".zshrc configured cleanly for zero-framework setup!"
209 220 }
210 221
211 222 switch_shell() {

zsh_wsl.sh

@@ -142,7 +142,7 @@ install_plugins() {
142 142 }
143 143
144 144 install_starship() {
145 - if command -v starship >/dev/null 2>&1; then
145 + if command -v starship >/dev/null 2>&1 || [[ -f "$HOME/.local/bin/starship" ]]; then
146 146 ok "Starship already installed"
147 147 else
148 148 log "Installing Starship prompt..."
@@ -192,10 +192,21 @@ configure_zshrc() {
192 192
193 193 touch "$zshrc"
194 194
195 - # Add Starship init if not present
195 + # CRITICAL FIX: Purge old corrupted multi-line/plaintext starship lines
196 + if [[ -f "$zshrc" ]]; then
197 + sed -i '/starship init zsh/d' "$zshrc" 2>/dev/null || true
198 + sed -i '/firing,/d' "$zshrc" 2>/dev/null || true
199 + fi
200 +
201 + # Ensure local binary path is explicitly loaded first
202 + if ! grep -q '\.local/bin' "$zshrc"; then
203 + sed -i '1i\export PATH="$HOME/.local/bin:$PATH"' "$zshrc" 2>/dev/null || echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$zshrc"
204 + fi
205 +
206 + # Cleanly inject one-line safe evaluator
196 207 if ! grep -q 'starship init zsh' "$zshrc"; then
197 208 echo -e '\n# Initialize Starship' >> "$zshrc"
198 - echo 'eval "$(starship init zsh)"' >> "$zshrc"
209 + echo 'if command -v starship >/dev/null 2>&1; then eval "$(starship init zsh)"; else eval "$($HOME/.local/bin/starship init zsh)"; fi' >> "$zshrc"
199 210 fi
200 211
201 212 # Add autosuggestions if not present
@@ -209,7 +220,7 @@ configure_zshrc() {
209 220 echo 'source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh' >> "$zshrc"
210 221 fi
211 222
212 - ok ".zshrc configured for zero-framework setup!"
223 + ok ".zshrc configured cleanly for zero-framework setup!"
213 224 }
214 225
215 226 switch_shell() {

zshrc

@@ -1,8 +1,6 @@
1 1 # =============================================================================
2 - # 1. ZSH THEME & PLUGINS (Must be defined before Oh My Zsh loads)
2 + # 1. HELPER FUNCTIONS & PATH
3 3 # =============================================================================
4 - export ZSH="$HOME/.oh-my-zsh"
5 -
6 4 source_if_readable() {
7 5 local file="$1"
8 6 if [[ -f "$file" && -r "$file" ]]; then
@@ -10,90 +8,43 @@ source_if_readable() {
10 8 fi
11 9 }
12 10
13 - ZSH_THEME_CHOICE="${ZSH_THEME_CHOICE:-}"
14 - if [[ -z "$ZSH_THEME_CHOICE" && -f "$HOME/.zsh_theme" ]]; then
15 - ZSH_THEME_CHOICE="$(<"$HOME/.zsh_theme")"
16 - fi
17 - ZSH_THEME_CHOICE="${ZSH_THEME_CHOICE:-spaceship}"
18 -
19 - case "$ZSH_THEME_CHOICE" in
20 - starship)
21 - ZSH_THEME=""
22 - ;;
23 - spaceship|*)
24 - ZSH_THEME="spaceship"
25 -
26 - SPACESHIP_PROMPT_ORDER=(
27 - time # Time stamps section
28 - user # Username section
29 - dir # Current directory section
30 - git # Git section (git_branch + git_status)
31 - node # Node.js section
32 - dotnet # .NET section
33 - java # Java section
34 - kotlin # Kotlin section
35 - ruby # Ruby section
36 - xcode # Xcode section
37 - swift # Swift section
38 - golang # Go section
39 - docker # Docker section
40 - venv # virtualenv section
41 - line_sep # Line break
42 - char # Prompt character
43 - )
44 -
45 - SPACESHIP_USER_SHOW=always
46 - SPACESHIP_PROMPT_SEPARATE_LINE=true
47 - SPACESHIP_PROMPT_ADD_NEWLINE=true
48 - SPACESHIP_CHAR_SYMBOL="❯"
49 - SPACESHIP_CHAR_SUFFIX=" "
50 - SPACESHIP_DOCKER_CONTEXT_SHOW=false
51 -
52 - if [[ $(uname) == "Darwin" ]]; then
53 - #  is the Apple logo in Nerd Fonts
54 - SPACESHIP_USER_SUFFIX="%F{cyan} [  ]%f "
55 - elif [[ $(uname) == "Linux" ]]; then
56 - #  is the Ubuntu logo in Nerd Fonts
57 - SPACESHIP_USER_SUFFIX="%F{yellow} [  ]%f "
58 - else
59 - SPACESHIP_USER_SUFFIX=" "
60 - fi
61 - ;;
62 - esac
63 -
64 - plugins=(git zsh-syntax-highlighting zsh-autosuggestions)
65 -
66 - # Initialize Oh My Zsh (Crucial for themes and plugins to work)
67 - source_if_readable "$ZSH/oh-my-zsh.sh"
11 + # Ensure local bin is in PATH early (catches manual Starship installations)
12 + export PATH="$HOME/.local/bin:$PATH"
68 13
69 14 # =============================================================================
70 - # 2. THIRD-PARTY INITIALIZATION (SDKMAN, NVM, Oh My Zsh)
15 + # 2. THIRD-PARTY INITIALIZATION & CUSTOM CONFIGS
71 16 # =============================================================================
17 + # Load external initializers (SDKMAN, NVM, etc.)
72 18 source_if_readable "$HOME/.sourcerc"
73 19
74 - # =============================================================================
75 - # 3. CUSTOM OVERRIDES (Functions must load before Path Management)
76 - # =============================================================================
20 + # Custom Functions (must load before Path Management)
77 21 source_if_readable "$HOME/.func"
78 22
79 - # =============================================================================
80 - # 4. PATH MANAGEMENT (Relies on append_path from .func)
81 - # =============================================================================
23 + # Path Management (Relies on append_path from .func)
82 24 source_if_readable "$HOME/.pathrc"
83 25
84 - # =============================================================================
85 - # 5. ALIASES (Loaded dead last so YOUR code always wins over Oh My Zsh)
86 - # =============================================================================
26 + # Aliases (Loaded late so they override system defaults)
87 27 source_if_readable "$HOME/.alias"
88 28
89 - if [[ "$ZSH_THEME_CHOICE" == "starship" ]]; then
90 - if [[ -z "${STARSHIP_CONFIG:-}" && -f "$HOME/.config/starship.toml" ]]; then
91 - export STARSHIP_CONFIG="$HOME/.config/starship.toml"
92 - fi
29 + # =============================================================================
30 + # 3. STARSHIP PROMPT
31 + # =============================================================================
32 + if [[ -z "${STARSHIP_CONFIG:-}" && -f "$HOME/.config/starship.toml" ]]; then
33 + export STARSHIP_CONFIG="$HOME/.config/starship.toml"
34 + fi
93 35
94 - if command -v starship >/dev/null 2>&1; then
95 - eval "$(starship init zsh)"
96 - else
97 - echo "Warning: Starship selected but starship is not installed."
98 - fi
36 + # Cleanly initialize Starship checking both system and local paths
37 + if command -v starship >/dev/null 2>&1; then
38 + eval "$(starship init zsh)"
39 + elif [[ -f "$HOME/.local/bin/starship" ]]; then
40 + eval "$($HOME/.local/bin/starship init zsh)"
99 41 fi
42 +
43 + # =============================================================================
44 + # 4. PLUGINS (Loaded directly from ~/.zsh)
45 + # =============================================================================
46 + # Autosuggestions
47 + source_if_readable "$HOME/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh"
48 +
49 + # Syntax Highlighting (CRITICAL: Must be the absolute last thing loaded)
50 + source_if_readable "$HOME/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"

weehong revisou este gist 2 weeks ago. Ir para a revisão

3 files changed, 194 insertions, 312 deletions

zsh_macos.sh

@@ -43,21 +43,9 @@ check_requirements() {
43 43 # =============================
44 44 # INSTALLATION FUNCTIONS
45 45 # =============================
46 - install_oh_my_zsh() {
47 - if [[ -d "$HOME/.oh-my-zsh" ]]; then
48 - ok "Oh My Zsh already installed"
49 - return
50 - fi
51 -
52 - log "Installing Oh My Zsh..."
53 - RUNZSH=no CHSH=no KEEP_ZSHRC=yes \
54 - sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
55 - ok "Oh My Zsh installed"
56 - }
57 -
58 46 install_plugins() {
59 - log "Installing plugins..."
60 - local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins"
47 + log "Installing manual Zsh plugins..."
48 + local dir="$HOME/.zsh"
61 49 mkdir -p "$dir"
62 50
63 51 [[ -d "$dir/zsh-autosuggestions" ]] || \
@@ -66,39 +54,10 @@ install_plugins() {
66 54 [[ -d "$dir/zsh-syntax-highlighting" ]] || \
67 55 git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting"
68 56
69 - ok "Plugins installed"
70 - }
71 -
72 - install_spaceship_theme() {
73 - log "Installing Spaceship theme..."
74 - local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes"
75 - local dir="$themes/spaceship-prompt"
76 -
77 - mkdir -p "$themes"
78 - [[ -d "$dir" ]] || \
79 - git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1
80 -
81 - ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme"
82 - ok "Spaceship theme installed"
83 - }
84 -
85 - install_starship_config() {
86 - local target="$HOME/.config/starship.toml"
87 - local tmp="${target}.tmp.$$"
88 -
89 - log "Installing Starship config..."
90 - mkdir -p "$(dirname "$target")"
91 -
92 - if curl -fsSL "$GIST_RAW_BASE/starship.toml" -o "$tmp"; then
93 - mv "$tmp" "$target"
94 - ok "Starship config installed at $target"
95 - else
96 - rm -f "$tmp"
97 - warn "Failed to download Starship config"
98 - fi
57 + ok "Plugins installed directly to $dir"
99 58 }
100 59
101 - install_starship_theme() {
60 + install_starship() {
102 61 if command -v starship >/dev/null 2>&1; then
103 62 ok "Starship already installed"
104 63 elif command -v brew >/dev/null 2>&1; then
@@ -111,34 +70,6 @@ install_starship_theme() {
111 70 curl -fsSL https://starship.rs/install.sh | sh -s -- -y -b "$HOME/.local/bin"
112 71 ok "Starship installed"
113 72 fi
114 -
115 - install_starship_config
116 - }
117 -
118 - install_theme() {
119 - local choice="${1:-}"
120 - local selected_theme
121 -
122 - if [[ -z "$choice" ]]; then
123 - echo "Select prompt theme:"
124 - echo " 1) Spaceship"
125 - echo " 2) Starship"
126 - read -r -p "Select theme [1-2]: " choice
127 - fi
128 -
129 - case "$(printf '%s' "$choice" | tr '[:upper:]' '[:lower:]')" in
130 - 1|spaceship) selected_theme="spaceship" ;;
131 - 2|starship) selected_theme="starship" ;;
132 - *) warn "Invalid theme selection: $choice"; return 1 ;;
133 - esac
134 -
135 - case "$selected_theme" in
136 - spaceship) install_spaceship_theme ;;
137 - starship) install_starship_theme ;;
138 - esac
139 -
140 - printf "%s\n" "$selected_theme" > "$HOME/.zsh_theme"
141 - ok "Theme selected: $selected_theme"
142 73 }
143 74
144 75 download_configs() {
@@ -172,17 +103,31 @@ download_configs() {
172 103 ok "Configs downloaded (Backup at $backup)"
173 104 }
174 105
175 - update_zshrc() {
106 + configure_zshrc() {
176 107 local zshrc="$HOME/.zshrc"
177 - log "Checking .zshrc..."
108 + log "Configuring .zshrc for plugins and Starship..."
109 +
110 + touch "$zshrc"
111 +
112 + # Add Starship init if not present
113 + if ! grep -q 'starship init zsh' "$zshrc"; then
114 + echo -e '\n# Initialize Starship' >> "$zshrc"
115 + echo 'eval "$(starship init zsh)"' >> "$zshrc"
116 + fi
117 +
118 + # Add autosuggestions if not present
119 + if ! grep -q 'zsh-autosuggestions.zsh' "$zshrc"; then
120 + echo -e '\n# Load Plugins' >> "$zshrc"
121 + echo 'source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh' >> "$zshrc"
122 + fi
178 123
179 - if [[ ! -f "$zshrc" ]]; then
180 - warn ".zshrc not found. Run option 5 first."
181 - return 1
124 + # Add syntax highlighting if not present (MUST be last)
125 + if ! grep -q 'zsh-syntax-highlighting.zsh' "$zshrc"; then
126 + echo 'source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh' >> "$zshrc"
182 127 fi
183 128
184 - ok ".zshrc already comes from the managed gist."
185 - ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias"
129 + ok ".zshrc configured for zero-framework setup!"
130 + ok "Load order is preserved: .sourcerc -> .func -> .pathrc -> .alias"
186 131 }
187 132
188 133 switch_shell() {
@@ -199,16 +144,15 @@ switch_shell() {
199 144 # =============================
200 145 show_menu() {
201 146 echo "==========================================="
202 - echo "macOS Zsh Setup - Choose what to do"
147 + echo "macOS Minimal Zsh Setup - Choose what to do"
203 148 echo "==========================================="
204 - echo " 0) Run ALL steps (1-7)"
205 - echo " 1) Install Oh My Zsh"
206 - echo " 2) Install plugins (autosuggestions, syntax highlighting)"
207 - echo " 3) Install/select prompt theme (Spaceship or Starship)"
208 - echo " 4) Download custom configs (~/.alias, .func, .vimrc, etc.)"
209 - echo " 5) Check ~/.zshrc load order"
210 - echo " 6) Switch to Zsh (Temporary Sub-shell)"
211 - echo " 7) Quit"
149 + echo " 0) Run ALL steps (1-5)"
150 + echo " 1) Install manual Zsh plugins (autosuggestions, syntax highlighting)"
151 + echo " 2) Install Starship prompt"
152 + echo " 3) Download custom configs (~/.alias, .func, .vimrc, etc.)"
153 + echo " 4) Configure ~/.zshrc (Inject Starship & Plugins)"
154 + echo " 5) Switch to Zsh (Temporary Sub-shell)"
155 + echo " 6) Quit"
212 156 echo "==========================================="
213 157 }
214 158
@@ -224,7 +168,7 @@ run_choices() {
224 168 if [[ "$item" == !* ]]; then
225 169 to_exclude+=("${item:1}")
226 170 elif [[ "$item" == "0" ]]; then
227 - to_run+=(1 2 3 4 5 6)
171 + to_run+=(1 2 3 4 5)
228 172 else
229 173 to_run+=("$item")
230 174 fi
@@ -246,13 +190,12 @@ run_choices() {
246 190 $skip && continue
247 191
248 192 case "$choice" in
249 - 1) install_oh_my_zsh ;;
250 - 2) install_plugins ;;
251 - 3) install_theme ;;
252 - 4) download_configs ;;
253 - 5) update_zshrc ;;
254 - 6) switch_shell ;;
255 - 7) exit 0 ;;
193 + 1) install_plugins ;;
194 + 2) install_starship ;;
195 + 3) download_configs ;;
196 + 4) configure_zshrc ;;
197 + 5) switch_shell ;;
198 + 6) exit 0 ;;
256 199 *) warn "Skipping invalid option: $choice" ;;
257 200 esac
258 201 echo
@@ -271,7 +214,7 @@ main() {
271 214 read -p "Do you want to run more options? (y/n): " again
272 215 [[ "$again" =~ ^[Yy]$ ]] || break
273 216 done
274 - ok "macOS configuration complete!"
217 + ok "macOS minimal Zsh configuration complete!"
275 218 }
276 219
277 220 main "$@"

zsh_ubuntu.sh

@@ -37,7 +37,9 @@ CONFIG_FILES=(
37 37 # OS DETECTION
38 38 # =============================
39 39 detect_os() {
40 - if [ -f /etc/os-release ]; then
40 + if [[ "$OSTYPE" == "darwin"* ]]; then
41 + echo "macos"
42 + elif [ -f /etc/os-release ]; then
41 43 . /etc/os-release
42 44 echo "$ID"
43 45 else
@@ -50,11 +52,11 @@ detect_os() {
50 52 # =============================
51 53 check_requirements() {
52 54 if [[ $EUID -eq 0 ]]; then
53 - err "Do not run as root"
55 + err "Do not run as root. The script will request sudo when necessary."
54 56 exit 1
55 57 fi
56 - if ! command -v sudo >/dev/null 2>&1; then
57 - err "sudo required"
58 + if [[ "$(detect_os)" != "macos" ]] && ! command -v sudo >/dev/null 2>&1; then
59 + err "sudo required on Linux"
58 60 exit 1
59 61 fi
60 62 }
@@ -65,22 +67,41 @@ check_requirements() {
65 67 update_system() {
66 68 $SKIP_PACKAGES && return
67 69 log "Updating system..."
68 - sudo apt-get update -y
69 - sudo apt-get upgrade -y
70 + local os=$(detect_os)
71 +
72 + case "$os" in
73 + macos) brew update ;;
74 + ubuntu|debian) sudo apt-get update -y && sudo apt-get upgrade -y ;;
75 + fedora) sudo dnf upgrade -y ;;
76 + arch) sudo pacman -Syu --noconfirm ;;
77 + *) warn "Auto-update not supported for OS: $os" ;;
78 + esac
70 79 ok "System updated"
71 80 }
72 81
73 82 install_packages() {
74 83 $SKIP_PACKAGES && return
75 84 log "Installing core packages..."
76 - sudo apt-get install -y \
77 - zsh git vim curl wget unzip zip build-essential xz-utils
85 + local os=$(detect_os)
86 +
87 + case "$os" in
88 + macos) brew install zsh git vim curl wget unzip xz ;;
89 + ubuntu|debian) sudo apt-get install -y zsh git vim curl wget unzip zip build-essential xz-utils ;;
90 + fedora) sudo dnf install -y zsh git vim curl wget unzip zip @development-tools xz ;;
91 + arch) sudo pacman -S --noconfirm zsh git vim curl wget unzip zip base-devel xz ;;
92 + *) warn "Auto-install not supported for OS: $os. Please install zsh, git, vim, curl manually." ;;
93 + esac
78 94 ok "Packages installed"
79 95 }
80 96
81 97 set_timezone() {
82 98 log "Setting timezone to Asia/Singapore..."
83 - sudo timedatectl set-timezone Asia/Singapore
99 + local os=$(detect_os)
100 + if [[ "$os" == "macos" ]]; then
101 + sudo systemsetup -settimezone Asia/Singapore >/dev/null
102 + else
103 + sudo timedatectl set-timezone Asia/Singapore
104 + fi
84 105 ok "Timezone set to Asia/Singapore"
85 106 }
86 107
@@ -97,104 +118,46 @@ configure_shell() {
97 118 log "Changing default shell to zsh..."
98 119 local zsh_path
99 120 zsh_path="$(command -v zsh)"
100 - grep -qx "$zsh_path" /etc/shells || echo "$zsh_path" | sudo tee -a /etc/shells >/dev/null
121 +
122 + if ! grep -qx "$zsh_path" /etc/shells; then
123 + echo "$zsh_path" | sudo tee -a /etc/shells >/dev/null
124 + fi
101 125 chsh -s "$zsh_path"
102 126 ok "Shell changed (requires logout/login to take effect)"
103 127 }
104 128
105 - install_oh_my_zsh() {
106 - [[ -d "$HOME/.oh-my-zsh" ]] && ok "Oh My Zsh already installed" && return
107 - log "Installing Oh My Zsh..."
108 - RUNZSH=no CHSH=no KEEP_ZSHRC=yes \
109 - sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
110 - ok "Oh My Zsh installed"
111 - }
112 -
113 129 install_plugins() {
114 - log "Installing plugins..."
115 - local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins"
130 + log "Installing manual Zsh plugins..."
131 + local dir="$HOME/.zsh"
116 132 mkdir -p "$dir"
133 +
117 134 [[ -d "$dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions"
118 135 [[ -d "$dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting"
119 - ok "Plugins installed"
120 - }
121 -
122 - install_spaceship_theme() {
123 - log "Installing Spaceship theme..."
124 - local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes"
125 - local dir="$themes/spaceship-prompt"
126 - mkdir -p "$themes"
127 - [[ -d "$dir" ]] || git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1
128 - ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme"
129 - ok "Spaceship theme installed"
136 +
137 + ok "Plugins installed directly to $dir"
130 138 }
131 139
132 - install_starship_config() {
133 - local target="$HOME/.config/starship.toml"
134 - local tmp="${target}.tmp.$$"
135 -
136 - log "Installing Starship config..."
137 - mkdir -p "$(dirname "$target")"
138 -
139 - if curl -fsSL "$GIST_RAW_BASE/starship.toml" -o "$tmp"; then
140 - mv "$tmp" "$target"
141 - ok "Starship config installed at $target"
142 - else
143 - rm -f "$tmp"
144 - warn "Failed to download Starship config"
145 - fi
146 - }
147 -
148 - install_starship_theme() {
140 + install_starship() {
149 141 if command -v starship >/dev/null 2>&1; then
150 142 ok "Starship already installed"
151 - elif command -v brew >/dev/null 2>&1; then
152 - log "Installing Starship with Homebrew..."
153 - brew install starship
154 - ok "Starship installed"
155 143 else
156 - log "Installing Starship..."
157 - mkdir -p "$HOME/.local/bin"
158 - curl -fsSL https://starship.rs/install.sh | sh -s -- -y -b "$HOME/.local/bin"
144 + log "Installing Starship prompt..."
145 + if command -v brew >/dev/null 2>&1; then
146 + brew install starship
147 + else
148 + mkdir -p "$HOME/.local/bin"
149 + curl -fsSL https://starship.rs/install.sh | sh -s -- -y -b "$HOME/.local/bin"
150 + fi
159 151 ok "Starship installed"
160 152 fi
161 -
162 - install_starship_config
163 - }
164 -
165 - install_theme() {
166 - local choice="${1:-}"
167 - local selected_theme
168 -
169 - if [[ -z "$choice" ]]; then
170 - echo "Select prompt theme:"
171 - echo " 1) Spaceship"
172 - echo " 2) Starship"
173 - read -r -p "Select theme [1-2]: " choice
174 - fi
175 -
176 - case "$(printf '%s' "$choice" | tr '[:upper:]' '[:lower:]')" in
177 - 1|spaceship) selected_theme="spaceship" ;;
178 - 2|starship) selected_theme="starship" ;;
179 - *) warn "Invalid theme selection: $choice"; return 1 ;;
180 - esac
181 -
182 - case "$selected_theme" in
183 - spaceship) install_spaceship_theme ;;
184 - starship) install_starship_theme ;;
185 - esac
186 -
187 - printf "%s\n" "$selected_theme" > "$HOME/.zsh_theme"
188 - ok "Theme selected: $selected_theme"
189 153 }
190 154
191 155 download_configs() {
192 - log "Downloading custom config files..."
156 + log "Downloading custom config files from OpenGist..."
193 157 local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)"
194 158 mkdir -p "$backup"
195 159
196 160 for f in "${CONFIG_FILES[@]}"; do
197 - # Strip the leading dot for the download URL
198 161 local remote_file="${f#.}"
199 162 [[ "$f" == ".config/starship.toml" ]] && remote_file="starship.toml"
200 163 local url="$GIST_RAW_BASE/$remote_file"
@@ -219,17 +182,30 @@ download_configs() {
219 182 ok "Configs downloaded (Backup at $backup)"
220 183 }
221 184
222 - update_zshrc() {
185 + configure_zshrc() {
223 186 local zshrc="$HOME/.zshrc"
224 - log "Checking .zshrc..."
187 + log "Configuring .zshrc for plugins and Starship..."
188 +
189 + touch "$zshrc"
190 +
191 + # Add Starship init if not present
192 + if ! grep -q 'starship init zsh' "$zshrc"; then
193 + echo -e '\n# Initialize Starship' >> "$zshrc"
194 + echo 'eval "$(starship init zsh)"' >> "$zshrc"
195 + fi
196 +
197 + # Add autosuggestions if not present
198 + if ! grep -q 'zsh-autosuggestions.zsh' "$zshrc"; then
199 + echo -e '\n# Load Plugins' >> "$zshrc"
200 + echo 'source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh' >> "$zshrc"
201 + fi
225 202
226 - if [[ ! -f "$zshrc" ]]; then
227 - warn ".zshrc not found. Run option 9 first."
228 - return 1
203 + # Add syntax highlighting if not present (MUST be last)
204 + if ! grep -q 'zsh-syntax-highlighting.zsh' "$zshrc"; then
205 + echo 'source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh' >> "$zshrc"
229 206 fi
230 207
231 - ok ".zshrc already comes from the managed gist."
232 - ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias"
208 + ok ".zshrc configured for zero-framework setup!"
233 209 }
234 210
235 211 switch_shell() {
@@ -246,21 +222,20 @@ switch_shell() {
246 222 # =============================
247 223 show_menu() {
248 224 echo "==========================================="
249 - echo "Zsh Installer - Choose what to do"
225 + echo "Minimal Zsh Installer - Choose what to do"
250 226 echo "==========================================="
251 - echo " 0) Run ALL steps (1-11)"
227 + echo " 0) Run ALL steps (1-10)"
252 228 echo " 1) Update system packages"
253 229 echo " 2) Install core packages (zsh, git, vim, etc.)"
254 230 echo " 3) Set Timezone (Asia/Singapore)"
255 231 echo " 4) Install Homebrew"
256 232 echo " 5) Configure shell (chsh - sets default shell)"
257 - echo " 6) Install Oh My Zsh"
258 - echo " 7) Install plugins (autosuggestions, syntax highlighting)"
259 - echo " 8) Install/select prompt theme (Spaceship or Starship)"
260 - echo " 9) Download custom configs (~/.alias, .vimrc, etc.)"
261 - echo "10) Check ~/.zshrc load order"
262 - echo "11) Switch to Zsh (Temporary Sub-shell)"
263 - echo "12) Quit"
233 + echo " 6) Install manual Zsh plugins (Autosuggestions, Syntax Highlighting)"
234 + echo " 7) Install Starship prompt"
235 + echo " 8) Download custom configs (from OpenGist)"
236 + echo " 9) Configure ~/.zshrc (Inject Starship & Plugins)"
237 + echo "10) Switch to Zsh (Temporary Sub-shell)"
238 + echo "11) Quit"
264 239 echo "==========================================="
265 240 }
266 241
@@ -276,7 +251,7 @@ run_choices() {
276 251 if [[ "$item" == !* ]]; then
277 252 to_exclude+=("${item:1}")
278 253 elif [[ "$item" == "0" ]]; then
279 - to_run+=(1 2 3 4 5 6 7 8 9 10 11)
254 + to_run+=(1 2 3 4 5 6 7 8 9 10)
280 255 else
281 256 to_run+=("$item")
282 257 fi
@@ -300,13 +275,12 @@ run_choices() {
300 275 3) set_timezone ;;
301 276 4) install_homebrew ;;
302 277 5) configure_shell ;;
303 - 6) install_oh_my_zsh ;;
304 - 7) install_plugins ;;
305 - 8) install_theme ;;
306 - 9) download_configs ;;
307 - 10) update_zshrc ;;
308 - 11) switch_shell ;;
309 - 12) log "Exiting..."; exit 0 ;;
278 + 6) install_plugins ;;
279 + 7) install_starship ;;
280 + 8) download_configs ;;
281 + 9) configure_zshrc ;;
282 + 10) switch_shell ;;
283 + 11) log "Exiting..."; exit 0 ;;
310 284 *) warn "Skipping invalid option: $choice" ;;
311 285 esac
312 286 echo

zsh_wsl.sh

@@ -54,7 +54,7 @@ is_wsl() {
54 54 # =============================
55 55 check_requirements() {
56 56 if [[ $EUID -eq 0 ]]; then
57 - err "Do not run as root"
57 + err "Do not run as root. The script will request sudo when necessary."
58 58 exit 1
59 59 fi
60 60 if ! command -v sudo >/dev/null 2>&1; then
@@ -73,16 +73,28 @@ check_requirements() {
73 73 update_system() {
74 74 $SKIP_PACKAGES && return
75 75 log "Updating system..."
76 - sudo apt-get update -y
77 - sudo apt-get upgrade -y
76 + local os=$(detect_os)
77 +
78 + case "$os" in
79 + ubuntu|debian) sudo apt-get update -y && sudo apt-get upgrade -y ;;
80 + fedora) sudo dnf upgrade -y ;;
81 + arch) sudo pacman -Syu --noconfirm ;;
82 + *) warn "Auto-update not supported for OS: $os" ;;
83 + esac
78 84 ok "System updated"
79 85 }
80 86
81 87 install_packages() {
82 88 $SKIP_PACKAGES && return
83 89 log "Installing core packages..."
84 - sudo apt-get install -y \
85 - zsh git vim curl wget unzip zip build-essential xz-utils
90 + local os=$(detect_os)
91 +
92 + case "$os" in
93 + ubuntu|debian) sudo apt-get install -y zsh git vim curl wget unzip zip build-essential xz-utils ;;
94 + fedora) sudo dnf install -y zsh git vim curl wget unzip zip @development-tools xz ;;
95 + arch) sudo pacman -S --noconfirm zsh git vim curl wget unzip zip base-devel xz ;;
96 + *) warn "Auto-install not supported for OS: $os. Please install zsh, git, vim, curl manually." ;;
97 + esac
86 98 ok "Packages installed"
87 99 }
88 100
@@ -110,104 +122,46 @@ configure_shell() {
110 122 log "Changing default shell to zsh..."
111 123 local zsh_path
112 124 zsh_path="$(command -v zsh)"
113 - grep -qx "$zsh_path" /etc/shells || echo "$zsh_path" | sudo tee -a /etc/shells >/dev/null
125 +
126 + if ! grep -qx "$zsh_path" /etc/shells; then
127 + echo "$zsh_path" | sudo tee -a /etc/shells >/dev/null
128 + fi
114 129 chsh -s "$zsh_path"
115 130 ok "Shell changed (open a new WSL session for it to take effect)"
116 131 }
117 132
118 - install_oh_my_zsh() {
119 - [[ -d "$HOME/.oh-my-zsh" ]] && ok "Oh My Zsh already installed" && return
120 - log "Installing Oh My Zsh..."
121 - RUNZSH=no CHSH=no KEEP_ZSHRC=yes \
122 - sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
123 - ok "Oh My Zsh installed"
124 - }
125 -
126 133 install_plugins() {
127 - log "Installing plugins..."
128 - local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins"
134 + log "Installing manual Zsh plugins..."
135 + local dir="$HOME/.zsh"
129 136 mkdir -p "$dir"
137 +
130 138 [[ -d "$dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions"
131 139 [[ -d "$dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting"
132 - ok "Plugins installed"
133 - }
134 -
135 - install_spaceship_theme() {
136 - log "Installing Spaceship theme..."
137 - local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes"
138 - local dir="$themes/spaceship-prompt"
139 - mkdir -p "$themes"
140 - [[ -d "$dir" ]] || git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1
141 - ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme"
142 - ok "Spaceship theme installed"
143 - }
144 -
145 - install_starship_config() {
146 - local target="$HOME/.config/starship.toml"
147 - local tmp="${target}.tmp.$$"
148 -
149 - log "Installing Starship config..."
150 - mkdir -p "$(dirname "$target")"
151 -
152 - if curl -fsSL "$GIST_RAW_BASE/starship.toml" -o "$tmp"; then
153 - mv "$tmp" "$target"
154 - ok "Starship config installed at $target"
155 - else
156 - rm -f "$tmp"
157 - warn "Failed to download Starship config"
158 - fi
140 +
141 + ok "Plugins installed directly to $dir"
159 142 }
160 143
161 - install_starship_theme() {
144 + install_starship() {
162 145 if command -v starship >/dev/null 2>&1; then
163 146 ok "Starship already installed"
164 - elif command -v brew >/dev/null 2>&1; then
165 - log "Installing Starship with Homebrew..."
166 - brew install starship
167 - ok "Starship installed"
168 147 else
169 - log "Installing Starship..."
170 - mkdir -p "$HOME/.local/bin"
171 - curl -fsSL https://starship.rs/install.sh | sh -s -- -y -b "$HOME/.local/bin"
148 + log "Installing Starship prompt..."
149 + if command -v brew >/dev/null 2>&1; then
150 + brew install starship
151 + else
152 + mkdir -p "$HOME/.local/bin"
153 + curl -fsSL https://starship.rs/install.sh | sh -s -- -y -b "$HOME/.local/bin"
154 + fi
172 155 ok "Starship installed"
173 156 fi
174 -
175 - install_starship_config
176 - }
177 -
178 - install_theme() {
179 - local choice="${1:-}"
180 - local selected_theme
181 -
182 - if [[ -z "$choice" ]]; then
183 - echo "Select prompt theme:"
184 - echo " 1) Spaceship"
185 - echo " 2) Starship"
186 - read -r -p "Select theme [1-2]: " choice
187 - fi
188 -
189 - case "$(printf '%s' "$choice" | tr '[:upper:]' '[:lower:]')" in
190 - 1|spaceship) selected_theme="spaceship" ;;
191 - 2|starship) selected_theme="starship" ;;
192 - *) warn "Invalid theme selection: $choice"; return 1 ;;
193 - esac
194 -
195 - case "$selected_theme" in
196 - spaceship) install_spaceship_theme ;;
197 - starship) install_starship_theme ;;
198 - esac
199 -
200 - printf "%s\n" "$selected_theme" > "$HOME/.zsh_theme"
201 - ok "Theme selected: $selected_theme"
202 157 }
203 158
204 159 download_configs() {
205 - log "Downloading custom config files..."
160 + log "Downloading custom config files from OpenGist..."
206 161 local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)"
207 162 mkdir -p "$backup"
208 163
209 164 for f in "${CONFIG_FILES[@]}"; do
210 - # Strip the leading dot for the download URL
211 165 local remote_file="${f#.}"
212 166 [[ "$f" == ".config/starship.toml" ]] && remote_file="starship.toml"
213 167 local url="$GIST_RAW_BASE/$remote_file"
@@ -232,17 +186,30 @@ download_configs() {
232 186 ok "Configs downloaded (Backup at $backup)"
233 187 }
234 188
235 - update_zshrc() {
189 + configure_zshrc() {
236 190 local zshrc="$HOME/.zshrc"
237 - log "Checking .zshrc..."
191 + log "Configuring .zshrc for plugins and Starship..."
192 +
193 + touch "$zshrc"
194 +
195 + # Add Starship init if not present
196 + if ! grep -q 'starship init zsh' "$zshrc"; then
197 + echo -e '\n# Initialize Starship' >> "$zshrc"
198 + echo 'eval "$(starship init zsh)"' >> "$zshrc"
199 + fi
200 +
201 + # Add autosuggestions if not present
202 + if ! grep -q 'zsh-autosuggestions.zsh' "$zshrc"; then
203 + echo -e '\n# Load Plugins' >> "$zshrc"
204 + echo 'source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh' >> "$zshrc"
205 + fi
238 206
239 - if [[ ! -f "$zshrc" ]]; then
240 - warn ".zshrc not found. Run option 9 first."
241 - return 1
207 + # Add syntax highlighting if not present (MUST be last)
208 + if ! grep -q 'zsh-syntax-highlighting.zsh' "$zshrc"; then
209 + echo 'source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh' >> "$zshrc"
242 210 fi
243 211
244 - ok ".zshrc already comes from the managed gist."
245 - ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias"
212 + ok ".zshrc configured for zero-framework setup!"
246 213 }
247 214
248 215 switch_shell() {
@@ -259,21 +226,20 @@ switch_shell() {
259 226 # =============================
260 227 show_menu() {
261 228 echo "==========================================="
262 - echo "WSL Zsh Installer - Choose what to do"
229 + echo "WSL Minimal Zsh Installer - Choose what to do"
263 230 echo "==========================================="
264 - echo " 0) Run ALL steps (1-11)"
231 + echo " 0) Run ALL steps (1-10)"
265 232 echo " 1) Update system packages"
266 233 echo " 2) Install core packages (zsh, git, vim, etc.)"
267 234 echo " 3) Set Timezone (best effort)"
268 235 echo " 4) Install Homebrew"
269 236 echo " 5) Configure shell (chsh - sets default shell)"
270 - echo " 6) Install Oh My Zsh"
271 - echo " 7) Install plugins (autosuggestions, syntax highlighting)"
272 - echo " 8) Install/select prompt theme (Spaceship or Starship)"
273 - echo " 9) Download custom configs (~/.alias, .vimrc, etc.)"
274 - echo "10) Check ~/.zshrc load order"
275 - echo "11) Switch to Zsh (Temporary Sub-shell)"
276 - echo "12) Quit"
237 + echo " 6) Install manual Zsh plugins (Autosuggestions, Syntax Highlighting)"
238 + echo " 7) Install Starship prompt"
239 + echo " 8) Download custom configs (from OpenGist)"
240 + echo " 9) Configure ~/.zshrc (Inject Starship & Plugins)"
241 + echo "10) Switch to Zsh (Temporary Sub-shell)"
242 + echo "11) Quit"
277 243 echo "==========================================="
278 244 }
279 245
@@ -289,7 +255,7 @@ run_choices() {
289 255 if [[ "$item" == !* ]]; then
290 256 to_exclude+=("${item:1}")
291 257 elif [[ "$item" == "0" ]]; then
292 - to_run+=(1 2 3 4 5 6 7 8 9 10 11)
258 + to_run+=(1 2 3 4 5 6 7 8 9 10)
293 259 else
294 260 to_run+=("$item")
295 261 fi
@@ -313,13 +279,12 @@ run_choices() {
313 279 3) set_timezone ;;
314 280 4) install_homebrew ;;
315 281 5) configure_shell ;;
316 - 6) install_oh_my_zsh ;;
317 - 7) install_plugins ;;
318 - 8) install_theme ;;
319 - 9) download_configs ;;
320 - 10) update_zshrc ;;
321 - 11) switch_shell ;;
322 - 12) log "Exiting..."; exit 0 ;;
282 + 6) install_plugins ;;
283 + 7) install_starship ;;
284 + 8) download_configs ;;
285 + 9) configure_zshrc ;;
286 + 10) switch_shell ;;
287 + 11) log "Exiting..."; exit 0 ;;
323 288 *) warn "Skipping invalid option: $choice" ;;
324 289 esac
325 290 echo

weehong revisou este gist 3 weeks ago. Ir para a revisão

1 file changed, 1 insertion, 1 deletion

starship.toml

@@ -153,7 +153,7 @@ style = "bg:lavender"
153 153 format = '[[  $time ](fg:crust bg:lavender)]($style)'
154 154
155 155 [line_break]
156 - disabled = true
156 + disabled = false
157 157
158 158 [character]
159 159 disabled = false

weehong revisou este gist 3 weeks ago. Ir para a revisão

2 files changed, 268 insertions, 30 deletions

README.md

@@ -21,4 +21,4 @@ bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996
21 21 ```
22 22
23 23 ### Prompt theme
24 - Run the installer theme option and select either Spaceship or Starship. Starship uses the managed config at `~/.config/starship.toml`.
24 + Run the installer theme option and select either Spaceship or Starship. Starship uses the Catppuccin Powerline preset from the managed config at `~/.config/starship.toml`. A Nerd Font is required for the Powerline symbols.

starship.toml

@@ -1,47 +1,285 @@
1 - "$schema" = "https://starship.rs/config-schema.json"
1 + "$schema" = 'https://starship.rs/config-schema.json'
2 2
3 - add_newline = true
4 - command_timeout = 1000
5 - format = "$time$username$hostname$directory$git_branch$git_status$nodejs$dotnet$java$kotlin$ruby$xcode$swift$golang$docker_context$python$line_break$character"
3 + format = """
4 + [](red)\
5 + $os\
6 + $username\
7 + [](bg:peach fg:red)\
8 + $directory\
9 + [](bg:yellow fg:peach)\
10 + $git_branch\
11 + $git_status\
12 + [](fg:yellow bg:green)\
13 + $c\
14 + $rust\
15 + $golang\
16 + $nodejs\
17 + $bun\
18 + $php\
19 + $java\
20 + $kotlin\
21 + $haskell\
22 + $python\
23 + [](fg:green bg:sapphire)\
24 + $conda\
25 + [](fg:sapphire bg:lavender)\
26 + $time\
27 + [ ](fg:lavender)\
28 + $cmd_duration\
29 + $line_break\
30 + $character"""
6 31
7 - [time]
32 + palette = 'catppuccin_mocha'
33 +
34 + [os]
8 35 disabled = false
9 - format = "[$time]($style) "
10 - time_format = "%R"
11 - style = "dimmed white"
36 + style = "bg:red fg:crust"
37 +
38 + [os.symbols]
39 + Windows = ""
40 + Ubuntu = "󰕈"
41 + SUSE = ""
42 + Raspbian = "󰐿"
43 + Mint = "󰣭"
44 + Macos = "󰀵"
45 + Manjaro = ""
46 + Linux = "󰌽"
47 + Gentoo = "󰣨"
48 + Fedora = "󰣛"
49 + Alpine = ""
50 + Amazon = ""
51 + Android = ""
52 + AOSC = ""
53 + Arch = "󰣇"
54 + Artix = "󰣇"
55 + CentOS = ""
56 + Debian = "󰣚"
57 + Redhat = "󱄛"
58 + RedHatEnterprise = "󱄛"
12 59
13 60 [username]
14 61 show_always = true
15 - format = "[$user]($style) "
16 - style_user = "bold cyan"
17 - style_root = "bold red"
18 -
19 - [hostname]
20 - ssh_only = true
21 - format = "on [$hostname]($style) "
22 - style = "bold yellow"
62 + style_user = "bg:red fg:crust"
63 + style_root = "bg:red fg:crust"
64 + format = '[ $user]($style)'
23 65
24 66 [directory]
67 + style = "bg:peach fg:crust"
68 + format = "[ $path ]($style)"
25 69 truncation_length = 3
26 - truncate_to_repo = false
27 - style = "bold blue"
70 + truncation_symbol = "…/"
71 +
72 + [directory.substitutions]
73 + "Documents" = "󰈙 "
74 + "Downloads" = " "
75 + "Music" = "󰝚 "
76 + "Pictures" = " "
77 + "Developer" = "󰲋 "
28 78
29 79 [git_branch]
30 - symbol = "git:"
31 - format = "on [$symbol$branch]($style) "
32 - style = "bold purple"
80 + symbol = ""
81 + style = "bg:yellow"
82 + format = '[[ $symbol $branch ](fg:crust bg:yellow)]($style)'
33 83
34 84 [git_status]
35 - format = "([$all_status$ahead_behind]($style) )"
36 - style = "bold red"
85 + style = "bg:yellow"
86 + format = '[[($all_status$ahead_behind )](fg:crust bg:yellow)]($style)'
37 87
38 - [character]
39 - success_symbol = "[❯](bold green)"
40 - error_symbol = "[❯](bold red)"
41 - vimcmd_symbol = "[❮](bold green)"
88 + [nodejs]
89 + symbol = ""
90 + style = "bg:green"
91 + format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'
92 +
93 + [bun]
94 + symbol = ""
95 + style = "bg:green"
96 + format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'
97 +
98 + [c]
99 + symbol = " "
100 + style = "bg:green"
101 + format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'
102 +
103 + [rust]
104 + symbol = ""
105 + style = "bg:green"
106 + format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'
107 +
108 + [golang]
109 + symbol = ""
110 + style = "bg:green"
111 + format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'
112 +
113 + [php]
114 + symbol = ""
115 + style = "bg:green"
116 + format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'
117 +
118 + [java]
119 + symbol = " "
120 + style = "bg:green"
121 + format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'
122 +
123 + [kotlin]
124 + symbol = ""
125 + style = "bg:green"
126 + format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'
127 +
128 + [haskell]
129 + symbol = ""
130 + style = "bg:green"
131 + format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'
132 +
133 + [python]
134 + symbol = ""
135 + style = "bg:green"
136 + format = '[[ $symbol( $version)(\(#$virtualenv\)) ](fg:crust bg:green)]($style)'
42 137
43 138 [docker_context]
44 - disabled = true
139 + symbol = ""
140 + style = "bg:sapphire"
141 + format = '[[ $symbol( $context) ](fg:crust bg:sapphire)]($style)'
142 +
143 + [conda]
144 + symbol = "  "
145 + style = "fg:crust bg:sapphire"
146 + format = '[$symbol$environment ]($style)'
147 + ignore_base = false
148 +
149 + [time]
150 + disabled = false
151 + time_format = "%R"
152 + style = "bg:lavender"
153 + format = '[[  $time ](fg:crust bg:lavender)]($style)'
45 154
46 - [package]
155 + [line_break]
47 156 disabled = true
157 +
158 + [character]
159 + disabled = false
160 + success_symbol = '[❯](bold fg:green)'
161 + error_symbol = '[❯](bold fg:red)'
162 + vimcmd_symbol = '[❮](bold fg:green)'
163 + vimcmd_replace_one_symbol = '[❮](bold fg:lavender)'
164 + vimcmd_replace_symbol = '[❮](bold fg:lavender)'
165 + vimcmd_visual_symbol = '[❮](bold fg:yellow)'
166 +
167 + [cmd_duration]
168 + show_milliseconds = true
169 + format = " in $duration "
170 + style = "bg:lavender"
171 + disabled = false
172 + show_notifications = true
173 + min_time_to_notify = 45000
174 +
175 + [palettes.catppuccin_mocha]
176 + rosewater = "#f5e0dc"
177 + flamingo = "#f2cdcd"
178 + pink = "#f5c2e7"
179 + mauve = "#cba6f7"
180 + red = "#f38ba8"
181 + maroon = "#eba0ac"
182 + peach = "#fab387"
183 + yellow = "#f9e2af"
184 + green = "#a6e3a1"
185 + teal = "#94e2d5"
186 + sky = "#89dceb"
187 + sapphire = "#74c7ec"
188 + blue = "#89b4fa"
189 + lavender = "#b4befe"
190 + text = "#cdd6f4"
191 + subtext1 = "#bac2de"
192 + subtext0 = "#a6adc8"
193 + overlay2 = "#9399b2"
194 + overlay1 = "#7f849c"
195 + overlay0 = "#6c7086"
196 + surface2 = "#585b70"
197 + surface1 = "#45475a"
198 + surface0 = "#313244"
199 + base = "#1e1e2e"
200 + mantle = "#181825"
201 + crust = "#11111b"
202 +
203 + [palettes.catppuccin_frappe]
204 + rosewater = "#f2d5cf"
205 + flamingo = "#eebebe"
206 + pink = "#f4b8e4"
207 + mauve = "#ca9ee6"
208 + red = "#e78284"
209 + maroon = "#ea999c"
210 + peach = "#ef9f76"
211 + yellow = "#e5c890"
212 + green = "#a6d189"
213 + teal = "#81c8be"
214 + sky = "#99d1db"
215 + sapphire = "#85c1dc"
216 + blue = "#8caaee"
217 + lavender = "#babbf1"
218 + text = "#c6d0f5"
219 + subtext1 = "#b5bfe2"
220 + subtext0 = "#a5adce"
221 + overlay2 = "#949cbb"
222 + overlay1 = "#838ba7"
223 + overlay0 = "#737994"
224 + surface2 = "#626880"
225 + surface1 = "#51576d"
226 + surface0 = "#414559"
227 + base = "#303446"
228 + mantle = "#292c3c"
229 + crust = "#232634"
230 +
231 + [palettes.catppuccin_latte]
232 + rosewater = "#dc8a78"
233 + flamingo = "#dd7878"
234 + pink = "#ea76cb"
235 + mauve = "#8839ef"
236 + red = "#d20f39"
237 + maroon = "#e64553"
238 + peach = "#fe640b"
239 + yellow = "#df8e1d"
240 + green = "#40a02b"
241 + teal = "#179299"
242 + sky = "#04a5e5"
243 + sapphire = "#209fb5"
244 + blue = "#1e66f5"
245 + lavender = "#7287fd"
246 + text = "#4c4f69"
247 + subtext1 = "#5c5f77"
248 + subtext0 = "#6c6f85"
249 + overlay2 = "#7c7f93"
250 + overlay1 = "#8c8fa1"
251 + overlay0 = "#9ca0b0"
252 + surface2 = "#acb0be"
253 + surface1 = "#bcc0cc"
254 + surface0 = "#ccd0da"
255 + base = "#eff1f5"
256 + mantle = "#e6e9ef"
257 + crust = "#dce0e8"
258 +
259 + [palettes.catppuccin_macchiato]
260 + rosewater = "#f4dbd6"
261 + flamingo = "#f0c6c6"
262 + pink = "#f5bde6"
263 + mauve = "#c6a0f6"
264 + red = "#ed8796"
265 + maroon = "#ee99a0"
266 + peach = "#f5a97f"
267 + yellow = "#eed49f"
268 + green = "#a6da95"
269 + teal = "#8bd5ca"
270 + sky = "#91d7e3"
271 + sapphire = "#7dc4e4"
272 + blue = "#8aadf4"
273 + lavender = "#b7bdf8"
274 + text = "#cad3f5"
275 + subtext1 = "#b8c0e0"
276 + subtext0 = "#a5adcb"
277 + overlay2 = "#939ab7"
278 + overlay1 = "#8087a2"
279 + overlay0 = "#6e738d"
280 + surface2 = "#5b6078"
281 + surface1 = "#494d64"
282 + surface0 = "#363a4f"
283 + base = "#24273a"
284 + mantle = "#1e2030"
285 + crust = "#181926"

weehong revisou este gist 3 weeks ago. Ir para a revisão

Sem alterações

weehong revisou este gist 3 weeks ago. Ir para a revisão

7 files changed, 131 insertions, 17 deletions

README.md

@@ -18,4 +18,7 @@ bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996
18 18 ### Configuration
19 19 ```zsh
20 20 bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/config.sh)"
21 - ```
21 + ```
22 +
23 + ### Prompt theme
24 + Run the installer theme option and select either Spaceship or Starship. Starship uses the managed config at `~/.config/starship.toml`.

config.sh

@@ -10,6 +10,7 @@ CONFIG_FILES=(
10 10 ".sourcerc"
11 11 ".vimrc"
12 12 ".zshrc"
13 + ".config/starship.toml"
13 14 )
14 15
15 16 echo "Starting configuration download..."
@@ -17,10 +18,12 @@ echo "Starting configuration download..."
17 18 for f in "${CONFIG_FILES[@]}"; do
18 19 # Remove the leading dot for the URL path
19 20 remote_name="${f#.}"
21 + [[ "$f" == ".config/starship.toml" ]] && remote_name="starship.toml"
20 22 url="$GIST_RAW_BASE/$remote_name"
21 23 target="$HOME/$f"
22 24
23 25 echo "Downloading $f..."
26 + mkdir -p "$(dirname "$target")"
24 27
25 28 # Use -f to fail silently on server errors, -s for silent, -L to follow redirects
26 29 if curl -fsSL "$url" -o "$target"; then
@@ -30,4 +33,4 @@ for f in "${CONFIG_FILES[@]}"; do
30 33 fi
31 34 done
32 35
33 - echo "Done! All configuration files have been replaced."
36 + echo "Done! All configuration files have been replaced."

starship.toml(arquivo criado)

@@ -0,0 +1,47 @@
1 + "$schema" = "https://starship.rs/config-schema.json"
2 +
3 + add_newline = true
4 + command_timeout = 1000
5 + format = "$time$username$hostname$directory$git_branch$git_status$nodejs$dotnet$java$kotlin$ruby$xcode$swift$golang$docker_context$python$line_break$character"
6 +
7 + [time]
8 + disabled = false
9 + format = "[$time]($style) "
10 + time_format = "%R"
11 + style = "dimmed white"
12 +
13 + [username]
14 + show_always = true
15 + format = "[$user]($style) "
16 + style_user = "bold cyan"
17 + style_root = "bold red"
18 +
19 + [hostname]
20 + ssh_only = true
21 + format = "on [$hostname]($style) "
22 + style = "bold yellow"
23 +
24 + [directory]
25 + truncation_length = 3
26 + truncate_to_repo = false
27 + style = "bold blue"
28 +
29 + [git_branch]
30 + symbol = "git:"
31 + format = "on [$symbol$branch]($style) "
32 + style = "bold purple"
33 +
34 + [git_status]
35 + format = "([$all_status$ahead_behind]($style) )"
36 + style = "bold red"
37 +
38 + [character]
39 + success_symbol = "[❯](bold green)"
40 + error_symbol = "[❯](bold red)"
41 + vimcmd_symbol = "[❮](bold green)"
42 +
43 + [docker_context]
44 + disabled = true
45 +
46 + [package]
47 + disabled = true

zsh_macos.sh

@@ -27,6 +27,7 @@ CONFIG_FILES=(
27 27 ".sourcerc"
28 28 ".vimrc"
29 29 ".zshrc"
30 + ".config/starship.toml"
30 31 )
31 32
32 33 # =============================
@@ -81,22 +82,37 @@ install_spaceship_theme() {
81 82 ok "Spaceship theme installed"
82 83 }
83 84
85 + install_starship_config() {
86 + local target="$HOME/.config/starship.toml"
87 + local tmp="${target}.tmp.$$"
88 +
89 + log "Installing Starship config..."
90 + mkdir -p "$(dirname "$target")"
91 +
92 + if curl -fsSL "$GIST_RAW_BASE/starship.toml" -o "$tmp"; then
93 + mv "$tmp" "$target"
94 + ok "Starship config installed at $target"
95 + else
96 + rm -f "$tmp"
97 + warn "Failed to download Starship config"
98 + fi
99 + }
100 +
84 101 install_starship_theme() {
85 102 if command -v starship >/dev/null 2>&1; then
86 103 ok "Starship already installed"
87 - return
88 - fi
89 -
90 - if command -v brew >/dev/null 2>&1; then
104 + elif command -v brew >/dev/null 2>&1; then
91 105 log "Installing Starship with Homebrew..."
92 106 brew install starship
107 + ok "Starship installed"
93 108 else
94 109 log "Installing Starship..."
95 110 mkdir -p "$HOME/.local/bin"
96 111 curl -fsSL https://starship.rs/install.sh | sh -s -- -y -b "$HOME/.local/bin"
112 + ok "Starship installed"
97 113 fi
98 114
99 - ok "Starship installed"
115 + install_starship_config
100 116 }
101 117
102 118 install_theme() {
@@ -133,10 +149,13 @@ download_configs() {
133 149 for f in "${CONFIG_FILES[@]}"; do
134 150 # Strip the leading dot for the download URL
135 151 local remote_file="${f#.}"
152 + [[ "$f" == ".config/starship.toml" ]] && remote_file="starship.toml"
136 153 local url="$GIST_RAW_BASE/$remote_file"
137 154 local target="$HOME/$f"
138 155 local tmp="${target}.tmp.$$"
139 156
157 + mkdir -p "$(dirname "$target")"
158 +
140 159 if [[ -f "$target" ]]; then
141 160 cp "$target" "$backup/"
142 161 fi

zsh_ubuntu.sh

@@ -30,6 +30,7 @@ CONFIG_FILES=(
30 30 ".sourcerc"
31 31 ".vimrc"
32 32 ".zshrc"
33 + ".config/starship.toml"
33 34 )
34 35
35 36 # =============================
@@ -128,22 +129,37 @@ install_spaceship_theme() {
128 129 ok "Spaceship theme installed"
129 130 }
130 131
132 + install_starship_config() {
133 + local target="$HOME/.config/starship.toml"
134 + local tmp="${target}.tmp.$$"
135 +
136 + log "Installing Starship config..."
137 + mkdir -p "$(dirname "$target")"
138 +
139 + if curl -fsSL "$GIST_RAW_BASE/starship.toml" -o "$tmp"; then
140 + mv "$tmp" "$target"
141 + ok "Starship config installed at $target"
142 + else
143 + rm -f "$tmp"
144 + warn "Failed to download Starship config"
145 + fi
146 + }
147 +
131 148 install_starship_theme() {
132 149 if command -v starship >/dev/null 2>&1; then
133 150 ok "Starship already installed"
134 - return
135 - fi
136 -
137 - if command -v brew >/dev/null 2>&1; then
151 + elif command -v brew >/dev/null 2>&1; then
138 152 log "Installing Starship with Homebrew..."
139 153 brew install starship
154 + ok "Starship installed"
140 155 else
141 156 log "Installing Starship..."
142 157 mkdir -p "$HOME/.local/bin"
143 158 curl -fsSL https://starship.rs/install.sh | sh -s -- -y -b "$HOME/.local/bin"
159 + ok "Starship installed"
144 160 fi
145 161
146 - ok "Starship installed"
162 + install_starship_config
147 163 }
148 164
149 165 install_theme() {
@@ -180,10 +196,13 @@ download_configs() {
180 196 for f in "${CONFIG_FILES[@]}"; do
181 197 # Strip the leading dot for the download URL
182 198 local remote_file="${f#.}"
199 + [[ "$f" == ".config/starship.toml" ]] && remote_file="starship.toml"
183 200 local url="$GIST_RAW_BASE/$remote_file"
184 201 local target="$HOME/$f"
185 202 local tmp="${target}.tmp.$$"
186 203
204 + mkdir -p "$(dirname "$target")"
205 +
187 206 if [[ -f "$target" ]]; then
188 207 cp "$target" "$backup/"
189 208 fi

zsh_wsl.sh

@@ -30,6 +30,7 @@ CONFIG_FILES=(
30 30 ".sourcerc"
31 31 ".vimrc"
32 32 ".zshrc"
33 + ".config/starship.toml"
33 34 )
34 35
35 36 # =============================
@@ -141,22 +142,37 @@ install_spaceship_theme() {
141 142 ok "Spaceship theme installed"
142 143 }
143 144
145 + install_starship_config() {
146 + local target="$HOME/.config/starship.toml"
147 + local tmp="${target}.tmp.$$"
148 +
149 + log "Installing Starship config..."
150 + mkdir -p "$(dirname "$target")"
151 +
152 + if curl -fsSL "$GIST_RAW_BASE/starship.toml" -o "$tmp"; then
153 + mv "$tmp" "$target"
154 + ok "Starship config installed at $target"
155 + else
156 + rm -f "$tmp"
157 + warn "Failed to download Starship config"
158 + fi
159 + }
160 +
144 161 install_starship_theme() {
145 162 if command -v starship >/dev/null 2>&1; then
146 163 ok "Starship already installed"
147 - return
148 - fi
149 -
150 - if command -v brew >/dev/null 2>&1; then
164 + elif command -v brew >/dev/null 2>&1; then
151 165 log "Installing Starship with Homebrew..."
152 166 brew install starship
167 + ok "Starship installed"
153 168 else
154 169 log "Installing Starship..."
155 170 mkdir -p "$HOME/.local/bin"
156 171 curl -fsSL https://starship.rs/install.sh | sh -s -- -y -b "$HOME/.local/bin"
172 + ok "Starship installed"
157 173 fi
158 174
159 - ok "Starship installed"
175 + install_starship_config
160 176 }
161 177
162 178 install_theme() {
@@ -193,10 +209,13 @@ download_configs() {
193 209 for f in "${CONFIG_FILES[@]}"; do
194 210 # Strip the leading dot for the download URL
195 211 local remote_file="${f#.}"
212 + [[ "$f" == ".config/starship.toml" ]] && remote_file="starship.toml"
196 213 local url="$GIST_RAW_BASE/$remote_file"
197 214 local target="$HOME/$f"
198 215 local tmp="${target}.tmp.$$"
199 216
217 + mkdir -p "$(dirname "$target")"
218 +
200 219 if [[ -f "$target" ]]; then
201 220 cp "$target" "$backup/"
202 221 fi

zshrc

@@ -87,6 +87,10 @@ source_if_readable "$HOME/.pathrc"
87 87 source_if_readable "$HOME/.alias"
88 88
89 89 if [[ "$ZSH_THEME_CHOICE" == "starship" ]]; then
90 + if [[ -z "${STARSHIP_CONFIG:-}" && -f "$HOME/.config/starship.toml" ]]; then
91 + export STARSHIP_CONFIG="$HOME/.config/starship.toml"
92 + fi
93 +
90 94 if command -v starship >/dev/null 2>&1; then
91 95 eval "$(starship init zsh)"
92 96 else

weehong revisou este gist 3 weeks ago. Ir para a revisão

4 files changed, 199 insertions, 46 deletions

zsh_macos.sh

@@ -68,7 +68,7 @@ install_plugins() {
68 68 ok "Plugins installed"
69 69 }
70 70
71 - install_theme() {
71 + install_spaceship_theme() {
72 72 log "Installing Spaceship theme..."
73 73 local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes"
74 74 local dir="$themes/spaceship-prompt"
@@ -78,7 +78,51 @@ install_theme() {
78 78 git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1
79 79
80 80 ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme"
81 - ok "Theme installed"
81 + ok "Spaceship theme installed"
82 + }
83 +
84 + install_starship_theme() {
85 + if command -v starship >/dev/null 2>&1; then
86 + ok "Starship already installed"
87 + return
88 + fi
89 +
90 + if command -v brew >/dev/null 2>&1; then
91 + log "Installing Starship with Homebrew..."
92 + brew install starship
93 + else
94 + log "Installing Starship..."
95 + mkdir -p "$HOME/.local/bin"
96 + curl -fsSL https://starship.rs/install.sh | sh -s -- -y -b "$HOME/.local/bin"
97 + fi
98 +
99 + ok "Starship installed"
100 + }
101 +
102 + install_theme() {
103 + local choice="${1:-}"
104 + local selected_theme
105 +
106 + if [[ -z "$choice" ]]; then
107 + echo "Select prompt theme:"
108 + echo " 1) Spaceship"
109 + echo " 2) Starship"
110 + read -r -p "Select theme [1-2]: " choice
111 + fi
112 +
113 + case "$(printf '%s' "$choice" | tr '[:upper:]' '[:lower:]')" in
114 + 1|spaceship) selected_theme="spaceship" ;;
115 + 2|starship) selected_theme="starship" ;;
116 + *) warn "Invalid theme selection: $choice"; return 1 ;;
117 + esac
118 +
119 + case "$selected_theme" in
120 + spaceship) install_spaceship_theme ;;
121 + starship) install_starship_theme ;;
122 + esac
123 +
124 + printf "%s\n" "$selected_theme" > "$HOME/.zsh_theme"
125 + ok "Theme selected: $selected_theme"
82 126 }
83 127
84 128 download_configs() {
@@ -141,7 +185,7 @@ show_menu() {
141 185 echo " 0) Run ALL steps (1-7)"
142 186 echo " 1) Install Oh My Zsh"
143 187 echo " 2) Install plugins (autosuggestions, syntax highlighting)"
144 - echo " 3) Install Spaceship theme"
188 + echo " 3) Install/select prompt theme (Spaceship or Starship)"
145 189 echo " 4) Download custom configs (~/.alias, .func, .vimrc, etc.)"
146 190 echo " 5) Check ~/.zshrc load order"
147 191 echo " 6) Switch to Zsh (Temporary Sub-shell)"
@@ -211,4 +255,4 @@ main() {
211 255 ok "macOS configuration complete!"
212 256 }
213 257
214 - main "$@"
258 + main "$@"

zsh_ubuntu.sh

@@ -118,14 +118,58 @@ install_plugins() {
118 118 ok "Plugins installed"
119 119 }
120 120
121 - install_theme() {
121 + install_spaceship_theme() {
122 122 log "Installing Spaceship theme..."
123 123 local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes"
124 124 local dir="$themes/spaceship-prompt"
125 125 mkdir -p "$themes"
126 126 [[ -d "$dir" ]] || git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1
127 127 ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme"
128 - ok "Theme installed"
128 + ok "Spaceship theme installed"
129 + }
130 +
131 + install_starship_theme() {
132 + if command -v starship >/dev/null 2>&1; then
133 + ok "Starship already installed"
134 + return
135 + fi
136 +
137 + if command -v brew >/dev/null 2>&1; then
138 + log "Installing Starship with Homebrew..."
139 + brew install starship
140 + else
141 + log "Installing Starship..."
142 + mkdir -p "$HOME/.local/bin"
143 + curl -fsSL https://starship.rs/install.sh | sh -s -- -y -b "$HOME/.local/bin"
144 + fi
145 +
146 + ok "Starship installed"
147 + }
148 +
149 + install_theme() {
150 + local choice="${1:-}"
151 + local selected_theme
152 +
153 + if [[ -z "$choice" ]]; then
154 + echo "Select prompt theme:"
155 + echo " 1) Spaceship"
156 + echo " 2) Starship"
157 + read -r -p "Select theme [1-2]: " choice
158 + fi
159 +
160 + case "$(printf '%s' "$choice" | tr '[:upper:]' '[:lower:]')" in
161 + 1|spaceship) selected_theme="spaceship" ;;
162 + 2|starship) selected_theme="starship" ;;
163 + *) warn "Invalid theme selection: $choice"; return 1 ;;
164 + esac
165 +
166 + case "$selected_theme" in
167 + spaceship) install_spaceship_theme ;;
168 + starship) install_starship_theme ;;
169 + esac
170 +
171 + printf "%s\n" "$selected_theme" > "$HOME/.zsh_theme"
172 + ok "Theme selected: $selected_theme"
129 173 }
130 174
131 175 download_configs() {
@@ -193,7 +237,7 @@ show_menu() {
193 237 echo " 5) Configure shell (chsh - sets default shell)"
194 238 echo " 6) Install Oh My Zsh"
195 239 echo " 7) Install plugins (autosuggestions, syntax highlighting)"
196 - echo " 8) Install Spaceship theme"
240 + echo " 8) Install/select prompt theme (Spaceship or Starship)"
197 241 echo " 9) Download custom configs (~/.alias, .vimrc, etc.)"
198 242 echo "10) Check ~/.zshrc load order"
199 243 echo "11) Switch to Zsh (Temporary Sub-shell)"
@@ -264,4 +308,4 @@ main() {
264 308 ok "Zsh installation/configuration complete!"
265 309 }
266 310
267 - main "$@"
311 + main "$@"

zsh_wsl.sh

@@ -131,14 +131,58 @@ install_plugins() {
131 131 ok "Plugins installed"
132 132 }
133 133
134 - install_theme() {
134 + install_spaceship_theme() {
135 135 log "Installing Spaceship theme..."
136 136 local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes"
137 137 local dir="$themes/spaceship-prompt"
138 138 mkdir -p "$themes"
139 139 [[ -d "$dir" ]] || git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1
140 140 ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme"
141 - ok "Theme installed"
141 + ok "Spaceship theme installed"
142 + }
143 +
144 + install_starship_theme() {
145 + if command -v starship >/dev/null 2>&1; then
146 + ok "Starship already installed"
147 + return
148 + fi
149 +
150 + if command -v brew >/dev/null 2>&1; then
151 + log "Installing Starship with Homebrew..."
152 + brew install starship
153 + else
154 + log "Installing Starship..."
155 + mkdir -p "$HOME/.local/bin"
156 + curl -fsSL https://starship.rs/install.sh | sh -s -- -y -b "$HOME/.local/bin"
157 + fi
158 +
159 + ok "Starship installed"
160 + }
161 +
162 + install_theme() {
163 + local choice="${1:-}"
164 + local selected_theme
165 +
166 + if [[ -z "$choice" ]]; then
167 + echo "Select prompt theme:"
168 + echo " 1) Spaceship"
169 + echo " 2) Starship"
170 + read -r -p "Select theme [1-2]: " choice
171 + fi
172 +
173 + case "$(printf '%s' "$choice" | tr '[:upper:]' '[:lower:]')" in
174 + 1|spaceship) selected_theme="spaceship" ;;
175 + 2|starship) selected_theme="starship" ;;
176 + *) warn "Invalid theme selection: $choice"; return 1 ;;
177 + esac
178 +
179 + case "$selected_theme" in
180 + spaceship) install_spaceship_theme ;;
181 + starship) install_starship_theme ;;
182 + esac
183 +
184 + printf "%s\n" "$selected_theme" > "$HOME/.zsh_theme"
185 + ok "Theme selected: $selected_theme"
142 186 }
143 187
144 188 download_configs() {
@@ -206,7 +250,7 @@ show_menu() {
206 250 echo " 5) Configure shell (chsh - sets default shell)"
207 251 echo " 6) Install Oh My Zsh"
208 252 echo " 7) Install plugins (autosuggestions, syntax highlighting)"
209 - echo " 8) Install Spaceship theme"
253 + echo " 8) Install/select prompt theme (Spaceship or Starship)"
210 254 echo " 9) Download custom configs (~/.alias, .vimrc, etc.)"
211 255 echo "10) Check ~/.zshrc load order"
212 256 echo "11) Switch to Zsh (Temporary Sub-shell)"
@@ -277,4 +321,4 @@ main() {
277 321 ok "WSL Zsh installation/configuration complete!"
278 322 }
279 323
280 - main "$@"
324 + main "$@"

zshrc

@@ -10,43 +10,56 @@ source_if_readable() {
10 10 fi
11 11 }
12 12
13 - ZSH_THEME="spaceship"
13 + ZSH_THEME_CHOICE="${ZSH_THEME_CHOICE:-}"
14 + if [[ -z "$ZSH_THEME_CHOICE" && -f "$HOME/.zsh_theme" ]]; then
15 + ZSH_THEME_CHOICE="$(<"$HOME/.zsh_theme")"
16 + fi
17 + ZSH_THEME_CHOICE="${ZSH_THEME_CHOICE:-spaceship}"
14 18
15 - SPACESHIP_PROMPT_ORDER=(
16 - time # Time stamps section
17 - user # Username section
18 - dir # Current directory section
19 - git # Git section (git_branch + git_status)
20 - node # Node.js section
21 - dotnet # .NET section
22 - java # Java section
23 - kotlin # Kotlin section
24 - ruby # Ruby section
25 - xcode # Xcode section
26 - swift # Swift section
27 - golang # Go section
28 - docker # Docker section
29 - venv # virtualenv section
30 - line_sep # Line break
31 - char # Prompt character
32 - )
19 + case "$ZSH_THEME_CHOICE" in
20 + starship)
21 + ZSH_THEME=""
22 + ;;
23 + spaceship|*)
24 + ZSH_THEME="spaceship"
33 25
34 - SPACESHIP_USER_SHOW=always
35 - SPACESHIP_PROMPT_SEPARATE_LINE=true
36 - SPACESHIP_PROMPT_ADD_NEWLINE=true
37 - SPACESHIP_CHAR_SYMBOL="❯"
38 - SPACESHIP_CHAR_SUFFIX=" "
39 - SPACESHIP_DOCKER_CONTEXT_SHOW=false
26 + SPACESHIP_PROMPT_ORDER=(
27 + time # Time stamps section
28 + user # Username section
29 + dir # Current directory section
30 + git # Git section (git_branch + git_status)
31 + node # Node.js section
32 + dotnet # .NET section
33 + java # Java section
34 + kotlin # Kotlin section
35 + ruby # Ruby section
36 + xcode # Xcode section
37 + swift # Swift section
38 + golang # Go section
39 + docker # Docker section
40 + venv # virtualenv section
41 + line_sep # Line break
42 + char # Prompt character
43 + )
40 44
41 - if [[ $(uname) == "Darwin" ]]; then
42 - #  is the Apple logo in Nerd Fonts
43 - SPACESHIP_USER_SUFFIX="%F{cyan} [  ]%f "
44 - elif [[ $(uname) == "Linux" ]]; then
45 - #  is the Ubuntu logo in Nerd Fonts
46 - SPACESHIP_USER_SUFFIX="%F{yellow} [  ]%f "
47 - else
48 - SPACESHIP_USER_SUFFIX=" "
49 - fi
45 + SPACESHIP_USER_SHOW=always
46 + SPACESHIP_PROMPT_SEPARATE_LINE=true
47 + SPACESHIP_PROMPT_ADD_NEWLINE=true
48 + SPACESHIP_CHAR_SYMBOL="❯"
49 + SPACESHIP_CHAR_SUFFIX=" "
50 + SPACESHIP_DOCKER_CONTEXT_SHOW=false
51 +
52 + if [[ $(uname) == "Darwin" ]]; then
53 + #  is the Apple logo in Nerd Fonts
54 + SPACESHIP_USER_SUFFIX="%F{cyan} [  ]%f "
55 + elif [[ $(uname) == "Linux" ]]; then
56 + #  is the Ubuntu logo in Nerd Fonts
57 + SPACESHIP_USER_SUFFIX="%F{yellow} [  ]%f "
58 + else
59 + SPACESHIP_USER_SUFFIX=" "
60 + fi
61 + ;;
62 + esac
50 63
51 64 plugins=(git zsh-syntax-highlighting zsh-autosuggestions)
52 65
@@ -72,3 +85,11 @@ source_if_readable "$HOME/.pathrc"
72 85 # 5. ALIASES (Loaded dead last so YOUR code always wins over Oh My Zsh)
73 86 # =============================================================================
74 87 source_if_readable "$HOME/.alias"
88 +
89 + if [[ "$ZSH_THEME_CHOICE" == "starship" ]]; then
90 + if command -v starship >/dev/null 2>&1; then
91 + eval "$(starship init zsh)"
92 + else
93 + echo "Warning: Starship selected but starship is not installed."
94 + fi
95 + fi

weehong revisou este gist 1 month ago. Ir para a revisão

Sem alterações

Próximo Anterior