-
Notifications
You must be signed in to change notification settings - Fork 0
/
.alias
166 lines (139 loc) · 4.5 KB
/
.alias
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
################################
# Change directory
################################
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
function cdp () {
# Exit current venvs, but also exits current shell
while [[ "$VIRTUAL_ENV" != "" ]]; do exit; done
cd ${1:-.}; python -m pipenv shell
}
alias pipenv="python -m pipenv"
################################
# Clear
################################
alias clr=clear
alias cls=clear
################################
# List files
################################
alias la='ls -A'
alias ls='ls -1 --color=auto --group-directories-first -X --sort=extension'
function lw () {
ls "$@" | wc
}
function ser(){
find ${2:-.} \
\( -type d -name .git -prune \) \
-o \( -type d -name "_*" -prune \) \
-o -type f -print0 | xargs -0 sed -i $1
}
################################
# Docker
################################
# Soft docker cleanup
function dc (){
local services=$(docker service ls -q)
[ -s "$services" ] && docker service rm $services
local running=$(docker ps -aq)
[ -s "$running" ] && docker stop $running
local prs=$(docker ps -a -q)
[ -s "$prs" ] && docker rm $prs
echo "Cleaned Docker"
}
# Hard docker cleanup
function dc-hard (){ \
dc();
docker network prune -f
local volumes=$(docker volume ls -q)
[ -s "$volumes" ] && docker volume rm $volumes
}
alias dl='docker service ls -q | xargs -L 1 docker service logs 2>&1 | grep -i error'
alias dils='docker image ls'
alias dcls='docker container ls'
alias dps='docker stack ps --format "table {{.Name}}\t{{.Image}}\t{{.CurrentState}}"'
alias dsls='docker service ls'
# I've had problems with containers not producing logs
# this hacky alias fixes that by removing all logs (!)
alias docker-clear-logs='sh -c "truncate -s 0 /var/lib/docker/containers/*/*-json.log"'
#################################
# Git
################################
alias ga='git add'
alias gaa='git add -A'
alias gb='git branch'
alias gbd='git branch -d'
alias gbdd='git branch -D'
alias gc='git checkout'
alias gcm='git commit -m'
alias gd='git diff'
alias gdc='git diff --cached'
alias gcb='git checkout -b'
alias gl='git log -25 --graph --pretty=format:"%C(yellow)%h - %C(green)%cn %C(reset)%s %C(blue bold)%d"'
alias gp='git push'
alias gpl='git pull'
alias gpll='git pull --prune'
alias gri='git rebase -i'
alias gs='git status --short --branch'
alias gsp='git stash pop'
alias gst='git stash'
alias gprune='git remote prune origin'
# Commit current changes into previous commit
function gca() {
if [[ "$(git log -1)" == *"Merge"* ]]; then echo "Cannot amend into merge commit"; else git commit --amend --no-edit; fi
}
# Adds autocomplete to `grefresh`.
# NB: Only works if same autocomplete already been used once
# gref <branch-to-delete> <branch-to-checkout>
function gref() {
if [ ! -z "$2" ]; then git checkout $2; else git checkout master; fi
[ ! -z "$1" ] && git branch -d $1
git pull
git remote prune origin
}
compdef __git_branch_names gref
#################################
# Misc
################################
alias size="duh -sh"
alias volume="amixer sset 'Master'"
alias wifi=nmtui
alias format="npx prettier --write --prose-wrap always"
alias format-md="npx prettier --write --prose-wrap always --parser markdown"
alias format-svg="npx prettier --write --prose-wrap always --parser html"
# alias rg="rg --color ansi"
# Extract comand because no one remembers the tar flags
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "Error: Unable to extract '$1'..." ;;
esac
else
echo "Error: '$1' is not a valid file"
fi
}
alias diff="diff --color=always"
alias R="R --no-save --quiet"
alias vi="vim --clean"
#################################
# Application specific
################################
[ -x "$(command -v helm)" ] && source <(helm completion zsh)
[ -x "$(command -v kubectl)" ] && source <(kubectl completion zsh)
[ -f ~/.dotfiles/.alias.local ] && source ~/.dotfiles/.alias.local
if [[ "$OSTYPE" == "darwin"* ]]; then
source ~/.dotfiles/.alias.mac
fi