-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zshrc
453 lines (368 loc) · 11.1 KB
/
.zshrc
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# Authors: Sorin Ionescu <[email protected]>
#######################
#Vim Bind keys
#######################
bindkey -v
export KEYTIMEOUT=1
### Completion
# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"
autoload -Uz compinit && compinit
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
# Up and Down arrow keys now shows related history based on what is entered on the current prompt
if [[ -s "/opt/homebrew/share/zsh-history-substring-search/zsh-history-substring-search.zsh" ]]; then
source /opt/homebrew/share/zsh-history-substring-search/zsh-history-substring-search.zsh
fi
if [[ -s "/usr/local/share/zsh-history-substring-search/zsh-history-substring-search.zsh" ]]; then
source /usr/local/share/zsh-history-substring-search/zsh-history-substring-search.zsh
fi
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
# History sharing between sessions.
setopt share_history
# Cd directory without typing CD
setopt autocd
# Uncomment the following line to disable auto-setting terminal title.
DISABLE_AUTO_TITLE=true
# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# HIST_STAMPS="mm/dd/yyyy"
# Keep Secrets
if [[ -s "$HOME/.private" ]]; then
source $HOME/.private
fi
#######
# TMUX
#######
if command -v tmux &> /dev/null && [ -z "$TMUX" ]; then
tmux new-session
fi
#################################
# Aliases
#################################
#################################
# SKHD
#################################
function skhd_ddterm () {
WINDOW_TITLE="ddterm"
WINDOW_ID=$(yabai -m query --windows | jq -e ".[] | select(.title==\"$WINDOW_TITLE\") | .id")
case $WINDOW_ID in
''|*[!0-9]*) unset $WINDO_ID ;;
esac
if ! [[ $WINDOW_ID ]]; then
open -na /Applications/Kitty.app --args --title "$WINDOW_TITLE"
else
WINDOW_QUERY=$(yabai -m query --windows --window "$WINDOW_ID")
IS_HIDDEN=$(echo "$WINDOW_QUERY" | jq '."is-hidden"')
HAS_FOCUS=$(echo "$WINDOW_QUERY" | jq '."has-focus"')
if [[ "${HAS_FOCUS}" != "true" ]]; then
yabai -m window "$WINDOW_ID" --space mouse --move abs:0:0 --grid "10:1:0:0:1:4" --layer above --focus
fi
if [[ "${IS_HIDDEN}" != "true" ]]; then
skhd -k "cmd - h"
fi
fi
}
#################################
# Automattic
#################################
function wppull () {
rsync -az --delete --delete-after --exclude '.svn' --exclude '.git' --exclude '.settings' --exclude 'wp-content/themes' wpcom:/home/wpcom/public_html/ ~/Projects/wpcom/ --info=progress2
}
function wppush () {
rsync -az --delete --delete-after --exclude '.svn' --exclude '.git' --exclude '.settings' --exclude 'wp-content/themes' ~/Projects/wpcom/ wpcom:/home/wpcom/public_html/ --info=progress2
}
function a8cproxysettingon(){
sudo networksetup -setautoproxystate "Wi-Fi" on
sudo networksetup -setautoproxyurl "Wi-Fi" "https://pac.a8c.com"
}
function a8cproxysettingoff(){
sudo networksetup -setautoproxystate "Wi-Fi" off
}
function a8cproxy(){
if [[ 'on' == $1 ]]; then
echo 'Turning Setting On';
a8cproxysettingon
fi
if [[ 'off' == $1 ]]; then
echo 'Turning Setting Off';
a8cproxysettingoff
fi
}
function sandbox(){
if [[ 'on' == $1 ]]; then
echo 'Setting config and starting ssh session..';
sudo sed -i '' 's/^#192.0.92.115/192.0.92.115/g' /etc/hosts
ssh wpcomsandbox
fi
if [[ 'off' == $1 ]]; then
echo 'Disabling sandbox hosts config...';
sudo sed -i '' 's/^192.0.92.115/#192.0.92.115/g' /etc/hosts
fi
}
function rotationCalendarWeeks(){
for ((j = 1 ; j < 52 ; j++)); do
mondayMonth=$(date -v-Sun -v+${j}w -v+Mon "+%b")
mon=$(date -v-Sun -v+${j}w -v+Mon "+%d")
fridayMonth=$(date -v-Sun -v+${j}w -v+Fri "+%b")
fri=$(date -v-Sun -v+${j}w -v+Fri "+%d")
echo "$mondayMonth $mon - $fridayMonth $fri"
done
}
function wpurl(){
if [ -z "$1" ]; then
npm run wp option update home http://localhost:8082/
npm run wp option update siteurl http://localhost:8082/
return
fi
}
function plannerweekslonglist(){
months=''
dayranges=''
startweek=20
endweek=52
for ((j = startweek; j < endweek ; j++)); do
# Get the current weeks start and end date.
mon=$(date -v-Sun -v+${j}w -v+Mon "+%d")
fri=$(date -v-Sun -v+${j}w -v+Fri "+%d")
dayranges+="$mon - $fri\t"
# Get the current month and append it.
curmonth=$(date -v-Sun -v+${j}w -v+Mon "+%b")
months+="$curmonth\t";
done
echo -e $months
echo -e $dayranges
}
function weeklyupdateweeks(){
prevmonth='MON'
for ((j = 1 ; j < 52 ; j++)); do
curmonth=$(date -v-Sun -v+${j}w -v+Mon "+%B")
mon=$(date -v-Sun -v+${j}w -v+Mon "+%d")
fri=$(date -v-Sun -v+${j}w -v+Fri "+%d")
if [[ $curmonth != $prevmonth ]]; then
prevmonth=$curmonth;
echo ''
# echo $curmonth
echo ''
fi
echo "Weekly Update $curmonth $mon - $fri"
done
}
function plannerweeks(){
prevmonth='MON'
for ((j = 1 ; j < 52 ; j++)); do
curmonth=$(date -v-Sun -v+${j}w -v+Mon "+%b")
mon=$(date -v-Sun -v+${j}w -v+Mon "+%d")
fri=$(date -v-Sun -v+${j}w -v+Fri "+%d")
if [[ $curmonth != $prevmonth ]]; then
prevmonth=$curmonth;
echo ''
echo $curmonth
echo ''
fi
echo "$mon - $fri"
done
}
function calThisWeek(){
icalBuddy -nrd -nc -eep notes -ic [email protected] eventsToday+5 | grep • | grep -v Disengage | grep -v Family | grep -v Initialise | grep -v Lunch | grep -v 'weekly updates' | grep -v 'Week Planning' | grep -v 'Team and Group Updates' | grep -v Comms | tr • - | pbcopy
echo "Events coppied to clipboard"
}
function calendarlastweek(){
icalBuddy -nrd -nc -ic [email protected] eventsFrom:$(date -v-Sun -v-Mon "+%Y/%m/%d") to:$(date -v-Sun -v-Sat "+%Y/%m/%d") | grep • | grep -v Disengage | grep -v Family | grep -v Initialise | grep -v Lunch | grep -v Fika | grep -iv "\d slots" | grep -v Busy | tr • - | pbcopy
}
function wcpayurl(){
cd ~/projects/woocommerce-payments/
if [ -z "$1" ]; then
echo 'No url supplied';
else
wp option update home $1
wp option update siteurl $1
fi
}
#################################
# WP Docker
#################################
alias dc='docker-compose'
alias dcup='docker compose up -d'
alias dockerstop='docker stop $(docker ps -a -q)'
#################################
# Unix Text Handling
#################################
alias vim=nvim
alias vi=nvim
alias v=nvim
function vimrc(){
vi ~/.vim/vimrc
}
function nvrc(){
v ~/.config/nvim/
}
alias nvimrc=nvrc
alias wiki='vim -c "VimwikiIndex"'
alias a8cwiki=' vim ~/Documents/Automattic/index.md'
function download() {
if [ `which curl` ]; then
curl -s "$1" > "$2";
elif [ `which wget` ]; then
wget -nv -O "$2" "$1"
fi
}
function agreplace(){
ag $s1 --files-with-matches | xargs -I {} sed -i '.back' -e "s/$s1/$2/g" {};
}
###
# Git
##
alias gap="git add -p"
# Dotfiles gitifie
alias config='/usr/bin/git --git-dir=$HOME/.myconf/ --work-tree=$HOME'
alias cap='config add -p'
alias coz='config add ~/.zshrc'
alias cst='config status'
alias coc='config commit'
alias copus='config push'
alias copul='config pull'
#delete branche
function gbdel(){
git branch | grep $1 | xargs git branch -D
}
function gcol(){
#git checkout like %branch%
git branch | grep $1 | xargs git checkout
}
function gcob(){
git checkout -b $1
}
function gco(){
git fetch && git checkout $1
}
function gpoc(){
git rev-parse --abbrev-ref HEAD | xargs git push --set-upstream origin
}
function gpof(){
git rev-parse --abbrev-ref HEAD | xargs git push -fu origin
}
function gcd() {
REPONAME=$(node -e "console.log(process.argv[1].match(/.*?\/([a-zA-Z0-9\-]+).git/)[1]);" $1)
git clone $1 && cd "${REPONAME}"
}
### Home brew
export PATH="/usr/local/bin:$PATH"
######
# Custom Scripts
######
export PATH="$HOME/bin:$PATH"
#################################
# CLI
#################################
cpdir() {
echo "${PWD##*/}" | pbcopy
echo "${PWD##*/} copied"
}
cpwd() {
echo "${PWD}" | pbcopy
echo "path copied"
}
cdlike(){
ls -a | grep $1 | xargs cd
}
dater(){
TZ=GMT date -r $1
}
addspace(){
for i in $(seq $1)
do
echo
done
}
alias space='addspace'
alias lsg='ls | grep'
alias hosts='sudo vim /etc/hosts'
#turn on word wrap in less ( see -S, which removes wrap, is not in the list )
export LESS="-F -g -i -M -R -w -X -z-4"
## Legacy function to check if we're in a VIM shell
isvim() {
env | grep vim
}
#####
# POTFILES
#######
export WP_I18N_LIB="~/lib/wpi18n"
##########
# Node
#########
# this is the root folder where all globally installed node packages will go
export NPM_PACKAGES="/usr/local/npm_packages"
export NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
# add to PATH
export PATH="$NPM_PACKAGES/bin:$PATH"
#Node Version Manager
alias nvm='fnm'
eval "$(fnm env --use-on-cd)"
#Zoxide for better CD memory's
eval "$(zoxide init zsh)"
#Starship Prompt
eval "$(starship init zsh)"
#############
#navigation
############
function cdplugin(){
cd /Users/dwain/projects/$1/wordpress/wp-content/plugins/$2
}
function cdgosrc(){
cd /Users/dwain/projects/go/src
}
function cdwpcont(){
cd /Users/dwain/projects/$1/wordpress/wp-content
}
alias cdpayfast="cd /Users/dwain/projects/payfast/app/public/wp-content/plugins/woocommerce-gateway-payfast"
alias cdwcpayplugins="cd /Users/dwain/projects/woocommerce-payments/docker/wordpress/wp-content/plugins"
alias cdgo="cd /Users/dwain/projects/go"
alias cdstripe="cd /Users/dwain/projects/wcpay/app/public/wp-content/plugins/woocommerce-gateway-stripe"
function wplog(){
less +F /Users/dwain/projects/$1/wordpress/wp-content/debug.log
}
###########
# WooDeploy
###########
export GOPATH="/Users/dwain/projects"
export PATH=$PATH:$GOPATH
export PATH=$PATH:$GOPATH/bin
# export MANPATH="/usr/local/man:$MANPATH"
# You may need to manually set your language environment
# export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
if [[ -n $SSH_CONNECTION ]]; then
export EDITOR='vim'
else
export EDITOR='nvim'
fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
###########
# Ruby
###########
export GEM_HOME="$HOME/.gem"
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
export PATH="/usr/local/opt/ruby/bin:/usr/local/lib/ruby/gems/3.1.0/bin:$PATH"
export PATH="/usr/local/opt/ruby/bin:/usr/local/lib/ruby/gems/3.2.0/bin:$PATH"
# ssh
# export SSH_KEY_PATH="~/.ssh/rsa_id"
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
alias zshrc="vim ~/.zshrc"
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
export PATH="/usr/local/opt/[email protected]/bin:$PATH"
export PATH="/usr/local/opt/[email protected]/sbin:$PATH"
export PATH="/usr/local/sbin:$PATH"