Última atividade 1 day ago

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

Vernon Wee Hong KOH revisou este gist 3 months ago. Ir para a revisão

1 file changed, 14 insertions, 1 deletion

func

@@ -142,6 +142,19 @@ claude() {
142 142 # Function: plan-build (Claude Code multi-agent workflow orchestrator)
143 143 # -----------------------------------------------------------------------------
144 144 plan-build() {
145 + local claude_args=()
146 +
147 + if [[ "${1:-}" == "--yolo" ]]; then
148 + claude_args=(--yolo)
149 + shift
150 + fi
151 +
152 + if [ $# -gt 0 ]; then
153 + echo "Error: Unknown argument(s): $*"
154 + echo "Usage: plan-build [--yolo]"
155 + return 1
156 + fi
157 +
145 158 require_cli claude "Claude Code CLI" || return 1
146 159 require_cli codex "Codex CLI" || return 1
147 160 require_cli coderabbit "CodeRabbit CLI" || return 1
@@ -168,7 +181,7 @@ plan-build() {
168 181
169 182 echo "🚀 Launching Claude Code with your multi-agent workflow..."
170 183
171 - claude "Please read \`skills.md\` and strictly follow the 6-step multi-agent workflow to implement the following task:
184 + claude "${claude_args[@]}" "Please read \`skills.md\` and strictly follow the 6-step multi-agent workflow to implement the following task:
172 185
173 186 $payload"
174 187 }

Vernon Wee Hong KOH revisou este gist 3 months ago. Ir para a revisão

1 file changed, 25 insertions, 9 deletions

func

@@ -139,22 +139,38 @@ claude() {
139 139 }
140 140
141 141 # -----------------------------------------------------------------------------
142 - # Function: plan-build (Claude Code multi-agent workflow shortcut)
142 + # Function: plan-build (Claude Code multi-agent workflow orchestrator)
143 143 # -----------------------------------------------------------------------------
144 144 plan-build() {
145 - local task="$*"
145 + require_cli claude "Claude Code CLI" || return 1
146 + require_cli codex "Codex CLI" || return 1
147 + require_cli coderabbit "CodeRabbit CLI" || return 1
148 +
149 + echo "📥 Reading payload... Type 'EOF' on a new line and press Enter when finished."
146 150
147 - if [ -z "$task" ]; then
148 - echo "Error: Please provide a task description."
149 - echo "Usage: plan-build 'your task here'"
151 + local payload
152 + local line
153 + payload=""
154 +
155 + while IFS= read -r line; do
156 + [ "$line" = "EOF" ] && break
157 + if [ -z "$payload" ]; then
158 + payload="$line"
159 + else
160 + payload="${payload}"$'\n'"${line}"
161 + fi
162 + done
163 +
164 + if [ -z "$payload" ]; then
165 + echo "❌ Error: Payload was empty."
150 166 return 1
151 167 fi
152 168
153 - require_cli claude "Claude Code CLI" || return 1
154 - require_cli codex "Codex CLI" || return 1
155 - require_cli coderabbit "CodeRabbit CLI" || return 1
169 + echo "🚀 Launching Claude Code with your multi-agent workflow..."
170 +
171 + claude "Please read \`skills.md\` and strictly follow the 6-step multi-agent workflow to implement the following task:
156 172
157 - claude "Please read \`skills.md\` and strictly follow the 6-step multi-agent workflow to implement: $task"
173 + $payload"
158 174 }
159 175
160 176 # -----------------------------------------------------------------------------

Vernon Wee Hong KOH revisou este gist 3 months ago. Ir para a revisão

1 file changed, 43 insertions, 4 deletions

func

@@ -92,6 +92,29 @@ clear_history() {
92 92 esac
93 93 }
94 94
95 + # -----------------------------------------------------------------------------
96 + # Function: require_cli (Check external CLI availability)
97 + # -----------------------------------------------------------------------------
98 + require_cli() {
99 + local binary="$1"
100 + local label="$2"
101 + local resolved
102 +
103 + if command -v whence >/dev/null 2>&1; then
104 + if whence -p "$binary" >/dev/null 2>&1; then
105 + return 0
106 + fi
107 + else
108 + resolved="$(command -v "$binary" 2>/dev/null)" || resolved=""
109 + if [ -n "$resolved" ] && [ -x "$resolved" ]; then
110 + return 0
111 + fi
112 + fi
113 +
114 + printf "Error: %s ('%s') is not installed or not in your PATH.\n" "$label" "$binary" >&2
115 + return 1
116 + }
117 +
95 118 # -----------------------------------------------------------------------------
96 119 # Function: claude (Includes --yolo and clear shortcuts)
97 120 # -----------------------------------------------------------------------------
@@ -103,10 +126,7 @@ claude() {
103 126 fi
104 127
105 128 # Check if binary exists
106 - if ! whence -p claude >/dev/null 2>&1; then
107 - printf "Error: 'claude' CLI is not installed or not in your PATH.\n" >&2
108 - return 1
109 - fi
129 + require_cli claude "Claude Code CLI" || return 1
110 130
111 131 # Handle --yolo mode
112 132 if [[ "$1" == "--yolo" ]]; then
@@ -118,6 +138,25 @@ claude() {
118 138 command claude "$@"
119 139 }
120 140
141 + # -----------------------------------------------------------------------------
142 + # Function: plan-build (Claude Code multi-agent workflow shortcut)
143 + # -----------------------------------------------------------------------------
144 + plan-build() {
145 + local task="$*"
146 +
147 + if [ -z "$task" ]; then
148 + echo "Error: Please provide a task description."
149 + echo "Usage: plan-build 'your task here'"
150 + return 1
151 + fi
152 +
153 + require_cli claude "Claude Code CLI" || return 1
154 + require_cli codex "Codex CLI" || return 1
155 + require_cli coderabbit "CodeRabbit CLI" || return 1
156 +
157 + claude "Please read \`skills.md\` and strictly follow the 6-step multi-agent workflow to implement: $task"
158 + }
159 +
121 160 # -----------------------------------------------------------------------------
122 161 # Function: aicommit (Automated Conventional Commit Engine Wrapper)
123 162 # -----------------------------------------------------------------------------

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

1 file changed, 6 insertions, 6 deletions

func

@@ -123,7 +123,9 @@ claude() {
123 123 # -----------------------------------------------------------------------------
124 124 aicommit() {
125 125 local diff engine prompt
126 - diff=$(git diff --cached)
126 +
127 + # 1. Get diff safely: exclude lock files/minified files and cap at ~100k characters to prevent CLI crashes
128 + diff=$(git diff --cached -- . ":(exclude)*.lock" ":(exclude)*-lock.json" ":(exclude)*.min.js" | head -c 100000)
127 129
128 130 if [ -z "$diff" ]; then
129 131 printf "❌ Error: Nothing staged to commit.\n" >&2
@@ -155,10 +157,8 @@ $diff" -s --no-ask-user --allow-tool='shell(git:*)'
155 157
156 158 opencode)
157 159 echo "🤖 OpenCode is analyzing staged changes..."
158 - opencode run "$prompt
159 -
160 - Here is the git diff:
161 - $diff"
160 + # 2. Fixed: Piping standard input to opencode bypasses OS argument length limits
161 + cat "$HOME/.config/ai-commit-prompt.txt" <(echo -e "\n\nHere is the git diff:\n$diff") | opencode run
162 162 ;;
163 163
164 164 *)
@@ -272,4 +272,4 @@ add_path_to_config() {
272 272
273 273 printf "✅ Success: Added to %s\n" "$config_file"
274 274 append_path "$new_path" && export PATH
275 - }
275 + }

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

1 file changed, 51 insertions, 3 deletions

func

@@ -65,9 +65,6 @@ open_file() {
65 65 }
66 66 alias open='open_file'
67 67
68 - # -----------------------------------------------------------------------------
69 - # Function: clear_history (Supports shell and Claude)
70 - # -----------------------------------------------------------------------------
71 68 # -----------------------------------------------------------------------------
72 69 # Function: clear_history (Supports shell and Claude)
73 70 # -----------------------------------------------------------------------------
@@ -121,6 +118,57 @@ claude() {
121 118 command claude "$@"
122 119 }
123 120
121 + # -----------------------------------------------------------------------------
122 + # Function: aicommit (Automated Conventional Commit Engine Wrapper)
123 + # -----------------------------------------------------------------------------
124 + aicommit() {
125 + local diff engine prompt
126 + diff=$(git diff --cached)
127 +
128 + if [ -z "$diff" ]; then
129 + printf "❌ Error: Nothing staged to commit.\n" >&2
130 + return 1
131 + fi
132 +
133 + if [ ! -f "$HOME/.config/ai-commit-prompt.txt" ]; then
134 + printf "❌ Error: Configuration file not found at ~/.config/ai-commit-prompt.txt\n" >&2
135 + printf "Please create it and paste your system prompt inside.\n" >&2
136 + return 1
137 + fi
138 +
139 + engine=${1:-claude}
140 + prompt=$(cat "$HOME/.config/ai-commit-prompt.txt")
141 +
142 + case "$engine" in
143 + claude)
144 + echo "🤖 Claude is analyzing staged changes..."
145 + cat "$HOME/.config/ai-commit-prompt.txt" <(echo -e "\n\nHere is the git diff:\n$diff") | command claude -p "Read the provided instructions and diff, then generate and execute the commit."
146 + ;;
147 +
148 + copilot)
149 + echo "🤖 Copilot is analyzing staged changes..."
150 + copilot -p "$prompt
151 +
152 + Here is the git diff:
153 + $diff" -s --no-ask-user --allow-tool='shell(git:*)'
154 + ;;
155 +
156 + opencode)
157 + echo "🤖 OpenCode is analyzing staged changes..."
158 + opencode run "$prompt
159 +
160 + Here is the git diff:
161 + $diff"
162 + ;;
163 +
164 + *)
165 + printf "❌ Error: Invalid engine '%s'\n" "$engine" >&2
166 + printf "Usage: aicommit [claude | copilot | opencode]\n" >&2
167 + return 1
168 + ;;
169 + esac
170 + }
171 +
124 172 # -----------------------------------------------------------------------------
125 173 # Function: create (Efficiently create file + parent dirs)
126 174 # -----------------------------------------------------------------------------

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

