-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.zshrc
More file actions
246 lines (209 loc) · 7.09 KB
/
.zshrc
File metadata and controls
246 lines (209 loc) · 7.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
###############################################################################
# 🗂️ XDG CONFIG SETTINGS
###############################################################################
# Set XDG config directory only when XDG_CONFIG_HOME is not already defined.
# Many tools (e.g. git, neovim, ghostty, micro) use this as the base path for
# user-specific config files. Default to ~/.config to follow XDG conventions.
if [ -z "${XDG_CONFIG_HOME:-}" ]; then
export XDG_CONFIG_HOME="$HOME/.config"
fi
###############################################################################
# 🍺 HOMEBREW INITIALIZATION
###############################################################################
if command -v brew &>/dev/null; then
eval "$($(command -v brew) shellenv)"
fi
###############################################################################
# 🧰 MISE (POLYGLOT RUNTIME MANAGER)
###############################################################################
if command -v mise &>/dev/null; then
eval "$(mise activate zsh)"
fi
###############################################################################
# 🌟 STARSHIP PROMPT
###############################################################################
if command -v starship &>/dev/null; then
eval "$(starship init zsh)"
fi
###############################################################################
# ⚙️ ZSH OPTIONS
###############################################################################
# Configure Zsh behavior for directory stack, history, and editing experience.
# zsh: pushd history duplication restriction
setopt pushd_ignore_dups
# zsh: command history duplication restriction
setopt hist_ignore_all_dups
# zsh: don't add command history if started with 'space'
setopt hist_ignore_space
# zsh: share history between terminals
setopt share_history
# zsh: perform history expansion and reload the line into the editing buffer
setopt hist_verify
###############################################################################
# ✏️ EDITOR SETTINGS
###############################################################################
# Define default text editors for command-line and GUI programs.
export EDITOR='cot -n -w'
export VISUAL='cot -n -w'
###############################################################################
# 📦 GHQ SETTINGS
###############################################################################
# Define ghq root path. Use external workspace if available.
if command -v ghq >/dev/null 2>&1; then
if [ -d /Volumes/workspace ]; then
export GHQ_ROOT='/Volumes/workspace/src'
else
export GHQ_ROOT="$HOME/src"
fi
fi
###############################################################################
# ⚙️ ALIASES & FUNCTIONS
###############################################################################
# Utility aliases and helper functions for daily use.
# 🔹 scot
# Wrapper for CotEditor's bundled CLI.
# Opens files in a new CotEditor window and waits until that window closes.
# Behaves like a lightweight "cot -w -n" helper without creating a symlink.
# Example:
# % scot file.txt
# (opens file.txt in a new CotEditor window and waits)
function scot() {
local app="/Applications/CotEditor.app"
local cli="$app/Contents/SharedSupport/bin/cot"
if [[ -x "$cli" ]]; then
"$cli" -w -n "$@" 2>/dev/null
return $?
else
echo "❌ CotEditor の cot コマンドが見つかりませんでした。" >&2
echo " /Applications/CotEditor.app にあるか確認してください。" >&2
return 1
fi
}
# 🔹 smbname2ip
# Resolve an SMB machine name to its IP address.
# Example:
# % smbname2ip myserver
# 192.168.1.42
function smbname2ip() {
if [ $# -ne 1 ]; then
echo "usage:\n smbname2ip machine_name"
return 1
fi
local MACHINE_NAME=$1
smbutil lookup "${MACHINE_NAME}" | tail -1 | tr -d ' ' | rev | cut -d":" -f1 | rev
}
# 🔹 brewdump
# Print the current Homebrew bundle (list of installed packages, casks, and taps)
# directly to standard output instead of saving it to a file.
#
# Example:
# % brewdump
# tap "homebrew/core"
# brew "git"
# cask "visual-studio-code"
#
# Equivalent to: brew bundle dump --file=/dev/stdout
function brewdump() {
brew bundle dump --file=/dev/stdout
}
# 🔹 peek
# Show stdin on the current terminal while passing it through unchanged.
# Useful for checking piped output without interrupting the pipeline.
# Example:
# % mycli | peek | pbcopy
function peek() {
tee /dev/tty
}
# Compare two list files and show additions (+) and deletions (-) with colors
# Usage:
# % listdiff old.txt new.txt [--added] [--removed] [--print]
# Examples:
# % listdiff Brewfile <(brewdump)
# % listdiff Brewfile <(brewdump) --added
# % listdiff Brewfile <(brewdump) --removed --print
function listdiff() {
if [[ $# -lt 2 ]]; then
echo "usage: listdiff old.txt new.txt [--added] [--removed] [--print]"
return 1
fi
local old="$1"
local new="$2"
shift 2
local show_added=true
local show_removed=true
local print_sorted=false
# Parse flags
for arg in "$@"; do
case "$arg" in
--added)
show_removed=false ;;
--removed)
show_added=false ;;
--print)
print_sorted=true ;;
*)
echo "error: unknown option '$arg'" >&2
return 1 ;;
esac
done
# ANSI colors (Git standard style)
local red="\033[31m"
local green="\033[32m"
local reset="\033[0m"
# Normalize & sort each input (remove empty lines and comments)
local old_sorted new_sorted
old_sorted=$(awk '!/^($|#)/ {print}' "$old" | sort -u)
new_sorted=$(awk '!/^($|#)/ {print}' "$new" | sort -u)
# Print sorted output
if $print_sorted; then
echo "----- OLD (sorted) -----"
printf '%s\n' "$old_sorted"
echo "----- NEW (sorted) -----"
printf '%s\n' "$new_sorted"
echo "------------------------"
fi
# Removed (-): lines in old but not in new
if $show_removed; then
while IFS= read -r line; do
if ! grep -Fxq "$line" <<<"$new_sorted"; then
printf "${red}-%s${reset}\n" "$line"
fi
done <<<"$old_sorted"
fi
# Added (+): lines in new but not in old
if $show_added; then
while IFS= read -r line; do
if ! grep -Fxq "$line" <<<"$old_sorted"; then
printf "${green}+%s${reset}\n" "$line"
fi
done <<<"$new_sorted"
fi
}
# Reload Zsh configuration (~/.zshrc)
# Usage:
# % reload # Reload the current Zsh configuration
# % rr # Short alias for reload (faster to type and avoids conflicts)
#
# Example:
# % reload
# Reloading ~/.zshrc...
# ✅ Reloaded
#
function reload() {
echo "Reloading ~/.zshrc..."
source ~/.zshrc
hash -r
echo "✅ Reloaded"
}
# Short alias for reload
alias rr='reload'
# Antigravity (if installed)
[ -d "$HOME/.antigravity/antigravity/bin" ] && export PATH="$HOME/.antigravity/antigravity/bin:$PATH"
# Cursor (if installed)
[ -d "$HOME/.local/bin" ] && export PATH="$HOME/.local/bin:$PATH"
# bun (if installed)
if [ -d "$HOME/.bun" ]; then
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
source "$HOME/.bun/_bun"
fi