-
Notifications
You must be signed in to change notification settings - Fork 9
/
aliases
207 lines (196 loc) · 4.98 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
# APT
aptup() {
sudo apt update
for lock in '/var/lib/dpkg/lock-frontend' '/var/lib/dpkg/lock'; do
if [ -e "$lock" ]; then
ch='-'
locked=''
while sudo fuser "$lock" >/dev/null 2>&1; do
locked='y'
case "$ch" in
-) ch=\\ ;;
\\) ch='|' ;;
\|) ch='/' ;;
/) ch='-' ;;
esac
printf "%b" "\r[$ch] Waiting for $lock..."
sleep 0.5
done
[ "$locked" = 'y' ] && echo
unset ch locked
fi
done
sudo apt -y upgrade
}
# Number conversion
hex() {
if [ "$#" -ne 1 ]; then
echo "Usage: hex <num>"
fi
local num
case "$1" in
0x*)
num="$((16#${1#0x}))"
;;
0*)
num="$((8#${1#0}))"
;;
b*)
num="$((2#${1#b}))"
;;
*)
num="$1"
;;
esac
echo "Hex: $(echo "obase=16; $num" | bc)"
echo "Dec: $(echo "obase=10; $num" | bc)"
echo "Bin: $(echo "obase=2; $num" | bc)"
# [:print:]
if [ "$num" -ge "32" ] && [ "$num" -le "126" ]; then
echo "Chr: $(printf '\\x%02x' "$num")"
fi
}
# http://boredzo.org/blog/archives/2016-08-15/colorized-man-pages-understood-and-customized
man() {
env \
LESS_TERMCAP_mb="$(printf "\e[1;31m")" \
LESS_TERMCAP_md="$(printf "\e[1;31m")" \
LESS_TERMCAP_me="$(printf "\e[0m")" \
LESS_TERMCAP_se="$(printf "\e[0m")" \
LESS_TERMCAP_so="$(printf "\e[1;44;33m")" \
LESS_TERMCAP_ue="$(printf "\e[0m")" \
LESS_TERMCAP_us="$(printf "\e[1;32m")" \
man "$@"
}
# Check if reboot is required for Ubuntu
if [ -f /usr/lib/update-notifier/update-motd-reboot-required ]; then
reboot-required() {
/usr/lib/update-notifier/update-motd-reboot-required
}
fi
# Enable color support
if ls --color -d . >/dev/null 2>&1; then
alias ls='ls --color'
else
alias ls='ls -G'
fi
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
# Some more basic aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias md='mkdir -p'
mdcd() {
mkdir -p "$1" && cd "$1"
}
alias rd='rmdir'
# Homebrew
brdep() {
leaves=()
while IFS= read -r leaf; do
leaves+=("$leaf")
done < <(brew leaves)
brew deps --installed --for-each "${leaves[@]}"
}
brdepb() {
leaves=()
while IFS= read -r leaf; do
leaves+=("$leaf")
done < <(brew leaves)
brew deps --installed --for-each --include-build "${leaves[@]}"
}
brdeprb() {
leaves=()
while IFS= read -r leaf; do
leaves+=("$leaf")
done < <(brew leaves -r)
brew deps --installed --for-each --include-build "${leaves[@]}"
}
alias brup='brew upgrade && brew cleanup'
# Bundler
alias be='bundle exec'
alias bi='bundle install'
alias bu='bundle update'
# Git
if [ -n "$ZSH_VERSION" ]; then
alias git='noglob git'
fi
alias g='git'
alias ga='git add'
alias gap='git add --patch'
alias gb='git branch'
alias gba='git branch --all'
alias gbl='git blame'
alias gbv='git branch -vv'
alias gc='git commit'
alias gc!='git commit --amend'
alias gca='git commit --all'
alias gca!='git commit --all --amend'
alias gcb='git checkout -b'
alias gcd='git checkout develop'
alias gcl='git clone --recurse-submodules'
alias gcm='git show-ref --quiet refs/heads/main && git checkout main || git checkout master'
alias gco='git checkout'
alias gcop='git checkout --patch'
alias gcp='git cherry-pick'
alias gd='git diff'
alias gdc='git diff --cached'
alias gf='git fetch'
alias gfl='git-flow'
alias ggp='git push origin HEAD'
alias gl='git pull'
alias glg='git log --decorate --graph --pretty=format:"%C(auto,yellow)%h %C(auto,blue)%ar %C(auto,green)%an%C(auto,reset) %s%C(auto)%d"'
alias glga='glg --all'
alias glr='git pull --rebase'
alias gm='git merge'
alias gma='git merge --abort'
alias gp='git push'
alias gpf='git push --force-with-lease'
gpr() {
git fetch "${2:-$(git remote | grep ^upstream || echo origin)}" "refs/pull/$1/head:pr/$1"
git checkout "pr/$1"
}
alias gr='git remote'
alias gra='git remote add'
alias grb='git rebase'
alias grba='git rebase --abort'
alias grbc='git rebase --continue'
alias grbi='git rebase --interactive'
alias grs='git reset'
alias grsh='git reset --hard'
alias grsp='git reset --patch'
alias grsu='git reset --hard "@{upstream}"'
alias grup='git remote update'
alias grt='git restore'
alias grtp='git restore --patch'
alias grv='git remote --verbose'
alias gsb='git submodule'
alias gsh='git show'
alias gst='git status'
alias gsta='git stash'
alias gstap='git stash --patch'
alias gstd='git stash drop'
alias gstp='git stash pop'
alias gsu='git submodule update'
alias gsur='git submodule update --remote'
alias gsc='git switch --create'
alias gsd='git switch develop'
alias gsm='git show-ref --quiet refs/heads/main && git switch main || git switch master'
alias gsw='git switch'
alias gswd='git switch --detach'
# Vim
if command -v vim >/dev/null; then
alias v='vim'
alias vi='vim'
elif command -v vi >/dev/null; then
alias v='vi'
fi
if command -v nvim >/dev/null; then
alias nv='nvim'
fi
# Zinit
if [ -n "$ZSH_VERSION" ]; then
alias ziup='zinit self-update && zinit update --all --no-pager && zinit cclear'
fi