-
Notifications
You must be signed in to change notification settings - Fork 0
/
.aliases
226 lines (203 loc) · 6.9 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/usr/bin/env bash
# Collection of aliases and bash functions
# Utilties for dotfile versioning
#----------------------------
# Alias for .dotfile repository, see README
alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
# Checkout/ Update all Git submodules (e.g. Vim Plugins, ...)
alias configsub='config submodule init && cat .gitmodules | grep -Eo "\"(.)*\"" | cut -d "\"" -f 2 | xargs -I{} /usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME submodule update --remote {}'
# Search alias ir function in .aliases
function finda() { grep --no-filename -i -a1 "$@" ~/.aliases | grep -v '^\s*$' ; }
# Portable open
if [[ "$(uname)" == "Darwin" ]]; then
generic_open='open'
elif [[ "$(uname)" == "Linux" ]]; then
generic_open='xdg-open'
fi
# Terminal
#----------------------------
# Change directory and list content
function lcd() { cd "$1" && ls; }
# Create directory and enter it
function mcd() { mkdir -p "$1" && cd "$1" || return; }
if [[ "$(uname)" == "Darwin" ]]; then
colorflag=' -GFh';
elif [[ "$(uname)" == "Linux" ]]; then
colorflag=' --color=auto';
fi
# Ls
alias ls="ls $colorflag"
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Grep
if grep --color=auto "a" ~/.aliases &> /dev/null; then
alias grep='grep --color=auto'
fi
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
# If NeoVim is available prefer NeoVim over Vim
if type nvim > /dev/null 2>&1; then
alias vim=nvim
fi
# Shorthand for find
function f() { find . -name "$1" 2>&1 | grep -v 'Permission denied'; }
# Grep ps
function psa() { ps aux | grep "$1"; }
# List and sort folders by size
alias fbysize='du -h -a --max-depth=1 | sort -h'
# grep history
function hist() { history | grep "$1"; }
# Gradle
#----------------------------
# Gradle wrapper
alias gw='./gradlew'
# Gradlew wrapper clean build
alias gwcb='./gradlew clean build'
# Gradle dependency insight
function gwdi() { ./gradlew dependencyInsight --configuration "${2:-compileClasspath}" --dependency "$1"; }
# Generate HTML dependency report and open it
function gwhdr() { ./gradlew htmldependencyReport; $generic_open build/reports/project/dependencies/index.html; }
# Git
#----------------------------
# Show outgoing changes, inspired by Mercurials hgout
alias gout='git log --pretty=oneline --abbrev-commit --graph @{u}.. --stat'
# Show incoming changes
alias gin='git log --pretty=oneline --abbrev-commit ..@{u} --stat'
# Jump back to to the last branch
alias gback='git checkout -'
# Undo commit
alias gundo='git reset HEAD~'
# Git status
alias gs='git status'
# Git branch
alias gb='git branch -vv'
# Git diff
alias gd='git diff'
# Git diff last commit
alias gdl='git diff --cached HEAD^'
# Git push
alias gph='git push'
# Git pull
alias gpl='git pull'
# Git commit
alias gcm='git commit -m'
# Remove all local branches which remote equivalent is gone
function gprune() { git fetch -p && git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -d; }
alias g='git'
# Git checkout
alias gc='git checkout'
# Git show history of specific file
function ghist() { git log -p -- "$1"; }
# Git fetch
alias gf='git fetch'
# Git commit with "NO-TICKET:" as prefix in commit message
function gcmn() { git commit -m "NO-TICKET: $1"; }
# git add all
alias gaa='git add .'
# git add
alias ga='git add'
# git merge
alias gm='git merge'
# git log with graph
alias gl='git log --graph --decorate --all --stat'
# show last commit
alias glast='git show HEAD~1'
# git number of commits per author on all branches
alias gstat='git shortlog -s -n --all --no-merges'
# Docker
#----------------------------
# Docker
alias d='docker'
# list all running containers
alias dps="docker ps --format 'table {{.ID}}\t{{.Names}}\t{{.Image}}\t{{.Ports}}\t{{.Status}}'"
# list all running and stopped containers
alias dpsa="docker ps -a --format 'table {{.ID}}\t{{.Names}}\t{{.Image}}\t{{.Ports}}\t{{.Status}}'"
# list all images
alias di='docker images'
# docker build
alias db='docker build .'
# stop all containers
function dstop() { docker stop $(docker ps -q); }
# remove all containers
function drm() { docker rm -f -v $(docker ps -a -q); }
# remove all images
function drmi() { docker rmi -f $(docker images -q); }
# remove all dangeling volumes
function drmv() { docker volume rm $(docker volume ls -q -f dangling=true); }
# Docker Compose
#----------------------------
# Short docker-compose
alias doc='docker-compose'
# Kubernetes
#----------------------------
# Shorter
alias k='kubectl'
alias kgp='kubectl get pods'
# Change namespace
function kcns() { kubectl config set-context $(kubectl config current-context) --namespace=$1; }
# Print current namespace
alias kns='kubectl config view | grep namespace:'
alias kcd='kubectl config set-context $(kubectl config current-context) --namespace '
# Maven
#----------------------------
# Maven clean install
alias mci='mvn clean install'
# Maven dependency tree
alias mdep='mvn dependency:tree'
# Ansible
#----------------------------
alias ap='ansible-playbook'
# Network
#----------------------------
# list all IPs
if [[ "$(uname)" == "Darwin" ]]; then
function ip() { ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}'; }
elif [[ "$(uname)" == "Linux" ]]; then
alias ip='hostname -I'
fi
# Get Wan IP
alias wanip='dig +short myip.opendns.com @resolver1.opendns.com'
# Comes back when online
function online() { while true; do wanip > /dev/null 2>&1; if [ $? -eq 0 ]; then echo "online :)"; break; fi; echo "offline..."; sleep 10; done; }
# serve current directory via http
if type python3 > /dev/null 2>&1; then
function serve() { python3 -m http.server; }
fi
# tmux
#----------------------------
# start tmux with 4 panes
function t() {
tmux new-session -s "${1:-default}"\; \
split-window -v \; \
split-window -h \; \
select-pane -t 0 \; \
split-window -h \; \
select-pane -t 0 \;
}
# tmux attach to sessionf
function ta() { tmux attach -t "$1"; }
# tmux list session
alias tl='tmux ls'
# systemd
function dlog() { journalctl -b -a -f -n 30 -u "$1"; }
# SDK man
#----------------------------
if type sdk > /dev/null 2>&1; then
alias usejava8='sdk use java 8.0.312-zulu'
alias usejava11='sdk use java 11.0.2-open'
alias usejava17='sdk use java 17.0.1-open'
alias usejava21='sdk use java 21.0.1-open'
fi
# Show description of HTTP Status Code
function httpc() { sed -n -e '/^'$1'/p' ~/.lib/http_codes.csv | sed -e $'s/;/\\\n/g' | fold -w 81; }
# Create random password
function pw() { cat /dev/urandom | env LC_CTYPE=C tr -dc _ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjklmnpqrstuvwxyz23456789- | head -c 16; echo; }
# Short clear
alias c=clear
function smonitor() { echo "Remember: Type ~. to quit. "; sudo cu -l /dev/cu.SLAB_USBtoUART -s 115200; }
# Create high CPU load, e.g. for 8 processors call "cpumeld 8"
function cpumeld() { for c in {1..$1}; do yes > /dev/null & done; }
function cpumeldstop() { killall yes; }
# Decode jwt token
function jwt() { jq -R 'split(".") | .[1] | @base64d | fromjson' <<< "$1"; }