-
Notifications
You must be signed in to change notification settings - Fork 1
/
.zshenv
236 lines (218 loc) · 6.42 KB
/
.zshenv
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
export EDITOR="nvim"
export PAGER="nvim"
export MANPAGER="nvim +Man!"
export LESS="-F -R -S -W"
export GREP_OPTIONS="-I --exclude=\*.svn\* --exclude=\*.min.\*js"
export RIPGREP_CONFIG_PATH=~/workspace/dotfiles/ripgrep.cfg
#########
# unixy #
#########
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias c="curl"
digbr() {
dig ${1?:specify a subdomain to look up}.bleacherreport.com
}
alias e="nvim"
alias gr="grep"
alias l="ls -AFlno" # OMZ? is overriding this...
alias la="ls -A"
alias ll="ls -AFl" # OMZ? is overriding this...
alias ln="ln -v"
lsd() {
if [[ -n "$1" ]]; then
ls -G -d $1/*(D/)
else
# h/t Stéphane https://unix.stackexchange.com/a/502028/48320
ls -G -d -- *(D/)
fi
}
alias tlf="tail -f"
alias top="top -o cpu -O vsize"
alias tophistory="history | awk '{a[\$2]++}END{for(i in a){print a[i] \" \" i}}' | sort -rn | head -n30" # https://coderwall.com/p/o5qijw
until_fail() {
tries=1
eval "$@"
while [ "$?" -eq "0" ]; do
((tries+=1))
sleep 1
eval "$@"
done
echo "tries: ${tries}"
}
until_success() {
tries=1
eval "$@"
while [ "$?" -ne "0" ]; do
sleep 1
((tries+=1))
eval "$@"
done
echo "tries: ${tries}"
}
alias uq="cat -n | sort -uk2 | sort -nk1 | cut -f2-" # h/t https://stackoverflow.com/a/20639730/303896
alias wh="which"
alias yr="ncal $(date -j +'%Y')"
#########
# mac-y #
#########
battery() { ioreg -n AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%.0f%%"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}' }
alias fixcamera="sudo killall AppleCameraAssistant && sudo killall VDCAssistant" # h/t @GregMefford
notify() { osascript -e "display notification \"$2\" with title \"$1\"" }
yt() { youtube-dl --format best $1 }
yt-mp3() { youtube-dl --extract-audio --audio-format mp3 $1 }
#######
# git #
#######
alias bad="git bisect bad"
alias good="git bisect good"
alias g="git"
alias ga="git add"
alias gA="git add --all"
alias gap="git add --patch"
alias gb="git branch --color"
alias gco="git checkout"
alias gcv="git commit --verbose"
alias gd="git diff --color-words='[^[:space:]]|([[:alnum:]]|UTF_8_GUARD)+'."
gdiff() {
$FIRST=$1
$SECOND=$2
$FILE=$3
diff <(git show :$FIRST:$FILE) <(git show :$SECOND:$FILE)
}
alias gdp="git co develop && git pull"
alias gds="gd --staged"
alias gf="git fetch"
alias gh="giturl | xargs open"
ghb() { open $(giturl)/compare/develop...$(git branch-name) }
alias giturl="git config --get remote.origin.url | sed -e 's/\/\///' -e 's/git.//' -e 's/:/\//' -e 's/\.git//' -e 's/^/http:\/\//'"
alias gl="git l"
alias glg="git lg"
alias glh="git l --since yesterday"
alias glu="git log --patch"
alias gmd="git co develop && git pull && git co - && git merge develop"
alias gp="git pull"
gri() { git rebase --interactive "HEAD~$1" --verbose }
alias gsl="git stash list"
gsp() {
git stash pop stash@{${1:-0}}
}
gss() {
git stash show --patch stash@{${1:-0}}
}
resolve() {
$EDITOR -O $(git conflicting)
}
alias s="git status --short"
##########
# docker #
##########
alias d="docker"
alias dc="docker-compose"
alias dm="docker-machine"
alias dmenv="eval \"\$(docker-machine env default)\""
docker-scrub() {
docker rm $(docker ps -q -f 'status=exited')
docker rmi $(docker images -f "dangling=true" -q)
docker volume rm $(docker volume ls -qf dangling=true)
docker image prune
docker container prune
docker volume prune
}
###########
# general #
###########
alias a="asdf"
alias b="brew"
alias bl="bundle"
alias bx="bundle exec"
decode_jwt() {
if [[ -n "$1" ]]; then
JWT=$1
else
read JWT
fi
JWT_SPLIT=(${(s:.:)JWT}) # split on periods
for JWT_PIECE in $JWT_SPLIT; do
echo
echo $JWT_PIECE | base64 -D
echo
done
}
dotenv() {
# Usage: `dotenv command [args...]`
# If there's an .env file in the current directory, it will run the
# given command (with optional args) after adding the name=value
# options specified in the .env file to the command's environment.
if [[ ! -r .env ]]; then
echo "ERROR: No .env file in current directory; exiting..."
return 1
fi
# TODO This breaks if there's a backslash in a value?
env $(grep -E "^(export )?\w+=" .env | xargs) $@
}
extract_urls() {
[[ -z "$1" ]] && echo "Usage: spider url [depth=5]" && return 1
lynx \
-dump \
-listonly \
$1 \
| awk '/^ *[0-9]/ {print $2}'
}
f="echo Start getting used to asdf... aliased to 'a' at least"
alias n="npm"
alias nd="node"
alias ndd="nodemon"
alias ni="npm install --loglevel warn"
alias niD="npm install --loglevel warn --save-dev"
alias niS="npm install --loglevel warn --save"
node-watcher() {
if [[ -z "$1" ]]; then
echo "need a command to run whenever a webfile changes..."
else
webfiles | PWD=$(pwd) entr -rs "echo \"\n\\033[36m➥ \${0##${PWD}/}\\033[00m\n\" && $1"
fi
}
alias nr="npm run --silent"
alias nt="npm test"
alias nx="npx"
alias o="ocaml"
alias py="python"
report() { $@ && say "done" || say "error" }
alias rk="raku"
alias rt="racket"
alias sactl="sudo apachectl"
alias start_postgres="pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start"
alias us="bundle exec unicorn -c tmp/unicorn.rb"
upyet() {
URL=$1
until [[ $(curl -Is $URL | grep "HTTP\S* 200 OK") ]]; do
echo -n .
sleep 5
done
echo $URL
date
}
alias waitfor="wait-on --interval 999 --timeout ${TIMEOUT:-99999}"
alias webfiles="rg --type web --files"
webm2mp3() {
ffmpeg -i "$1" -vn -f mp3 "${1%.webm}.mp3"
}
alias y="yarn" # runs `yarn install` with no args...
alias z="zola"
back_up_media_unison() {
START=$(date)
echo "Started: $START"
unison \
-fastcheck true \
-copythreshold 999 \
-ignore 'Name .*' \
/Volumes/MEDIA \
/Volumes/Media2
END=$(date)
echo
echo "Started: $START"
echo "Ended @: $END"
}
[[ -f ~/.br-env.zsh ]] && source ~/.br-env.zsh