Last active 2 weeks ago

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

weehong revised this gist 1 month ago. Go to revision

1 file changed, 1 deletion

sourcerc

@@ -22,7 +22,6 @@ fi
22 22 # CLAUDE CODE / AI GATEWAY
23 23 # ==========================================
24 24 export ANTHROPIC_BASE_URL="https://gateway.ai.cloudflare.com/v1/9a71825e3842e918e0dff9ad84f50484/claude-code-gateway/anthropic"
25 - export OPENAI_BASE_URL="https://gateway.ai.cloudflare.com/v1/9a71825e3842e918e0dff9ad84f50484/codex-gateway/openai"
26 25
27 26 # ==========================================
28 27 # OH MY ZSH

weehong revised this gist 1 month ago. Go to revision

1 file changed, 1 insertion, 1 deletion

README.md

@@ -17,5 +17,5 @@ bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996
17 17
18 18 ### Configuration
19 19 ```zsh
20 - bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_macos.sh)"
20 + bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/config.sh)"
21 21 ```

weehong revised this gist 1 month ago. Go to revision

1 file changed, 5 insertions

README.md

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

weehong revised this gist 1 month ago. Go to revision

1 file changed, 5 insertions, 2 deletions

func

@@ -65,6 +65,9 @@ open_file() {
65 65 }
66 66 alias open='open_file'
67 67
68 + # -----------------------------------------------------------------------------
69 + # Function: clear_history (Supports shell and Claude)
70 + # -----------------------------------------------------------------------------
68 71 # -----------------------------------------------------------------------------
69 72 # Function: clear_history (Supports shell and Claude)
70 73 # -----------------------------------------------------------------------------
@@ -72,7 +75,8 @@ clear_history() {
72 75 case "$1" in
73 76 claude)
74 77 if [ -d "$HOME/.claude/projects" ]; then
75 - rm -rf "$HOME/.claude/projects"/*
78 + # Use 'yes' to skip prompts and -f to ignore non-existent files
79 + yes | rm -rf "$HOME/.claude/projects"/*
76 80 echo "Claude project history/cache cleared."
77 81 fi
78 82 ;;
@@ -82,7 +86,6 @@ clear_history() {
82 86 : > "$HISTFILE"
83 87
84 88 # 2. Clear RAM by briefly setting history size to 0
85 - # This is the most reliable way to clear Zsh RAM without hanging
86 89 local old_histsize=$HISTSIZE
87 90 HISTSIZE=0
88 91 HISTSIZE=$old_histsize

weehong revised this gist 1 month ago. Go to revision

1 file changed, 33 insertions

config.sh(file created)

@@ -0,0 +1,33 @@
1 + #!/bin/bash
2 + set -euo pipefail
3 +
4 + # Configuration
5 + GIST_RAW_BASE="https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD"
6 + CONFIG_FILES=(
7 + ".alias"
8 + ".func"
9 + ".pathrc"
10 + ".sourcerc"
11 + ".vimrc"
12 + ".zshrc"
13 + )
14 +
15 + echo "Starting configuration download..."
16 +
17 + for f in "${CONFIG_FILES[@]}"; do
18 + # Remove the leading dot for the URL path
19 + remote_name="${f#.}"
20 + url="$GIST_RAW_BASE/$remote_name"
21 + target="$HOME/$f"
22 +
23 + echo "Downloading $f..."
24 +
25 + # Use -f to fail silently on server errors, -s for silent, -L to follow redirects
26 + if curl -fsSL "$url" -o "$target"; then
27 + echo "Successfully updated $target"
28 + else
29 + echo "Error: Failed to download $f from $url" >&2
30 + fi
31 + done
32 +
33 + echo "Done! All configuration files have been replaced."

weehong revised this gist 1 month ago. Go to revision

1 file changed, 9 insertions, 8 deletions

func

@@ -74,18 +74,19 @@ clear_history() {
74 74 if [ -d "$HOME/.claude/projects" ]; then
75 75 rm -rf "$HOME/.claude/projects"/*
76 76 echo "Claude project history/cache cleared."
77 - else
78 - echo "Note: ~/.claude/projects directory already empty or not found."
79 77 fi
80 78 ;;
81 79
82 80 *)
83 - # >| forces truncation even if 'noclobber' is set
84 - # We also clear current session buffer if in Zsh
85 - >| "$HISTFILE"
86 - if [[ -n "$ZSH_VERSION" ]]; then
87 - fc -p "$HISTFILE" && fc -R
88 - fi
81 + # 1. Truncate the file
82 + : > "$HISTFILE"
83 +
84 + # 2. Clear RAM by briefly setting history size to 0
85 + # This is the most reliable way to clear Zsh RAM without hanging
86 + local old_histsize=$HISTSIZE
87 + HISTSIZE=0
88 + HISTSIZE=$old_histsize
89 +
89 90 echo "Shell history cleared."
90 91 ;;
91 92 esac

weehong revised this gist 1 month ago. Go to revision

1 file changed, 8 insertions, 15 deletions

pathrc

@@ -2,28 +2,21 @@
2 2 # ENVIRONMENT & PATH CONFIGURATION
3 3 # =============================================================================
4 4
5 - # Source functions first so 'append_path' is available
5 + # 1. Source functions first
6 6 if [ -f "$HOME/.func" ]; then
7 7 source "$HOME/.func"
8 8 fi
9 9
10 - # -----------------------------------------------------------------------------
11 - # PATH INITIALIZATION
12 - # -----------------------------------------------------------------------------
10 + # 2. Define Root Variables
11 + export DOTNET_ROOT="$HOME/.dotnet"
13 12
14 - # System & Local Binaries
13 + # 3. PATH INITIALIZATION
14 + # -----------------------------------------------------------------------------
15 15 append_path "$HOME/.local/bin"
16 - append_path "$HOME/.dotnet"
17 - append_path "$HOME/.dotnet/tools"
18 -
19 - # Development Tools
16 + append_path "$DOTNET_ROOT"
17 + append_path "$DOTNET_ROOT/tools"
20 18 append_path "$HOME/Flutter/bin"
21 19 append_path "/Applications/Espanso.app/Contents/MacOS"
22 20
23 21 # Finalize PATH
24 - export PATH
25 -
26 - # -----------------------------------------------------------------------------
27 - # ADDITIONAL ENVIRONMENT VARIABLES
28 - # -----------------------------------------------------------------------------
29 - export DOTNET_ROOT="$HOME/.dotnet"
22 + export PATH

weehong revised this gist 1 month ago. Go to revision

2 files changed, 60 insertions, 284 deletions

func

@@ -3,7 +3,7 @@
3 3 # =============================================================================
4 4
5 5 # -----------------------------------------------------------------------------
6 - # Function: clip
6 + # Function: clip (Cross-platform clipboard)
7 7 # -----------------------------------------------------------------------------
8 8 clip() {
9 9 local cmd
@@ -46,18 +46,15 @@ open_file() {
46 46 local target="${1:-.}"
47 47
48 48 if [[ "$OSTYPE" == "darwin"* ]]; then
49 - # Use native macOS open
50 49 command open "$target"
51 50 elif grep -qi "microsoft" /proc/version 2>/dev/null; then
52 - # Use WSL Explorer
53 51 if command -v wslpath >/dev/null 2>&1 && command -v explorer.exe >/dev/null 2>&1; then
54 52 explorer.exe "$(wslpath -w "$target")"
55 53 else
56 - printf "Error: 'wslpath' or 'explorer.exe' not found. Windows interop might be disabled.\n" >&2
54 + printf "Error: 'wslpath' or 'explorer.exe' not found.\n" >&2
57 55 return 1
58 56 fi
59 57 elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
60 - # Use Linux xdg-open
61 58 if command -v xdg-open >/dev/null 2>&1; then
62 59 xdg-open "$target"
63 60 else
@@ -69,39 +66,48 @@ open_file() {
69 66 alias open='open_file'
70 67
71 68 # -----------------------------------------------------------------------------
72 - # Function: clear_history
69 + # Function: clear_history (Supports shell and Claude)
73 70 # -----------------------------------------------------------------------------
74 71 clear_history() {
75 72 case "$1" in
76 73 claude)
77 - # Check if the directory exists before attempting to clear
78 74 if [ -d "$HOME/.claude/projects" ]; then
79 75 rm -rf "$HOME/.claude/projects"/*
80 76 echo "Claude project history/cache cleared."
81 77 else
82 - echo "Error: ~/.claude/projects directory not found."
78 + echo "Note: ~/.claude/projects directory already empty or not found."
83 79 fi
84 80 ;;
85 81
86 82 *)
87 - # Default behavior: Clear Zsh history
88 83 # >| forces truncation even if 'noclobber' is set
89 - >| "$HISTFILE" && fc -R
84 + # We also clear current session buffer if in Zsh
85 + >| "$HISTFILE"
86 + if [[ -n "$ZSH_VERSION" ]]; then
87 + fc -p "$HISTFILE" && fc -R
88 + fi
90 89 echo "Shell history cleared."
91 90 ;;
92 91 esac
93 92 }
94 93
95 94 # -----------------------------------------------------------------------------
96 - # Function: claude
95 + # Function: claude (Includes --yolo and clear shortcuts)
97 96 # -----------------------------------------------------------------------------
98 97 claude() {
99 - # Run the check in a subshell, unsetting the function first so it only finds the binary
98 + # Shortcut for clearing cache
99 + if [[ "$1" == "clear" ]]; then
100 + clear_history claude
101 + return 0
102 + fi
103 +
104 + # Check if binary exists
100 105 if ! whence -p claude >/dev/null 2>&1; then
101 106 printf "Error: 'claude' CLI is not installed or not in your PATH.\n" >&2
102 107 return 1
103 108 fi
104 109
110 + # Handle --yolo mode
105 111 if [[ "$1" == "--yolo" ]]; then
106 112 shift
107 113 command claude --dangerously-skip-permissions "$@"
@@ -112,11 +118,11 @@ claude() {
112 118 }
113 119
114 120 # -----------------------------------------------------------------------------
115 - # Function: create
121 + # Function: create (Efficiently create file + parent dirs)
116 122 # -----------------------------------------------------------------------------
117 123 create() {
118 124 if ! command -v install >/dev/null 2>&1; then
119 - printf "Error: 'install' coreutil is not available on this system.\n" >&2
125 + printf "Error: 'install' coreutil is not available.\n" >&2
120 126 return 1
121 127 fi
122 128
@@ -126,13 +132,12 @@ create() {
126 132 fi
127 133
128 134 for p in "$@"; do
129 - if [ "${p#\~}" != "$p" ]; then
130 - p="${HOME}${p#\~}"
131 - fi
135 + # Expand tilde manually if shell doesn't
136 + [[ "$p" == "~/"* ]] && p="${HOME}/${p#\~/}"
132 137
133 138 if [ -z "$p" ] || [ "$p" = "/" ]; then
134 139 printf "create: refusing to operate on '%s'\n" "$p" >&2
135 - return 1
140 + continue
136 141 fi
137 142
138 143 if [ -e "$p" ]; then
@@ -140,12 +145,10 @@ create() {
140 145 continue
141 146 fi
142 147
143 - if ! install -D /dev/null "$p"; then
144 - printf "create: failed to create '%s'\n" "$p" >&2
145 - return 1
148 + if install -D /dev/null "$p"; then
149 + echo "Created '$p'"
146 150 fi
147 151 done
148 - return 0
149 152 }
150 153
151 154 # -----------------------------------------------------------------------------
@@ -153,42 +156,26 @@ create() {
153 156 # -----------------------------------------------------------------------------
154 157 check_port() {
155 158 local PORT=$1
156 -
157 159 if [ -z "$PORT" ]; then
158 160 printf "Usage: check_port <port_number>\n" >&2
159 161 return 1
160 162 fi
161 163
162 164 if [[ "$OSTYPE" == "darwin"* ]]; then
163 - if lsof -i :"$PORT" >/dev/null 2>&1; then
164 - echo "Port $PORT is IN USE"
165 - lsof -i :"$PORT"
166 - else
167 - echo "Port $PORT is FREE"
168 - fi
165 + lsof -i :"$PORT" || echo "Port $PORT is FREE"
169 166 else
170 - if ! command -v ss >/dev/null 2>&1; then
171 - printf "Error: 'ss' command not found. This function requires Linux iproute2 utilities.\n" >&2
172 - return 1
173 - fi
174 -
175 - if sudo ss -tulnp | grep -q ":$PORT "; then
176 - echo "Port $PORT is IN USE"
177 - sudo ss -tulnp | grep ":$PORT "
178 - else
179 - echo "Port $PORT is FREE"
180 - fi
167 + sudo ss -tulnp | grep ":$PORT " || echo "Port $PORT is FREE"
181 168 fi
182 169 }
183 170
184 171 # -----------------------------------------------------------------------------
185 - # Function: append_path
172 + # Function: append_path (Adds to session PATH if exists)
186 173 # -----------------------------------------------------------------------------
187 174 append_path() {
188 175 local dir="$1"
189 176 if [ -d "$dir" ]; then
190 177 case ":$PATH:" in
191 - *":$dir:"*) ;; # Already in PATH
178 + *":$dir:"*) ;;
192 179 *) PATH="$PATH:$dir" ;;
193 180 esac
194 181 elif [ "${SUPPRESS_WARNINGS:-0}" -ne 1 ]; then
@@ -197,50 +184,40 @@ append_path() {
197 184 }
198 185
199 186 # -----------------------------------------------------------------------------
200 - # Function: add_path_to_config
187 + # Function: add_path_to_config (Fixed awk/sed injection)
201 188 # -----------------------------------------------------------------------------
202 189 add_path_to_config() {
203 190 local new_path="$1"
204 191 local config_file="$HOME/.bashrc"
205 -
206 - if [[ "$SHELL" == *"zsh"* ]]; then
207 - config_file="$HOME/.zshrc"
208 - fi
192 + [[ "$SHELL" == *"zsh"* ]] && config_file="$HOME/.zshrc"
209 193
210 194 if [ -z "$new_path" ]; then
211 - printf "Usage: addpath <directory>\n" >&2
195 + printf "Usage: add_path_to_config <directory>\n" >&2
212 196 return 1
213 197 fi
214 198
215 199 new_path="${new_path/#\~/$HOME}"
216 200
217 201 if [ ! -d "$new_path" ]; then
218 - printf "Warning: '%s' does not exist.\n" "$new_path" >&2
219 - printf "Do you still want to add it to your config? (y/N) "
220 - read -r -k 1 REPLY
221 - echo
222 - if [[ ! $REPLY =~ ^[Yy]$ ]]; then
223 - return 1
224 - fi
202 + printf "Warning: '%s' does not exist. Add anyway? (y/N) " "$new_path"
203 + read -r REPLY
204 + [[ ! $REPLY =~ ^[Yy]$ ]] && return 1
225 205 fi
226 206
227 - if grep -Fq "append_path \"$new_path\"" "$config_file" || grep -Fq "append_path '$new_path'" "$config_file"; then
228 - printf "Notice: '%s' is already in your %s.\n" "$new_path" "$config_file"
207 + # Check if already exists in file
208 + if grep -Fq "append_path \"$new_path\"" "$config_file"; then
209 + printf "Notice: Already in %s.\n" "$config_file"
229 210 return 0
230 211 fi
231 212
213 + # Robust Injection: Use sed to insert before export PATH or just append
232 214 if grep -q "^export PATH" "$config_file"; then
233 - awk -v new_cmd="append_path \"$new_path\"" '/^export PATH/{print new_cmd}1' "$config_file" > "${config_file}.tmp" && mv "${config_file}.tmp" "$config_file"
215 + sed -i.bak "/^export PATH/i append_path \"$new_path\"" "$config_file"
234 216 else
235 217 echo "append_path \"$new_path\"" >> "$config_file"
236 218 echo "export PATH" >> "$config_file"
237 219 fi
238 220
239 - printf "✅ Success: Added '%s' to %s\n" "$new_path" "$config_file"
240 -
241 - if type append_path >/dev/null 2>&1; then
242 - append_path "$new_path"
243 - export PATH
244 - printf "🚀 Path is now active in your current session!\n"
245 - fi
246 - }
221 + printf "✅ Success: Added to %s\n" "$config_file"
222 + append_path "$new_path" && export PATH
223 + }

pathrc

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

weehong revised this gist 1 month ago. Go to revision

1 file changed, 18 insertions, 3 deletions

func

@@ -72,9 +72,24 @@ alias open='open_file'
72 72 # Function: clear_history
73 73 # -----------------------------------------------------------------------------
74 74 clear_history() {
75 - # Clears the history file and reloads the current session's history for Zsh
76 - >| "$HISTFILE" && fc -R
77 - echo "History cleared."
75 + case "$1" in
76 + claude)
77 + # Check if the directory exists before attempting to clear
78 + if [ -d "$HOME/.claude/projects" ]; then
79 + rm -rf "$HOME/.claude/projects"/*
80 + echo "Claude project history/cache cleared."
81 + else
82 + echo "Error: ~/.claude/projects directory not found."
83 + fi
84 + ;;
85 +
86 + *)
87 + # Default behavior: Clear Zsh history
88 + # >| forces truncation even if 'noclobber' is set
89 + >| "$HISTFILE" && fc -R
90 + echo "Shell history cleared."
91 + ;;
92 + esac
78 93 }
79 94
80 95 # -----------------------------------------------------------------------------

weehong revised this gist 1 month ago. Go to revision

1 file changed, 39 insertions, 31 deletions

sourcerc

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