1 file changed, 4 insertions, 4 deletions

README.md

@@ -4,20 +4,20 @@ The "Bash Script Installer" simplifies the setup of Zsh.
4 4 ## Zsh
5 5 ### Ubuntu
6 6 ```zsh
7 - bash -c "$(curl -fsSL https://opengist.resetrix.work/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_ubuntu.sh)"
7 + bash -c "$(curl -fsSL https://tinyurl.com/y6fhb594)"
8 8 ```
9 9 ### WSL
10 10 ```zsh
11 - bash -c "$(curl -fsSL https://opengist.resetrix.work/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_wsl.sh)"
11 + bash -c "$(curl -fsSL https://tinyurl.com/ycyct6wp)"
12 12 ```
13 13 ### MacOS
14 14 ```zsh
15 - bash -c "$(curl -fsSL https://opengist.resetrix.work/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_macos.sh)"
15 + bash -c "$(curl -fsSL https://tinyurl.com/yptybtpa)"
16 16 ```
17 17
18 18 ### Configuration
19 19 ```zsh
20 - bash -c "$(curl -fsSL https://opengist.resetrix.work/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/config.sh)"
20 + bash -c "$(curl -fsSL https://tinyurl.com/y8vf753j)"
21 21 ```
22 22
23 23 ### Shell framework and prompt

