-
Notifications
You must be signed in to change notification settings - Fork 3
/
.zaliases
202 lines (181 loc) · 5.72 KB
/
.zaliases
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
# Bundler
alias be='bundle exec'
alias bi='bundle install --jobs 4'
alias bu='bundle update'
brew() {
if /usr/local/bin/brew $@; then
if [[ $1 == "install" || $1 == "uninstall" ]]; then
echo "Don't forget to adjust brew packages in dotfiles"
fi
fi
}
# Better utilities
alias git='hub'
alias cat='bat'
alias l='exa'
# Docker
alias lzd='lazydocker'
alias dc=docker-compose
alias dc-run='dc run --rm'
alias docker-kill-all-running='docker kill $(docker ps -q)'
alias docker-delete-all-containers='docker rm $(docker ps -a -q)'
alias docker-delete-all-images='docker rmi $(docker images -q)'
# Misc.
alias standuplog='~/bin/standuplog'
alias dokku='ssh -t [email protected] dokku'
alias ngrok-url="curl --silent http://127.0.0.1:4040/api/tunnels | jq '.tunnels[0].public_url'"
# Shopify
alias monday='dev cd shopify && git pull --prune && dev up && bin/rails log:clear'
alias core-check='dev style --include-branch-commits && dev typecheck && dev test --include-branch-commits'
cdev-all() {
cd ~/src/github.com/$(find ~/src/github.com -maxdepth 2 -mindepth 2 -type d | sed "s|$HOME/src/github.com/||" | fzf)
}
cdev() {
cd ~/src/github.com/Shopify/$(find ~/src/github.com/Shopify -maxdepth 1 -mindepth 1 -type d | sed "s|$HOME/src/github.com/Shopify/||" | fzf)
}
# https://github.com/aykamko/tag
if (( $+commands[tag] )); then
export TAG_SEARCH_PROG="ag"
export TAG_CMD_FMT_STRING="nvim {{.Filename}} +{{.LineNumber}}"
tag() { command tag "$@"; source ${TAG_ALIAS_FILE:-/tmp/tag_aliases} 2>/dev/null }
alias ag=tag
fi
##### FZF aliases #####
#######################
# Modified version where you can press
# - CTRL-O to open with `open` command,
# - CTRL-E or Enter key to open with the $EDITOR
fo() {
local out file key
out=$(fzf --preview 'bat --style=numbers --color=always --line-range :500 {}' --query="$1" --exit-0 --expect=ctrl-o,ctrl-e)
key=$(head -1 <<< "$out")
file=$(head -2 <<< "$out" | tail -1)
if [ -n "$file" ]; then
[ "$key" = ctrl-o ] && open "$file" || ${EDITOR:-vim} "$file"
fi
}
# fcd - cd to selected directory
fcd() {
local dir
dir=$(find ${1:-*} -path '*/\.*' -prune \
-o -type d -print 2> /dev/null | fzf +m) &&
cd "$dir"
}
# fda - including hidden directories
fda() {
local dir
dir=$(find ${1:-.} -type d 2> /dev/null | fzf +m) && cd "$dir"
}
# cdf - cd into the directory of the selected file
cdf() {
local file
local dir
file=$(fzf +m -q "$1") && dir=$(dirname "$file") && cd "$dir"
}
# fh - repeat history
fh() {
print -z $(([ -n "$ZSH_NAME" ] && fc -l 1 || history) | fzf +s | sed 's/ *[0-9]* *//')
}
# fkill - kill processes - list only the ones you can kill.
fkill() {
local pid
if [ "$UID" != "0" ]; then
pid=$(ps -f -u $UID | sed 1d | fzf -m | awk '{print $2}')
else
pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}')
fi
if [ "x$pid" != "x" ]
then
echo $pid | xargs kill -${1:-9}
fi
}
# fbr - checkout git branch
fbr() {
local branches branch
branches=$(git branch) &&
branch=$(echo "$branches" | fzf +m) &&
git checkout $(echo "$branch" | sed "s/.* //")
}
# fbr - checkout git branch (including remote branches)
fbr() {
local branches branch
branches=$(git branch --all | grep -v HEAD) &&
branch=$(echo "$branches" |
fzf-tmux -d $(( 2 + $(wc -l <<< "$branches") )) +m) &&
git checkout $(echo "$branch" | sed "s/.* //" | sed "s#remotes/[^/]*/##")
}
# fco - checkout git branch/tag
fco() {
local tags branches target
tags=$(
git tag | awk '{print "\x1b[31;1mtag\x1b[m\t" $1}') || return
branches=$(
git branch --all | grep -v HEAD |
sed "s/.* //" | sed "s#remotes/[^/]*/##" |
sort -u | awk '{print "\x1b[34;1mbranch\x1b[m\t" $1}') || return
target=$(
(echo "$tags"; echo "$branches") |
fzf-tmux -l30 -- --no-hscroll --ansi +m -d "\t" -n 2) || return
git checkout $(echo "$target" | awk '{print $2}')
}
# fcoc - checkout git commit
fcoc() {
local commits commit
commits=$(git log --pretty=oneline --abbrev-commit --reverse) &&
commit=$(echo "$commits" | fzf --tac +s +m -e) &&
git checkout $(echo "$commit" | sed "s/ .*//")
}
# fshow - git commit browser
fshow() {
local out sha q
while out=$(
git log --decorate=short --graph --oneline --color=always |
fzf --ansi --multi --no-sort --reverse --query="$q" --print-query); do
q=$(head -1 <<< "$out")
while read sha; do
[ -n "$sha" ] && git show --color=always $sha | less -R
done < <(sed '1d;s/^[^a-z0-9]*//;/^$/d' <<< "$out" | awk '{print $1}')
done
}
# fcs - get git commit sha
# example usage: git rebase -i `fcs`
fcs() {
local commits commit
commits=$(git log --color=always --pretty=oneline --abbrev-commit --reverse) &&
commit=$(echo "$commits" | fzf --tac +s +m -e --ansi --reverse) &&
echo -n $(echo "$commit" | sed "s/ .*//")
}
# fstash - easier way to deal with stashes
# type fstash to get a list of your stashes
# enter shows you the contents of the stash
# ctrl-d shows a diff of the stash against your current HEAD
# ctrl-b checks the stash out as a branch, for easier merging
fstash() {
local out q k sha
while out=$(
git stash list --pretty="%C(yellow)%h %>(14)%Cgreen%cr %C(blue)%gs" |
fzf --ansi --no-sort --query="$q" --print-query \
--expect=ctrl-d,ctrl-b);
do
q=$(head -1 <<< "$out")
k=$(head -2 <<< "$out" | tail -1)
sha=$(tail -1 <<< "$out" | cut -d' ' -f1)
[ -z "$sha" ] && continue
if [ "$k" = 'ctrl-d' ]; then
git diff $sha
elif [ "$k" = 'ctrl-b' ]; then
git stash branch "stash-$sha" $sha
break;
else
git stash show -p $sha
fi
done
}
unalias z
z() {
if [[ -z "$*" ]]; then
cd "$(_z -l 2>&1 | sed -n 's/^[ 0-9.,]*//p' | fzf)"
else
_z "$@"
fi
}