This repository has been archived by the owner on Nov 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaliases
301 lines (280 loc) · 9.71 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
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#!/usr/bin/env bash
# ALIASES FILE
#
# This script is a component of ConfigCloud
# https://github.com/robertpeteuil/configcloud
#
# Robert Peteuil (c) 2018
#
aliasfilename=".aliases"
aliasfilenum="2.0.25"
aliasfiledate="2018-05-10"
#### VARS
OS=$(uname -s)
#### FUNCTIONS
check-git-installed () {
if $(git --version 2&> /dev/null); then
GIT_INST=1
else
unset GIT_INST
fi
echo -n "$GIT_INST"
}
update-repos () {
GIT_INST=$(check-git-installed)
prev_dir=$(pwd)
if [[ -e "$HOME/.configcloud/.git" ]] && [[ -n $GIT_INST ]]; then
echo -e "\n${GREEN}Updating .configcloud repo...${WHITE}"
cd "$HOME/.configcloud"; git pull; cd "$prev_dir"
GIT_UPDATE=True
fi
}
#### SET VARS
GIT_UPDATE=False
GIT_INST=$(check-git-installed)
#### SET PACKAGE MANAGER
if $(apt -h &> /dev/null); then
pkg_cmd="apt"
elif $(apt-get &> /dev/null); then
pkg_cmd="apt-get"
elif $(yum -h &> /dev/null); then
pkg_cmd="yum"
fi
update-all() {
if [[ "$pkg_cmd" == apt* ]]; then
echo -e "${GREEN}Updating via ${pkg_cmd}...${WHITE}"
sudo ${pkg_cmd} update -qq -y
echo -e "${GREEN}upgrading via ${pkg_cmd}...${WHITE}"
sudo ${pkg_cmd} upgrade -y
if [[ "$1" == "clean" ]]; then
echo -e "${GREEN}Autoclean & Autoremove...${WHITE}"
sudo apt-get autoclean -qq
sudo apt-get autoremove -qq
fi
elif [[ "$pkg_cmd" == "yum" ]]; then
echo -e "${GREEN}Updating via ${pkg_cmd}...${WHITE}"
sudo yum makecache fast
sudo yum update -y
if [[ "$1" == "clean" ]]; then
sudo yum clean packages expire-cache
fi
else
echo -e "${RED}Unknown Package Manager - Packages not updated${WHITE}"
fi
if [[ $GIT_UPDATE ]]; then
update-repos
fi
}
#### LS ALIASES
alias ls="ls --color -Fh"
alias lsa="ls -laFhv --color --group-directories-first"
alias ll='lsa'
alias lsh="ls -laFhdv --color --group-directories-first .*"
alias lsd="ls --color -laFh | grep --color=never '^d'"
alias lld='lsd'
#### DIR NAVIGATION
alias ..='cd ..'
alias ...='cd ../../'
alias ....='cd ../../../'
if [ -d "${HOME}/Versioned" ] ; then
alias cd2v="cd ${HOME}/Versioned"
fi
if [ -d "${HOME}/.configcloud" ] ; then
alias cd2cf="cd ${HOME}/.configcloud"
fi
#### DOCKER
alias d='docker'
alias d-c='docker-compose'
alias drmsc='docker rm $(docker ps -q -f 'status=exited') 2> /dev/null'
alias drmsi='docker rmi $(docker images -q -f "dangling=true") 2> /dev/null'
alias drmsv='docker volume prune -f'
alias drmsall='drmsc; drmsi; drmsv'
alias dim='docker images'
alias dima='docker images -a'
alias dps="docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'"
alias dpsa="docker ps -a --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'"
alias dpss="docker ps --format 'table {{.Names}}\t{{.Status}}'"
alias dpsi="docker ps --format 'table {{.Image}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}'"
alias dstat="docker stats --no-stream --format 'table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}'"
alias dstatn="docker stats --no-stream --format 'table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t\t{{.NetIO}}'"
alias dstatp="docker stats --no-stream --format 'table {{.Name}}\t{{.CPUPerc}}\t{{.MemPerc}}'"
alias dstat-s="docker stats --format 'table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t\t{{.NetIO}}'"
dockerip () {
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$@"
}
alias d-ip='dockerip'
dockerexec () {
[[ -z "$1" ]] && echo "specify name of container as \$1" && return 1
docker exec -it "$1" bash
}
alias dexec='dockerexec'
#### GIT
if [[ -n $GIT_INST ]]; then
# add gitconfig shortcut 'ghweb' for https://github.com/ - ex: "git clone gh:USER/REPO"
git config -f ~/.gitconfig_custom --replace-all url.https://github.com/.insteadof ghweb:
# add gitconfig shortcut 'gh' for [email protected]/ - ex: "git clone gh:USER/REPO"
git config -f ~/.gitconfig_custom --replace-all [email protected]:.insteadof gh:
# add gitconfig shortcut 'myweb' for https://github.com/$USER/ - ex: "git clone my:REPONAME"
git config -f ~/.gitconfig_custom --replace-all url.https://github.com/$USER/.insteadof myweb:
# add gitconfig shortcut 'my' for [email protected]/$USER/ - ex: "git clone my:REPONAME"
git config -f ~/.gitconfig_custom --replace-all [email protected]:$USER/.insteadof my:
fi
export GIT_MERGE_AUTOEDIT=no
alias g="git"
alias gs="git status"
alias gp="git pull"
alias gup="git up"
alias gpush="git push"
alias gcomb="git checkout master"
alias gcodb="git checkout develop"
alias ga="git add"
alias gcm="git commit -m"
alias gacmpush='git add .;git commit -m "updates";git push'
alias gremote='git remote -v'
# alias gremote='git remote get-url --all $(git remote)'
# alias grpl="git reset HEAD --hard; git pull"
alias glog='git log --pretty=format:"%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset" --date=format:"%m-%d-%Y %H:%M" --abbrev-commit'
gitaddupstream () {
[[ -z "$1" ]] && echo "specify URL or remote as param1" && return 1
git remote add upstream "$1"
git remote set-url --push upstream DISABLE
}
alias gaddupstream='gitaddupstream'
gitsyncupstream () {
if [[ -z "$1" ]]; then
echo "Syncing with Upstream requires specifying local branch as param1"
return 1
else
echo "Syncing with Upstream to branch: $1"
fi
updefined=$(git remote)
if [[ ! "$updefined" =~ upstream ]]; then
echo "Upstream Repo not Configured - use 'gitaddup' alias to add it"
return 1
else
git fetch upstream
git checkout "$1"
git merge upstream/master
git checkout -
fi
}
alias gsyncupstream='gitsyncupstream'
#### SYSTEMD
alias svc-stat='sudo systemctl status'
alias svc-status='svc-stat'
alias svc-start='sudo systemctl start'
alias svc-stop='sudo systemctl stop'
alias svc-enable='sudo systemctl enable'
alias svc-status='sudo systemctl status'
alias svc-disable='sudo systemctl disable'
alias svc-daemon='sudo systemctl daemon-reload'
alias svc-journal='sudo SYSTEMD_LESS=FRXMK journalctl -u'
alias svc-edit='sudo systemctl edit'
alias svc-editfull='sudo systemctl edit --full'
#### NETWORK
# LOCAL IP ADDRESS
alias ifconfig-lan='ifconfig | grep "inet addr:" | grep -v "127.0.0.1" | cut -d: -f2 | cut -d" " -f 1'
alias ifconfig-local='ifconfig-lan'
alias ifconfig-private='ifconfig-lan'
# IP ADDRESS - PUBLIC INTERNET
alias ifconfig-ext='curl -s ipinfo.io/ip'
alias ifconfig-pub='ifconfig-ext'
alias ifconfig-public='ifconfig-ext'
# SHOW ALL ACTIVE ETHNET CARDS & IP ADDRESS INFO
alias ifconfig-active="ifconfig -a | grep 'eth0' -A 6; ifconfig -a | grep 'wlan0' -A 6"
# NETSTAT
alias ifconfig-ports='netstat -ntlp | grep LISTEN'
#### DISK / MEMORY USAGE
# TOP TEN LARGEST FILES IN CURRENT DIRECTORY
alias ls-big='ls -1Rhs | sed -e "s/^ *//" | grep "^[0-9]" | sort -hr | head -n20'
# TOP TEN LARGEST FILES OR DIRECTORIES IN CURRENT DIR
alias big='du -ah . | sort -rh | head -20'
# TOP MEMORY USE PROCESSES
alias psmem='ps -o time,ppid,pid,nice,pcpu,pmem,user,comm -A | sort -n -k 6 | tail -15'
#### FILE OPERATIONS
# TAKE FILE OWNERSHIP
alias mychown='chown $(id -u):$(id -g)'
# DISPLAY OCTAL FILE PERMISSIONS
alias octalmode='stat -c "%a %n" '
alias getoctal='octalmode'
# MAKE DIR ANYWHERE AND TAKE OWNERSHIP
mkdirsys() {
if [[ "$2" ]]; then
grpOwner="$2"
else
grpOwner="$USER"
fi
sudo mkdir -p "$1"
sudo chown ${USER:=$(/usr/bin/id -run)}:$grpOwner $1
sudo chmod g+srwx "$1"
}
find-broken() {
eval $(dircolors)
if [[ ! "$1" ]]; then
searchDir="."
else
searchDir="$1"
fi
find -L "$searchDir" -type l -exec ls -lF --color=yes '{}' +
}
#### GENERAL ALIASES
# DISPLAY UNATTENDED UPDATE LOG
alias showuulog='cat /var/log/unattended-upgrades/unattended-upgrades.log'
alias showupdatelog='cat /var/log/unattended-upgrades/unattended-upgrades.log'
alias showrebootfiles='cat /var/run/reboot-required.pkgs'
alias showlivepatch='canonical-livepatch status --verbose'
# ENABLE SUDOING ALIASES
alias sudo='sudo '
# RELOAD SHELL (invoke as a login shell)
alias reload="exec $SHELL -l"
# OUTPUT CLARIFIERS
alias mv='mv -v'
alias rm='rm -v'
alias ln='ln -v'
alias mkdir='mkdir -p'
alias df='df -h'
alias ln='ln -v'
#### HOST SETUP AND CONFIG
# SET TIMEZONE
alias settimezone="sudo timedatectl set-timezone "
# alias settimezone="sudo dpkg-reconfigure tzdata"
# UPDATE APT-KEY
alias getaptkey-goog='curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -'
alias getaptkey-docker='curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -'
# MAKE SSH KEY
alias make-key='ssh-keygen -t rsa -b 4096'
# SEND SSH KEY
send-key-to-host() {
if [ "$1" == "-h" ]; then
echo -e "usage: send-key-to-host REMOTESERVER"
echo -e "\n\t REMOTESERVER supports 'user@host' or 'HOST'"
echo -e "\t depending on username in use on local/remot HOST"
return
fi
cat ~/.ssh/id_rsa.pub | ssh "$1" "mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys"
}
# INSTALL SYSIS
alias install-sysis='bash -c "`curl -s -L https://raw.github.com/robertpeteuil/sysis/master/install.sh`"'
# INSTALL PIP
pip-installer () {
curl -s https://bootstrap.pypa.io/get-pip.py > get-pip.py
chmod +x get-pip.py
sudo -H python get-pip.py
}
alias install-pip='pip-installer'
#### COLORIZATION
# COLOR DIR / VDIR
if $(dir --color &> /dev/null); then
alias dir='dir --color'
else
alias dir='dir -G'
fi
if $(vdir --color &> /dev/null); then
alias vdir='vdir --color'
else
alias vdir='vdir -G'
fi
# COLOR GREP
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'