-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaliases
284 lines (251 loc) · 8.03 KB
/
aliases
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
# Just little things
alias so=source
alias watch="fd . | entr"
function slurp() {
extension="${1:-py}"
fd -e "$extension" -x sh -c 'echo "# {}"; cat {}' | pbcopy
}
# Finder stuff
unsetopt flowcontrol
function insert-selecta-path-in-command-line() {
local selected_path
echo
selected_path=$(rg --files -g "" | fzy) || return
eval 'LBUFFER="$LBUFFER$selected_path"'
zle reset-prompt
}
zle -N insert-selecta-path-in-command-line
bindkey "^S" "insert-selecta-path-in-command-line"
alias b="git branch | cut -c 3- | fzy | xargs git checkout"
v () {
if [[ -z $1 ]]
then
file=$(rg --files -g "" | fzy)
escaped_file=$(printf '%q' "$file")
print -s "nvim $escaped_file"
nvim "$file"
else
print -s "nvim $*"
nvim "$@"
fi
}
fcd(){
cd "$(find . -type d | fzy)"
}
compdef v=nvim
# Python
export PIP_REQUIRE_VIRTUALENV=true
## Pytest-watch
function watch_tests() {
CATCH_WARNINGS="-p no:warnings"
REPO="$(basename "$(git rev-parse --show-toplevel)")"
if [[ $REPO =~ ^(siphon|surfvey)$ ]];
then
CATCH_WARNINGS=""
fi
PYTHON_ENV=test rm -f .testmond\* && ptw --runner "pytest --testmon -s $CATCH_WARNINGS tests"
}
alias install-watch='pip install pytest-watch pytest-testmon'
## Jupyter Notebook
alias jn="cd && jupyter notebook &> /dev/null &"
alias jnk='ps -ax | grep "jupyter-notebook" | awk "{print \$1}" | xargs kill'
### Vim everywhere
# But actually, neovim
alias vi=nvim
alias vim=nvim
function reload-all-vim() {
tmux list-panes -aF "#{pane_id} #{pane_current_command}" |
awk '/vim|nvim/ {print $1}' |
xargs -I {} tmux send-keys -t {} "C-[" ":so ~/.vimrc" "C-m"
}
function install-jupyter-vim() {
if [ command -v jupyter --version ]
then
# Create required directory in case (optional)
mkdir -p $(jupyter --data-dir)/nbextensions
# Clone the repository
cd $(jupyter --data-dir)/nbextensions
git clone https://github.com/lambdalisue/jupyter-vim-binding vim_binding
# Activate the extension
jupyter nbextension enable vim_binding/vim_binding
else
echo "Please make sure Jupyter is installed"
exit 1
fi
}
function delswp() { find . -type f -name "*.sw[klmnop]" -delete }
## Git
# Create a better gitignore
alias get_gitignore="curl https://www.toptal.com/developers/gitignore/api/jupyternotebooks,python,macos,windows,linux,zsh > .gitignore"
# Better checkout
gch () {
git for-each-ref --format='%(refname:short)' refs/heads | fzf -q "$@" | xargs git checkout
}
# Amend commit
function gac() {git add . && git commit --amend --no-edit}
# Add & commit
function gitc () { git add --all && if [ $# -eq 0 ]; then git commit; else git commit -m "$@"; fi }
# Push to master
function gitp () { git push origin $(git branch --show-current) $@; }
alias gitpf="gitp --force-with-lease"
# Back to master and pull
function gmp () {
MAIN_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | xargs basename)
git checkout $MAIN_BRANCH && git fetch && git pull origin $MAIN_BRANCH;
}
# Git squash last n commits
function gits () {
NUM_COMMITS="$1"
COMMIT_MSG="${@:2}"
git reset --soft HEAD~$NUM_COMMITS && git commit -m $COMMIT_MSG;
}
# git recursively pull all subdirectories
alias gitr="find . -name '.git' -type d | sed 's/\/.git//' | xargs -P10 -I{} git -C {} pull"
# Re-apply gitignore
alias giti="git rm -r --cached . && git add . && git commit -m 're-applied .gitignore'"
# I must type this 100 times a day; shorten it
function main_branch () {
git symbolic-ref refs/remotes/origin/HEAD | xargs basename
}
alias gs="git status"
alias gl="git log"
alias gp="git pull"
alias gres="git restore ."
function grbm () {
git rebase $(main_branch) $@
}
alias grbc="git rebase --continue"
alias garp="git add . && grc"
alias gcan="git commit --amend --no-edit"
function gdmno () {
git diff $(main_branch) --name-only
}
# Github cli
alias ghpr="gh pr create"
alias ghm="gh pr checks --watch && gh pr merge --merge"
alias ghs="gh pr checks --watch && gh pr merge --squash"
function ghmm() {
PR_ID=$1
END_TIME=$((SECONDS+1800)) # 30 minutes from now
while [ $SECONDS -lt $END_TIME ]; do
PR_STATUS=$(gh pr view $PR_ID --json reviews -q '.reviews.nodes[0].state')
if [ "$PR_STATUS" = "APPROVED" ]; then
# gh pr merge $PR_ID --merge
echo "PR $PR_ID merged!"
return 0
fi
sleep 10
done
echo "Time limit reached. PR $PR_ID was not merged."
}
# Tag for review
alias ghar="gh pr edit --add-reviewer"
alias ghtfr="gh pr edit --add-reviewer btimothy-har,nikodraca,wjwatkinson"
alias ghvw="gh pr view --web"
alias ghurl="gh pr view --json url -q '.url' | tr -d '\n'"
alias ghcp="gh pr view --json url -q '.url' | tr -d '\n' | pbcopy"
# Common workflows
alias gpm="gitp && ghpr -f && sleep 10 && ghm"
## Run black on files in git staging
function blacken () {
git status --porcelain | cut -d ' ' -f3 | xargs black
}
## Pandoc - generate Bootstrap HTML
function panodt () {
filename=$(basename -- "$1")
filename="${filename%.*}"
OUTPUT_FILENAME="$filename.odt"
pandoc "$1" --variable colorlinks=true -o "$OUTPUT_FILENAME"
echo "$OUTPUT_FILENAME"
}
function panstrap () {
DIR="$HOME/Templates"
# If there's a second argument, use that as the output filename
if [ "$#" -eq 2 ]
then
pandoc "$1" -o "$2" --template $DIR/template.html --css $DIR/template.css --self-contained --toc --toc-depth 3 --quiet
elif [ "$#" -eq 1 ]
then
filename=$(basename -- "$1")
filename="${filename%.*}"
OUTPUT_FILENAME="$filename.html"
pandoc "$1" -o "$OUTPUT_FILENAME" --template $DIR/template.html --css $DIR/template.css --self-contained --toc --toc-depth 3
else
echo "Illegal number of parameters: need at least input filename and optional output filename"
exit 1
fi
}
## BigQuery
alias bqq="bq query --use_legacy_sql=false"
function dryrun () {
dbt compile --model "$@" |
awk '/[0-9]{2}:[0-9]{2}:[0-9]{2} Compiled node/ {flag=1; next} flag' |
tee /dev/fd/2 |
bq query --use_legacy_sql=false --dry_run
}
## Moving around
alias t1="tree --dirsfirst -ChFL 1"
alias si="dev cd siphon"
alias to="dev cd totally-radford"
alias ia="dev cd impulse-api"
alias os="dev cd os"
alias analysis="dev cd analysis"
alias fw="dev cd os; cd tools/frameworks"
alias tw="dev cd os; cd tools/web"
alias pp="dev cd party-parrots"
function pg_pw() {
cat $HOME/src/github.com/ShopifyPeopleAnalytics/siphon/config/sources.development.json | jq -r '.read_database' | cut -f3-3 -d":" | cut -f1 -d"@" | tr -d '[:space:]' | pbcopy
}
function db () {
pg_pw
gcloud sql connect people-analytics --user=postgres --database=hr
}
alias wds="gcloud scheduler jobs run worker_daily_snapshot"
alias bullet='pbpaste | sed "s/^.\{6\}//g" | pbcopy'
## Dotfiles
# Update dotfiles
function dfpush() {
(
cd ~/dotfiles
git add .
git commit -m 'autoupdate'
git push origin master
)
}
function dfpull() {
(
cd ~/dotfiles
git pull --ff-only
./install 2>&1 >/dev/null
)
}
## Etc
alias cl="clear"
alias ding="afplay /System/Library/Sounds/Funk.aiff"
# Install dependencies
alias install-pip="pip install --user wheel pandas clipboard tabulate"
# More user stuff
export PATH="$HOME/.poetry/bin:$PATH"
export EDITOR="nvim"
alias shrug="echo '¯\\_(ツ)_/¯' | pbcopy"
function notify() {
INCANTATION="$@"
COMMAND=$( echo "$INCANTATION" | cut -d " " -f1 )
"$INCANTATION" && terminal-notifier -title "$COMMAND" -message "Task complete" -contentImage "https://cdn4.iconfinder.com/data/icons/logos-brands-5/24/shopify-128.png"
}
alias clip='python $HOME/dotfiles/scripts/clipboard_md.py'
function syn() {
WORD="$1"
python $HOME/dotfiles/scripts/dict.py syn "$WORD"
}
function def() {
WORD="$1"
python $HOME/dotfiles/scripts/dict.py def "$WORD"
}
function ant() {
WORD="$1"
python $HOME/dotfiles/scripts/dict.py ant "$WORD"
}
function tomato() {
termdown 25m -T "🍅" --no-figlet && say "ding"
}