-
Notifications
You must be signed in to change notification settings - Fork 2
/
bash_aliases
279 lines (222 loc) · 9.13 KB
/
bash_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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# -*- bash -*-
# Symlink this to ~/.bash_aliases:
# rm -f ~/.bash_aliases && ln -sf ~/git/dotfiles/bash_aliases ~/.bash_aliases
# 1Password uses the LANG-based locale settings, which makes it use US date
# formats (MM/DD/YYYY) on my system. Override this to use Swedish date format
# instead (YYYY-MM-DD).
alias 1password='LANG=sv_SE.UTF-8 1password'
# Color is nice, and it also makes it easier to distinguish different types
# of files from each other.
alias ls='ls --color=auto'
alias jq='jq -C'
# Makes grep color the search term when grepping - very helpful.
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
if [ -x /usr/local/bin/rainbow ]; then
# Uses Rainbow coloring of ifconfig output, to make it easier to see the IP
# address(es) configured.
alias ifconfig='ifconfig | rainbow -f ifconfig'
fi
# This command will loop over all git branches and delete the ones that
# *have been pushed* to the remote. Non-pushed branches will not be
# touched. The `--prune` part at the end will also delete local remote-only
# branches which have been deleted at the remote.
alias prune_branches='git branch -l | grep -v "*" | grep -v upstream-master | xargs git branch -d 2>&1 | grep -v "If you are sure" ; git fetch --all --prune'
alias pbcopy="xclip -sel clip"
alias start_tomcat='$HOME/java/tomcat/bin/startup.sh'
alias kill_gradle='pkill -e -f gradle'
alias tail_tomcat_log='tail -n60 -f ~/java/tomcat/logs/catalina.out | rainbow -f catalina'
alias cat_tomcat_log='cat ~/java/tomcat/logs/catalina.out'
alias less_tomcat_log='less ~/java/tomcat/logs/catalina.out'
# cd back to the root of a git repository.
alias cdr='cd $(git rev-parse --show-toplevel)'
# git alias for when you want to use a different editor for writing the
# commit message. This is particularly useful when you do 'git commit
# -v', to see the diff when you are writing the commit message - VS Code
# will perform syntax highlighting when displaying this diff.
alias vscode_commit='GIT_EDITOR="code --new-window --wait" git commit'
# Convenience alias to make ack exclude .gitignore'd files
alias gack="git ls-files -oc --exclude-standard | ack -x"
# Works with timescale/timescaledb:2.5.0-pg13-oss
alias psql_docker='psql -h localhost -U postgres'
# VisualVM doesn't play well with https://github.com/perlun/perlun-cinnamon-theme,
# so forcing the Metal look-and-feel makes it behave more reasonably.
alias visualvm='visualvm --laf Metal'
# Random number generation. The idea with providing the lower boundaries is to
# generate random numbers of a certain "quality" in the sense that (almost) all
# numbers generated have an equal number of digits.
alias random_int32='shuf -i 1000000000-2147483647 -n 1'
alias random_int16='shuf -i 10000-65535 -n 1'
alias random_int20='shuf -i 100000-1048576 -n 1'
alias random_int8='shuf -i 1-255 -n 1'
# Redshift adjusts the color temperature of your screen, making it use a better
# color temperature when working late nights. https://packages.debian.org/redshift
alias redshift_enable='redshift -m randr -P -O 4500K'
alias redshift_disable='redshift -m randr -x'
# Useful if I forgot to start my time tracking when I get back to my desk.
alias show_logins='grep "unlocked login keyring" /var/log/auth.log'
# Workaround for bug in Xorg. Sometimes, the "use Caps Lock for switching
# keyboard map" doesn't work and sets the Caps Lock state instead. This is used
# as an emergency break, to get rid of Caps Lock in case that happens.
alias CAPSOFF='setcapslock off'
# Destroy all running LXD instances forcefully. (note: processes will not
# shutdown gracefully with this approach. Use with care!)
alias lxd_destroy_all='for e in $(lxc list -c n -f csv) ; do lxc rm -f $e ; done'
# Destroys a Vagrant machine, then recreates it (presuming the LXD provider
# should be used)
alias vagrant_recreate_lxd='vagrant destroy -f && vagrant up --provider lxd'
# Output a date in debian/changelog format
alias rfc5322_date='LANG=C date -R'
# Debian packaging-related aliases
alias dquilt="quilt --quiltrc=${HOME}/.quiltrc-dpkg"
complete -F _quilt_completion -o filenames dquilt
# Convenience alias to be able to get the Tomcat PID for use in e.g.
# 'jstack $(tomcat_pid)'
[ -x /usr/bin/pgrep ] && alias tomcat_pid='pgrep -f "org.apache.catalina.startup.Bootstrap"'
# Make it possible to do things like 'code .' on WSL
[ ! -z "$IS_WSL" ] && alias code='/mnt/c/Users/per/AppData/Local/Programs/Microsoft\ VS\ Code/Code.exe'
# Exif photo renaming, courtesy of exiftool
alias exif_rename="exiftool -fileOrder DateTimeOriginal -recurse -extension jpg -ignoreMinorErrors '-FileName<CreateDate' -d \"IMG_%Y%m%d_%H%M%S%%-c.%%e\""
# Like the 'pbcopy' alias above, but copies the given .png file to the clipboard
pbcopy_from_png() {
copyq write image/png - < $1 && copyq select 0
}
create_backup() {
DATE=$(date +%Y%m%d)
cp -a $1 $1.bak.${DATE}
}
kill_tomcat() {
$HOME/java/tomcat/bin/shutdown.sh
}
# Quirk: has to be a function so that "./gw devBuild && restart_tomcat" can work
restart_tomcat() {
kill_tomcat
sleep 1
start_tomcat
}
rotate_tomcat_log() {
mv ~/java/tomcat/logs/catalina.out ~/java/tomcat/logs/catalina-$(date +%s).out
}
# Git aliases (technically, functions)
gfa() {
git fetch --all
}
grb() {
case $1 in
''|*[!0-9]*) git rebase $1 ;;
*) git rebase -i HEAD~$1 ;;
esac
}
grbc() {
git rebase --continue
}
grbm() {
local _branches=$(git branches --remote)
if printf '%s' "$_branches" | grep -q 'upstream/main '; then
git rebase upstream/main $*
elif printf '%s' "$_branches" | grep -q 'upstream/master '; then
git rebase upstream/master $*
elif printf '%s' "$_branches" | grep -q 'origin/main '; then
git rebase origin/main $*
else
git rebase origin/master $*
fi
}
# 'git checkout master' for a particular file
gcm() {
local _branches=$(git branches --remote)
if printf '%s' "$_branches" | grep -q 'upstream/main '; then
git checkout upstream/main $*
elif printf '%s' "$_branches" | grep -q 'upstream/master '; then
git checkout upstream/master $*
elif printf '%s' "$_branches" | grep -q 'origin/main '; then
git checkout origin/main $*
else
git checkout origin/master $*
fi
}
grm() {
git rm $*
}
# Poor-man's replacement for https://github.com/jcsalterego/pngpaste
pngpaste() {
xclip -selection clipboard -t image/png -o > $1
}
prompt_save() {
export PS2=$PS1
export PS1='$ '
}
prompt_restore() {
export PS1=$PS2
export -n PS2
}
docker_container_id() {
docker ps -qf name=$1
}
docker_container_ip() {
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $1
}
docker_mysql_port() {
docker port $1 3306 | grep -v ::: | awk -F : '{ print $2 }'
}
docker_postgres_port() {
docker port $1 5432 | grep -v ::: | awk -F : '{ print $2 }'
}
docker_redis_port() {
docker port $1 6379 | grep -v ::: | awk -F : '{ print $2 }'
}
tomcat_container_id() {
docker_container_id tomcat
}
# Converts 40:b0:76:a3:36:54 to 40-B0-76-A3-36-54 format
mac_to_dashes() {
echo $1 | sed s/:/-/g | tr a-f A-F
}
# Converts 40-B0-76-A3-36-54 to 40:b0:76:a3:36:54 format
mac_to_colons() {
echo $1 | sed s/-/:/g | tr A-F a-f
}
dark_mode() {
gsettings set org.cinnamon.desktop.wm.preferences theme 'perlun-cinnamon-theme'
gsettings set org.cinnamon.desktop.interface gtk-theme 'perlun-cinnamon-theme'
gsettings set org.cinnamon.desktop.interface icon-theme 'perlun-cinnamon-theme'
gsettings set org.cinnamon.theme name 'perlun-cinnamon-theme'
}
light_mode() {
gsettings set org.cinnamon.desktop.wm.preferences theme 'Adwaita'
gsettings set org.cinnamon.desktop.interface gtk-theme 'Adwaita'
gsettings set org.cinnamon.desktop.interface icon-theme 'Adwaita'
gsettings set org.cinnamon.theme name 'Adwaita'
}
unixtime_to_string() {
date -d @$1
}
# Poor-man's replacement for SDKMAN: https://sdkman.io/
if [[ -d /usr/lib/jvm/temurin-8-jdk-amd64 ]]; then
java8() {
sudo update-alternatives --set java /usr/lib/jvm/temurin-8-jdk-amd64/bin/java
sudo update-alternatives --set javac /usr/lib/jvm/temurin-8-jdk-amd64/bin/javac
}
fi
if [[ -d /usr/lib/jvm/temurin-11-jdk-amd64 ]]; then
java11() {
sudo update-alternatives --set java /usr/lib/jvm/temurin-11-jdk-amd64/bin/java
sudo update-alternatives --set javac /usr/lib/jvm/temurin-11-jdk-amd64/bin/javac
sudo update-alternatives --set jshell /usr/lib/jvm/temurin-11-jdk-amd64/bin/jshell
}
fi
if [[ -d /usr/lib/jvm/temurin-17-jdk-amd64 ]]; then
java17() {
sudo update-alternatives --set java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java
sudo update-alternatives --set javac /usr/lib/jvm/temurin-17-jdk-amd64/bin/javac
sudo update-alternatives --set jshell /usr/lib/jvm/temurin-17-jdk-amd64/bin/jshell
}
fi
if [[ -d /usr/lib/jvm/temurin-21-jdk-amd64 ]]; then
java21() {
sudo update-alternatives --set java /usr/lib/jvm/temurin-21-jdk-amd64/bin/java
sudo update-alternatives --set javac /usr/lib/jvm/temurin-21-jdk-amd64/bin/javac
sudo update-alternatives --set jshell /usr/lib/jvm/temurin-21-jdk-amd64/bin/jshell
}
fi