-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
aliases.zsh
210 lines (172 loc) · 5.96 KB
/
aliases.zsh
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
#!/usr/bin/env zsh
# aliases.zsh
# for all active aliases, run `alias`
# Atom
# https://github.com/jeefberkey/dotfiles/blob/2ded1c3/.zshrc#L48-L61
alias atom-beta="atom-nightly"
alias apm-beta="apm-nightly"
alias atom="atom-nightly"
alias apm="apm-nightly"
# dotfiles
# https://stackoverflow.com/q/4210042#comment38334264_4210072
alias mu=" \
cd ${DOTFILES:-$HOME/Dropbox/dotfiles} && \
garbage && \
mackup backup --force --root && \
git fetch --all && \
git submodule update --init --recursive && \
git status"
alias mux=" \
cd ${DOTFILES:-$HOME/Dropbox/dotfiles} && \
garbage --verbose && \
mackup backup --force --root --verbose && \
git fetch --all --verbose && \
git submodule update --init --recursive --remote && \
git status --verbose"
# Git
alias gap="git add --patch --verbose" # override `git apply` alias
alias gc="git commit --verbose --gpg-sign"
alias gca="git commit --amend --verbose --gpg-sign"
alias gcl="git clone --verbose --progress --recursive --recurse-submodules"
alias gcm="git commit --verbose --gpg-sign --message"
alias gco="git checkout --progress"
# `git checkout` the default branch
# place the function inside `{()}` to prevent the leaking of variable data
# https://stackoverflow.com/a/37675401
gcom () {(
git checkout --progress "$(git_default_branch)"
)}
gdm () {(
git diff "$(git_default_branch)"
)}
alias gfgs="git fetch --all --verbose && git status"
ggc () {(
if git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
git fetch --prune --prune-tags --verbose
git gc --aggressive --prune=now
else
return 1
fi
)}
# initial commit’s hash
# https://stackoverflow.com/a/1007545
# https://stackoverflow.com/q/1006775#comment23686803_1007545
alias gic="git rev-list --topo-order --parents HEAD | egrep '^[a-f0-9]{40}$'"
alias ginit="git init"
alias glog="git log"
# return the name of the repository’s default branch
# ohmyzsh/ohmyzsh@c99f3c5/plugins/git/git.plugin.zsh#L28-L35
git_default_branch () {(
# run only from within a git repository
# https://stackoverflow.com/a/53809163
if git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
# check if there’s a `remote` with a default branch and
# if so, then use that name for `default_branch`
# https://stackoverflow.com/a/44750379
if git symbolic-ref refs/remotes/origin/HEAD > /dev/null 2>&1; then
default_branch="$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')"
# check for `main`, which, if it exists, is most likely to be default
elif [ -n "$(git branch --list main)" ]; then
default_branch=main
# check for a branch called `master`
elif [ -n "$(git branch --list master)" ]; then
default_branch=master
else
printf 'unable to detect a \x60main\x60, \x60master\x60, or default '
printf 'branch in this repository\n'
return 1
fi
else
printf 'git_default_branch must be called from within a Git repository\n'
return 1
fi
printf '%s' "$default_branch"
)}
alias gdb="git_default_branch"
# git merge main
gmm () {(
# set Git merge verbosity environment variable
# 4 “shows all paths as they are processed” but
# 5 is “show detailed debugging information”
# https://github.com/progit/progit2/commit/aea93a7
GIT_MERGE_VERBOSITY=4 git merge --verbose --progress --strategy-option patience "$(git_default_branch)"
)}
alias gmv="git mv --verbose"
# git pull after @ohmyzsh `gupav` ohmyzsh/ohmyzsh@3d2542f
alias gpull="git pull --all --rebase --autostash --verbose && git status"
# git push after @ohmyzsh `gpsup` ohmyzsh/ohmyzsh@ae21102
alias gpv='git push --verbose --set-upstream origin "$(git_current_branch)"'
alias gsu="git submodule update --init --recursive --remote"
alias gtake="git checkout -b"
alias gti="git"
gu () {
# run only from within a git repository
# https://stackoverflow.com/a/53809163
if git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
git fetch --all --verbose
# `git submodule update` with `--remote` appears to slow Git to a crawl
# https://docs.google.com/spreadsheets/d/14W8w71DK0YpsePbgtDkyFFpFY1NVrCmVMaw06QY64eU
git submodule update --init --recursive
garbage
git status
fi
}
# https://github.com/tarunsk/dotfiles/blob/5b31fd6/.always_forget.txt#L1957
alias gvc="git verify-commit HEAD"
# GPG
if command -v gpg2 > /dev/null 2>&1; then
alias gpg="gpg2"
fi
# Python
alias python="python3"
alias pip="pip3"
# shell
# https://mywiki.wooledge.org/BashPitfalls?rev=524#Filenames_with_leading_dashes
alias cp="cp -r -i --"
cy () {
if [ -n $2 ]; then
cp "$1" "$2"
else
# if there is no second argument,
# then copy to the current directory
cp "$1" "$PWD"
fi
}
garbage () {(
# if `garbage -v` or `garbage --verbose`,
# then use `-print` during `-delete`
if [ "$1" = -v ] || [ "$1" = --verbose ]; then
verbose=-print
fi
# delete `.DS_Store` files recursively
find . -type f \
-name '.DS_Store' \
$verbose -delete
# delete empty, zero-length files except those
# with specific names or within `.git/` directories
find . -type f -size 0 \
-not -path './.git/*' -and \
-not -path '*.gitkeep' -and \
-not -path '*.hushlogin' -and \
-not -path '*.lock' \
$verbose -delete
# delete empty directories, except within `.git/`, recursively \
# https://stackoverflow.com/q/4210042#comment38334264_4210072 \
find . -type d -size 0 \
-not -path './.git/*' -and \
-not -path './.well-known/*' \
$verbose -delete
)}
alias mv="mv -v -i" # https://unix.stackexchange.com/a/30950
alias unixtime="date +%s" # https://stackoverflow.com/a/12312982
alias which="which -a"
alias whcih="which"
alias whihc="which"
alias whuch="which"
alias wihch="which"
# Zsh
alias aliases="edit $ZSH_CUSTOM/aliases.zsh; . ~/.zshrc && exec zsh"
alias ohmyzsh="cd ${ZSH:-$HOME/.oh-my-zsh}"
alias zshconfig="edit ~/.zshrc; . ~/.zshrc && exec zsh"
alias zshenv="edit ~/.zshenv; . ~/.zshrc && exec zsh"
alias zshrc="zshconfig"