-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzshrc
More file actions
285 lines (244 loc) · 9.12 KB
/
Copy pathzshrc
File metadata and controls
285 lines (244 loc) · 9.12 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
278
279
280
281
282
283
284
285
# ==============================================================================
# Custom Aliases and Functions
# ==============================================================================
# Sourced from ~/.zshrc after oh-my-zsh loads
# ------------------------------------------------------------------------------
# ENVIRONMENT
# ------------------------------------------------------------------------------
export PATH=/Users/samvit/builds/bin:$PATH
# ------------------------------------------------------------------------------
# MODERN CLI TOOLS
# ------------------------------------------------------------------------------
# fzf - fuzzy finder (Ctrl+R for history, Ctrl+T for files)
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
source <(fzf --zsh 2>/dev/null) || true
# zoxide - smart directory jumping (use 'z' to jump to frecent directories)
# keeps regular 'cd' with your ls-after-cd behavior, adds 'z' for smart jumps
eval "$(zoxide init zsh)"
# zsh-autosuggestions - fish-like suggestions as you type
source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh 2>/dev/null || true
# nvm (lazy-loaded for fast shell startup)
export NVM_DIR="$HOME/.nvm"
nvm() {
unset -f nvm node npm npx
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm"
nvm "$@"
}
node() { nvm use default &>/dev/null; command node "$@"; }
npm() { nvm use default &>/dev/null; command npm "$@"; }
npx() { nvm use default &>/dev/null; command npx "$@"; }
export CLICOLOR=1
export LSCOLORS=Gxfxcxdxbxegedabagacad
export HISTSIZE=20000
# ------------------------------------------------------------------------------
# ALIASES - LS & FILES (using eza + bat)
# ------------------------------------------------------------------------------
# eza - modern ls with git integration
alias ls='eza --color=always --group-directories-first'
alias ll='eza -alh --git --group-directories-first'
alias la='eza -a --group-directories-first'
alias l='eza -F --group-directories-first'
alias lt='eza --tree --level=2'
alias lr='eza --tree'
alias ducks='du -cks *|sort -rn|head -11'
# bat - modern cat with syntax highlighting
alias cat='bat --paging=never'
alias catp='bat' # with pager
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias rm='trash'
alias json="python -mjson.tool"
alias hs='history | grep --color=auto'
# ------------------------------------------------------------------------------
# ALIASES - NAVIGATION
# ------------------------------------------------------------------------------
alias '..'='cd ..'
alias '...'='cd ../..'
alias junk='cd ~/junk'
alias dev='cd ~/dev'
alias u='cd ~/dev/union/union-mobile'
alias u2='cd ~/junk/union2/outreach'
alias c='cd ~/dev/chatter'
alias .cc='cd ~/.claude'
alias dbox='cd ~/Dropbox'
alias todo='vim ~/Dropbox/notes/todo.txt'
alias jokes='vim ~/Dropbox/Notes/Jokes.txt'
alias notes='cd "/Users/samvit/Library/Mobile Documents/iCloud~md~obsidian/Documents/Notes/"'
# ------------------------------------------------------------------------------
# ALIASES - GIT
# ------------------------------------------------------------------------------
alias gs='git status'
alias gpm='git push origin master'
alias gl="git log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
alias glog='git log --pretty=format:"[%h] %ae, %ar: %s" --stat'
alias gtree='git log --graph --full-history --all --color --pretty=format:"%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s"'
alias glf='gl | head -n 15'
function gc () { git checkout $@; }
function gcm () { git commit -m "$@"; }
function gb () { git branch $@; }
function gbd () { git branch -D $@; }
function gd () { git difftool $@; }
function gpll () { git pull $@; }
function gpsh () { git push $@; }
function gup () { git up $@; }
function pull_request() {
to_branch=$1
if [ -z $to_branch ]; then
to_branch="master"
fi
upstream=$(git config --get remote.upstream.url)
origin=$(git config --get remote.origin.url)
if [ -z $upstream ]; then
upstream=$origin
fi
to_user=$(echo $upstream | sed -e 's/.*[\/:]\([^/]*\)\/[^/]*$/\1/')
from_user=$(echo $origin | sed -e 's/.*[\/:]\([^/]*\)\/[^/]*$/\1/')
repo=$(basename `git rev-parse --show-toplevel`)
from_branch=$(git rev-parse --abbrev-ref HEAD)
open "https://github.com/$to_user/$repo/pull/new/$to_user:$to_branch...$from_user:$from_branch"
}
# ------------------------------------------------------------------------------
# ALIASES - TOOLS
# ------------------------------------------------------------------------------
alias cl='claude --dangerously-skip-permissions'
alias ph='phantom'
alias surf="/Applications/Windsurf.app/Contents/MacOS/Electron"
alias eb="vim ~/.dotfiles/zshrc"
alias sb="source ~/.dotfiles/zshrc"
alias ev="vim ~/.vim/vimrc"
alias es="vim ~/.dotfiles/mac_setup_script.sh"
# ------------------------------------------------------------------------------
# ALIASES - ENCRYPTION
# ------------------------------------------------------------------------------
# age (modern)
alias encrypt="age -p -o"
alias decrypt="age -d -o"
# openssl (legacy)
alias old_encrypt="openssl des3 -salt"
alias old_decrypt="openssl des3 -d -salt"
# ------------------------------------------------------------------------------
# FUNCTIONS
# ------------------------------------------------------------------------------
# Run ls whenever I cd somewhere
function cd () {
builtin cd "$@" && ls;
}
# Repeating alerts every N minutes (default 5)
function alerts() {
local mins=${1:-5}
local secs=$((mins * 60))
echo "🔔 Alerts: meditate for 30 seconds every $mins minute(s). Press Ctrl+C to stop."
while true; do
echo "🧘🏾 Start micro-meditation..."
afplay /System/Library/Sounds/Ping.aiff
sleep 30
echo "🚀 Back to work! Don't be attached to state."
afplay /System/Library/Sounds/Submarine.aiff
sleep $((secs - 30))
done
}
function server () {
python -m SimpleHTTPServer $@
}
function dirlength() {
echo -n ${PWD/#$HOME} | wc -c
}
function extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
function tarball () {
tar -zcvf "$1.tar.gz" $1
}
function mov_to_mp4 () {
ffmpeg -i $1.mov -qscale 0 $1.mp4
}
function runforever () {
while true; do
$@
echo "Process Died... RESTARTING"
sleep 5
done
}
function cdf() {
target=`osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)'`
if [ "$target" != "" ]; then
cd "$target"; pwd
else
echo 'No Finder window found' >&2
fi
}
function portkill () {
pid=$(lsof -i:$1 -t);
if [ "$pid" != "" ]; then
kill -TERM $pid || kill -KILL $pid
fi
}
function pdf.like_scanned () {
OUT=$(basename "$1" .pdf)
convert -density 150 "$1" -rotate "$([ $((RANDOM % 2)) -eq 1 ] && echo -)0.$(($RANDOM % 4 + 5))" \
-attenuate 0.4 +noise Multiplicative -attenuate 0.03 +noise Multiplicative -sharpen 0x1.0 \
-colorspace Gray "$OUT"_scanned.pdf
}
function gstats {
if [ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]; then
echo "Number of commits per author:"
git --no-pager shortlog -sn --all
AUTHORS=$( git shortlog -sn --all | cut -f2 | cut -f1 -d' ')
LOGOPTS=""
if [ "$1" == '-w' ]; then
LOGOPTS="$LOGOPTS -w"
shift
fi
if [ "$1" == '-M' ]; then
LOGOPTS="$LOGOPTS -M"
shift
fi
if [ "$1" == '-C' ]; then
LOGOPTS="$LOGOPTS -C --find-copies-harder"
shift
fi
for a in $AUTHORS
do
echo '-------------------'
echo "Statistics for: $a"
echo -n "Number of files changed: "
git log $LOGOPTS --all --numstat --format="%n" --author=$a | cut -f3 | sort -iu | wc -l
echo -n "Number of lines added: "
git log $LOGOPTS --all --numstat --format="%n" --author=$a | cut -f1 | awk '{s+=$1} END {print s}'
echo -n "Number of lines deleted: "
git log $LOGOPTS --all --numstat --format="%n" --author=$a | cut -f2 | awk '{s+=$1} END {print s}'
echo -n "Number of merges: "
git log $LOGOPTS --all --merges --author=$a | grep -c '^commit'
done
else
echo "you're currently not in a git repository"
fi
}
function myip {
res=$(curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+')
echo "$res"
}
# ------------------------------------------------------------------------------
# PROMPT
# ------------------------------------------------------------------------------
# Custom prompt (translated from bash_ps)
source ~/.dotfiles/zsh_ps