Vernon revisou este gist 3 months ago. Ir para a revisão

4 files changed, 6 insertions, 6 deletions

README.md

@@ -4,11 +4,11 @@ The "Bash Script Installer" simplifies the setup of Zsh.
4 4 ## Zsh
5 5 ### Ubuntu
6 6 ```zsh
7 - bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_ubuntu.sh)"
7 + bash -c "$(curl -fsSL https://opengist.resetrix.work/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_ubuntu.sh)"
8 8 ```
9 9 ### WSL
10 10 ```zsh
11 - bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_wsl.sh)"
11 + bash -c "$(curl -fsSL https://opengist.resetrix.work/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_wsl.sh)"
12 12 ```
13 13 ### MacOS
14 14 ```zsh
@@ -17,7 +17,7 @@ bash -c "$(curl -fsSL https://opengist.resetrix.work/weehong/f0d940c3c1214bf5b79
17 17
18 18 ### Configuration
19 19 ```zsh
20 - bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/config.sh)"
20 + bash -c "$(curl -fsSL https://opengist.resetrix.work/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/config.sh)"
21 21 ```
22 22
23 23 ### Shell framework and prompt

config.sh

@@ -2,7 +2,7 @@
2 2 set -euo pipefail
3 3
4 4 # Configuration
5 - GIST_RAW_BASE="https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD"
5 + GIST_RAW_BASE="https://opengist.resetrix.work/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD"
6 6 CONFIG_FILES=(
7 7 ".alias"
8 8 ".func"

zsh_ubuntu.sh

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

zsh_wsl.sh

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

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

2 files changed, 2 insertions, 2 deletions

README.md

@@ -12,7 +12,7 @@ bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996
12 12 ```
13 13 ### MacOS
14 14 ```zsh
15 - bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_macos.sh)"
15 + bash -c "$(curl -fsSL https://opengist.resetrix.work/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_macos.sh)"
16 16 ```
17 17
18 18 ### Configuration

zsh_macos.sh

@@ -18,7 +18,7 @@ err() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
18 18 # =============================
19 19 # CONFIG
20 20 # =============================
21 - GIST_RAW_BASE="https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD"
21 + GIST_RAW_BASE="https://opengist.resetrix.work/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD"
22 22
23 23 CONFIG_FILES=(
24 24 ".alias"

weehong revisou este gist 4 months 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 4 months 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"