-
Notifications
You must be signed in to change notification settings - Fork 0
/
.aliases
210 lines (177 loc) · 5.26 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
#!/usr/bin/bash
## epoch_ms to timestamp
ts () { python3 -c "from datetime import datetime; print(datetime.fromtimestamp(${1}/1000 - (60*60*7)).strftime(\"%Y-%m-%d %H:%M:%S\"))"; }
## launch lazygit
alias lg='lazygit'
## activate python env from path or in current directory if not path given
activate () {
if [ "$#" -eq 0 ]; then
[ -f ./env/bin/activate ] && source ./env/bin/activate
else
[ -f "$1"/bin/activate ] && source "$1"/bin/activate
fi
}
# use this cmd to open lf and cd into whatever directory it is in when it exits
if command -v lf &> /dev/null; then
lfcd () {
# `command` is needed in case `lfcd` is aliased to `lf`
cd "$(command lf -print-last-dir "$@")" || return
}
fi
# ninja build and filter compdb
alias compdb="ninja -C out all_apps -t compdb | jq '[ .[] | select(.command | contains(\"bad_toolchain\")|not) ]' > compile_commands.json"
################################################################################
# Common Git Commands
################################################################################
#######################
###### Helpers
#######################
# function to confirm operation
confirm_branch () {
branch=$(gbc 2>&1)
if [ $? -ne 0 ]; then
return 1
fi
if [ -n "$ZSH_VERSION" ]; then
read "?You are about to $1 $branch. Continue? (y/n) " confirm
else
read -p "You are about to $1 $branch. Continue? (y/n) " confirm
fi
if [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]]; then
return 0
fi
return 1
}
#######################
###### Basics
#######################
alias gb='git branch'
alias gs='git status'
alias gc='git clean -dxf'
#######################
###### Branching
#######################
# return current branch
alias gbc='git branch --show-current'
# grep for branches
gbg () { git branch | grep -E "$@"; }
# make and checkout new brallanch
alias gbn='git checkout -b'
# delete branch
alias gbd='git branch -D'
# delete branch, grep branch name
gbdg () { gbd $(gbg "$@"); }
# fetch branch
unalias gfo 2>/dev/null
gfo () { branch=$1; shift; git fetch --prune origin "$branch":"$branch" "$@"; }
# checkout branch
alias gco='git checkout'
# checkout branch, grep branch name
gcog () { local branch=$1; shift; gco $(gbg "$branch") "$@"; }
# fetch and checkout branch
gfco () { gfo "$1" && gco "$1"; }
#######################
###### Conflicts
#######################
# list conflicted files
alias gcl='git diff --name-only --diff-filter=U'
# check if there are any conflict markers left
alias gdc='git diff --check'
#######################
###### Log
#######################
# open the log (current branch or other)
alias gl='git log'
# open the log, grep for branch name
unalias glg 2>/dev/null
glg () {
local branch=$1
shift
gl $(gbg "$branch") "$@"
}
# short log
alias glo='gl --oneline'
# short log, grep for branch name
unalias glog 2>/dev/null
glog () {
local branch=$1
shift
glo $(gbg "$branch") "$@"
}
#######################
###### Rebasing
#######################
# rebase
alias grb='git rebase'
# squash, pass in how far back to go
# alias gsq='git rebase -i HEAD~'
gsq () {
local back=$1
shift
git rebase -i HEAD~"$back" "$@"
}
# rebase onto other branch from origin
unalias grbo 2>/dev/null
grbo () { local branch=$1; shift; grb origin/"$branch" "$@"; }
# fetch and rebase
# alias gfrb='f(){ gfo "$1" ; [ $? -eq 0 ] && grb "$1" || echo "Fetch failed; exiting" ; unset -f f;}; f'
gfrb () { gfo "$1" || echo "Fetch failed; exiting" && grb "$1"; }
# continue rebase
alias grc='grb --continue'
# abort rebase
alias gra='grb --abort'
#######################
###### Cherry-picking
#######################
# cherry-pick
alias gcp='git cherry-pick'
# continue cherry-pick
alias gcpa='gcp --abort'
# abort cherry-pick
alias gcpc='gcp --continue'
#######################
###### Submodules
#######################
# init all submodules defined in $SUBMODULES (defined elsewhere)
# alias gsm='git submodule update --init --recursive $SUBMODULES'
# force init all submodules defined in $SUBMODULES (defined elsewhere)
# alias gsmf='git submodule update --init --recursive -f $SUBMODULES'
#######################
###### Committing
#######################
# amend commit, reset author
alias gca='git commit --amend'
# amend commit, reset author, don't edit commit msg
alias gcan='gca --no-edit'
# add conflicted files
alias gac='git add $(gcl)'
# fixup commit
unalias gcf 2>/dev/null
gcf () {
local back=$1
shift
git commit --fixup HEAD~"$back" "$@"
}
#######################
###### Pushing
#######################
# force push, confirm first
unalias gpf 2>/dev/null
gpf () {
confirm_branch "force-push to" && git push -f || echo "cancelled"
}
# push branch to origin, confirm first
unalias gpu 2>/dev/null
gpu () {
confirm_branch "push branch to origin" && git push -u origin $(gbc) || echo "cancelled"
}
# force push branch to origin, confirm first
gpuf () {
confirm_branch "force push branch to origin" && git push -u origin $(gbc) -f || echo "cancelled"
}
#######################
###### Misc
#######################
alias gsh='git rev-parse --short HEAD'
# source private alises if it exists
[ -f "$HOME/dotfiles_priv/.priv_aliases" ] && source "$HOME/dotfiles_priv/.priv_aliases"