forked from briancain/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathzshrc
More file actions
278 lines (234 loc) · 8.2 KB
/
zshrc
File metadata and controls
278 lines (234 loc) · 8.2 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
export EDITOR='vim'
if [ -d "/usr/local/Homebrew" ]; then
export PATH="$HOME/bin:$HOME/.bin:/usr/local/Homebrew/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/local/git/bin:$PATH"
else
export PATH="$HOME/bin:$HOME/.bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/local/git/bin:$PATH"
fi
export PATH="$HOME/.rbenv/bin:$PATH"
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"
LSCOLORS="gxfxcxdxbxegedabagacad"
if hash brew 2>/dev/null; then
_z_sh="$(brew --prefix)/etc/profile.d/z.sh"
if [ -f "$_z_sh" ]; then
. "$_z_sh"
fi
unset _z_sh
elif [ -f ~/.z.sh ]; then
. ~/.z.sh
fi
# --- History ---
HISTFILE="$HOME/.zsh_history"
HISTSIZE=50000
SAVEHIST=10000
setopt extended_history
setopt hist_expire_dups_first
setopt hist_ignore_dups
setopt hist_ignore_space
setopt hist_verify
setopt share_history
# --- Completion ---
autoload -U compinit
compinit
zmodload -i zsh/complist
WORDCHARS=''
unsetopt menu_complete
unsetopt flowcontrol
setopt auto_menu
setopt complete_in_word
setopt always_to_end
setopt menucomplete
zstyle ':completion:*:*:*:*:*' menu select
# Case-insensitive completion
zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'r:|=*' 'l:|=* r:|=*'
zstyle ':completion:*' special-dirs true
zstyle ':completion:*' list-colors ''
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
zstyle ':completion:*:*:*:*:processes' command "ps -u $USERNAME -o pid,user,comm -w -w"
zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories
zstyle ':completion:*' use-cache yes
zstyle ':completion:*' cache-path ~/.zsh-cache
autoload -U +X bashcompinit && bashcompinit
# --- Key bindings ---
bindkey -e
autoload -U up-line-or-beginning-search down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
bindkey "^[[A" up-line-or-beginning-search
bindkey "^[[B" down-line-or-beginning-search
if [[ -n "${terminfo[kcuu1]}" ]]; then
bindkey "${terminfo[kcuu1]}" up-line-or-beginning-search
fi
if [[ -n "${terminfo[kcud1]}" ]]; then
bindkey "${terminfo[kcud1]}" down-line-or-beginning-search
fi
if [[ -n "${terminfo[khome]}" ]]; then
bindkey "${terminfo[khome]}" beginning-of-line
fi
if [[ -n "${terminfo[kend]}" ]]; then
bindkey "${terminfo[kend]}" end-of-line
fi
if [[ -n "${terminfo[kdch1]}" ]]; then
bindkey "${terminfo[kdch1]}" delete-char
fi
if [[ -n "${terminfo[kcbt]}" ]]; then
bindkey "${terminfo[kcbt]}" reverse-menu-complete
fi
bindkey '^?' backward-delete-char
bindkey '^[[1;5C' forward-word
bindkey '^[[1;5D' backward-word
bindkey '\ew' kill-region
bindkey '^r' history-incremental-search-backward
bindkey ' ' magic-space
autoload -U edit-command-line
zle -N edit-command-line
bindkey '\C-x\C-e' edit-command-line
setopt prompt_subst
# --- Terminal title ---
function title {
setopt localoptions nopromptsubst
: ${2=$1}
case "$TERM" in
cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty*|st*|foot*|contour*|wezterm*)
print -Pn "\e]2;${2:q}\a"
print -Pn "\e]1;${1:q}\a"
;;
screen*|tmux*)
print -Pn "\ek${1:q}\e\\"
;;
esac
}
# --- Prompt ---
autoload colors && colors
parse_git_branch() {
(git symbolic-ref -q HEAD || git name-rev --name-only --no-undefined --always HEAD) 2> /dev/null
}
git_custom_status() {
local git_where="$(parse_git_branch)"
[ -n "$git_where" ] && echo "[${git_where#(refs/heads/|tags/)}]"
}
ruby_version() {
if (( $+commands[rbenv] )); then
echo "$(rbenv version | awk '{print $1}')"
fi
if (( $+commands[rvm-prompt] )); then
echo "$(rvm-prompt | awk '{print $1}')"
fi
}
pomv() {
if [ -z $1 ]; then
repo=.
else
repo=$DEV_ROOT/$1
fi
xpath $repo/pom.xml "project/version/text()" 2>/dev/null
echo
}
export PROMPT='[%D{%H:%M:%S}]%{$fg[cyan]%}[%~% ]%{$reset_color%}%B$%b '
precmd() {
title "zsh" "%m" "%55<...<%~"
echo -e "\033];$(hostname -f)\007"
if [[ -f "pom.xml" ]]; then
export RPROMPT='%{$fg[cyan]%}$(git_custom_status)%{$fg[white]%}[$(pomv)]%{$reset_color%}'
elif ! [[ -z "$(ruby_version)" ]]; then
export RPROMPT='%{$fg[cyan]%}$(git_custom_status)%{$fg[white]%}[$(ruby_version)]%{$reset_color%}'
else
export RPROMPT='%{$fg[cyan]%}$(git_custom_status)%{$reset_color%}'
fi
}
# --- rbenv ---
if hash rbenv 2>/dev/null; then
eval "$(rbenv init -)"
fi
export PATH="/opt/puppetlabs/bolt/bin:$PATH"
# --- Git aliases ---
alias gco='git checkout'
alias gb='git branch'
alias gd='git diff'
alias gp='git push origin HEAD'
alias gc='git commit'
alias gca='git commit -a'
alias gs='git status -sb'
alias gl='git pull --prune'
alias glog="git log --graph --pretty=format:'%Cred%h%Creset %an: %s - %Creset %C(yellow)%d%Creset %Cgreen(%cr)%Creset' --abbrev-commit --date=relative"
alias grm="git status | grep deleted | awk '{print \$3}' | xargs git rm"
# --- Rake ---
alias rake='noglob rake'
alias 'bin/rake'='noglob bin/rake'
# --- General aliases ---
alias reload!='. ~/.zshrc'
alias be='bundle exec'
alias df='df -h'
alias diff='colordiff'
alias grep='grep --color=auto'
alias ping='ping -c 2'
alias fpull='!git fetch upstream && git merge @{u} --ff-only'
alias changelog='git log `git log -1 --format=%H -- CHANGELOG*`..; cat CHANGELOG*'
# --- OS-specific ---
if [[ $(uname) = "Darwin" ]]; then
alias v="VAGRANT_CWD=/s/v vagrant"
alias vd='v destroy -f'
alias vup='v up'
alias vs='v suspend'
alias vstat='v status'
alias updatedb='sudo /usr/libexec/locate.updatedb'
alias ll='ls -liAFG'
alias start_watchr='cd /s/pe-dev-scripts/workflow && watchr installer.watchr'
elif [[ $(uname) = "Linux" ]]; then
alias ll='ls -liAFG --color'
fi
# --- Functions ---
fixssh() {
eval $(tmux show-env |sed -n 's/^\(SSH_[^=]*\)=\(.*\)/export \1="\2"/p')
}
pomd() {
grep $1 -A1 pom.xml | tail -1 | sed 's/.*<version>//' | sed 's/<\/version>//'
}
# --- nvm (lazy-loaded) ---
export NVM_DIR="$HOME/.nvm"
nvm() { unset -f nvm; [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"; nvm "$@"; }
# Add JBang to environment
alias j!=jbang
export PATH="$HOME/.jbang/bin:$PATH"
# Google Cloud SDK
if [ -f "$HOME/Downloads/google-cloud-sdk/path.zsh.inc" ]; then . "$HOME/Downloads/google-cloud-sdk/path.zsh.inc"; fi
if [ -f "$HOME/Downloads/google-cloud-sdk/completion.zsh.inc" ]; then . "$HOME/Downloads/google-cloud-sdk/completion.zsh.inc"; fi
# --- sdkman (lazy-loaded) ---
export SDKMAN_DIR="$HOME/.sdkman"
sdk() { unset -f sdk; [[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh"; sdk "$@"; }
export BOLT_GEM=1
export NODE_EXTRA_CA_CERTS=~/s/hal/ca.pem
# PE repos directory (where you clone PE repos)
export PEDEV_REPOS_DIR="$HOME/s"
# Run Claude Code inside the PE dev container
pedev-claude() {
local plugin_dir workdir
plugin_dir=$(ls -d ~/.claude/plugins/cache/puppetlabs-claude-tools/pedev/*/ 2>/dev/null | tail -1)
if [ -z "$plugin_dir" ]; then
echo "Error: pedev plugin not installed." >&2
return 1
fi
## Mode 1: Auto-mount parent of current directory (default)
## Works from anywhere — mounts the parent of your CWD into /repos,
## then starts claude in the CWD's directory name inside the container.
## Caveat: changing PEDEV_REPOS_DIR requires rebuilding the container.
export PEDEV_REPOS_DIR="$(dirname "$PWD")"
workdir="/repos/$(basename "$PWD")"
## Mode 2: Fixed repos directory (uncomment below, comment out Mode 1)
## All your PE repos live under one directory. Claude always sees all of them.
## More stable — the container doesn't need rebuilding when you switch repos.
# export PEDEV_REPOS_DIR="$HOME/repos/pe"
# if [[ "$PWD" == "$PEDEV_REPOS_DIR"* ]]; then
# workdir="/repos${PWD#$PEDEV_REPOS_DIR}"
# else
# workdir="/repos"
# fi
# One-time: migrate ~/.claude.json into ~/.claude/ so CLAUDE_CONFIG_DIR finds it
# (single-file bind mounts go stale on macOS; directory mounts don't)
if [ -f ~/.claude.json ] && [ ! -f ~/.claude/.claude.json ]; then
cp ~/.claude.json ~/.claude/.claude.json
fi
devcontainer up --workspace-folder "$plugin_dir" > /dev/null 2>&1
devcontainer exec --workspace-folder "$plugin_dir" bash -c "cd '$workdir' 2>/dev/null; exec claude --dangerously-skip-permissions $*"
}
#alias claude='pedev-claude'
[ -f "$HOME/.local/bin/env" ] && . "$HOME/.local/bin/env"