-
Notifications
You must be signed in to change notification settings - Fork 1
/
.commonshrc
210 lines (175 loc) · 4.37 KB
/
.commonshrc
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
export PATH="${PATH}:${HOME}/.local/bin:/opt/go/bin"
export PYTHONSTARTUP="${HOME}/.local/bin/pythonstartup.py"
# Uploading sessions by default is the worst possible idea.
export ASCIINEMA_API_URL="https://0.0.0.0/"
export EDITOR=vim # Scarcely used (see `update-alternatives --config editor`)
export LC_ALL=C.UTF-8
export FUNCTIONS_CORE_TOOLS_TELEMETRY_OPTOUT=1
# Nicer less by default
export LESS='-RFXS -x4 -n'
export PAGER='less'
export MANPAGER='less'
# 256 colors, except on TTY.
if [ "$TERM" != "linux" ]; then
export TERM='xterm-256color'
fi
# Color aliases
alias grep='grep --color=auto'
alias tree='tree -C'
# Aliases
alias cal='ncal -Mb'
alias cdr='cd $(git rev-parse --show-toplevel)'
alias gd='git diff -M -C'
alias gds='git diff -M -C --staged'
alias gpf='git push --force-with-lease'
alias gs='git status --short'
alias gap='git add -p'
alias la='ll -va'
alias ll='ls -vlh'
alias ls='ls --group-directories-first --color=auto -v'
alias mkdir='mkdir -pv'
alias optipng='optipng -strip all -o7'
alias phpcbf='phpcbf --standard=PSR12'
alias phpcs='phpcs --standard=PSR12'
alias py='python3'
alias rm='rm --preserve-root'
alias tf='terraform'
alias tfp='clear; rm -f plan 2>/dev/null; terraform plan -out plan'
alias tfa='terraform apply plan'
alias uuid='cat /proc/sys/kernel/random/uuid'
# Forgetting to sudo with docker.
export DOCKER='sudo docker'
export COMPOSE='sudo docker-compose'
alias docker='sudo docker'
alias docker-compose='sudo docker-compose'
alias dcb='sudo docker-compose build'
alias dcd='sudo docker-compose down'
alias dce='sudo docker-compose exec'
alias dcl='sudo docker-compose logs --follow'
alias dcr='sudo docker-compose restart'
alias dcs='sudo docker-compose stop'
alias dcu='sudo docker-compose up'
# tmux for the lazy.
t() {
tmux a -t "$1" || tmux new -s "$1"
}
# Nicer du (ncdu is nice too).
duf() {
du --apparent-size -csh -- "$@" | sort -rh
}
# Handy grep aliases, since ack sucks.
g() {
grep -EHnr --exclude-dir='node_modules' --exclude-dir='vendor' --exclude-dir='.git' "$*" . | "$PAGER" ;
}
gi() {
grep -EHnri --exclude-dir='node_modules' --exclude-dir='vendor' --exclude-dir='.git' "$*" . | "$PAGER" ;
}
# Same aliases for the faster git grep.
gg() {
git grep -En "$@"
}
ggi() {
git grep -Eni "$@"
}
# Find aliases
f() {
find . -iname "*$**" 2>/dev/null | grep -Ev '^\./(vendor|node_modules)/'
}
ff() {
find . -type "f" -iname "*$**" 2>/dev/null | grep -Ev '^\./(vendor|node_modules)/'
}
fd() {
find . -type d -iname "*$**" 2>/dev/null | grep -Ev '^\./(vendor|node_modules)/'
}
# Make a git repo with an empty commit
mkrepo() {
(
mkdir "$1"
pushd "$1"
git init
git ci --allow-empty -m "Initial commit"
popd ..
) > /dev/null
}
# Unmount a SSHFS.
ufs() {
fusermount -u "$1"
}
# Mount a SSHFS.
fs() {
local src="$1"
local dest="$2"
[ -d "$dest" ] || mkdir "$dest"
ufs "$dest" > /dev/null
sshfs "$src" "$dest"
}
# Examine a x509 cert.
cert() {
openssl x509 -in "$1" -text -noout
}
hl() {
hledger is -p 'this month'
printf "-------------------\n-------------------\n"
hledger bs -p 'this month'
}
hlp() {
hledger is -p "$*"
printf "-------------------\n-------------------\n"
hledger bs -p "$*"
}
ts() {
date "-d@$1"
}
# Convert a SVG to PNG
# svg2png FILE WIDTH
svg2png() {
inkscape --export-png="$1.png" --export-width="$2" --export-background-opacity=0 --without-gui "$1"
}
pass() {
val="$(dd if=/dev/urandom bs=1 count=36 status=none | base64)"
echo -n "$val" | xclip
echo "$val"
}
gv() {
vim -q <(grep -nr "$@" .) +copen
}
gvi() {
vim -q <(grep -inr "$@" .) +copen
}
ggv() {
vim -q <(git grep -n "$@") +copen
}
ggvi() {
vim -q <(git grep -in "$@") +copen
}
repl() {
while true; do
clear
"$@"
read
done
}
rekey() {
gpg-connect-agent "scd serialno" "learn --force" /bye
}
# fix PATTERN
# Commits the index as a fixup to the first commit that matches PATTERN
fix() {
sha="$(git log -n 1 --format='%H' -F -i --grep "$*")"
if [ '' = "$sha" ]; then
echo 'No commit found.' 1>&2
return 1
fi
git commit --fix "$sha"
}
# dcredo SERVICENAME
dcredo() {
docker-compose stop "$1" && \
docker-compose rm -f "$1" && \
docker-compose up -d
}
nonce() {
nonce="$(dd if=/dev/urandom bs=1 count=4 status=none | xxd -p)"
printf "%s" "$nonce" | xclip
echo "$nonce"
}