forked from lawrencesystems/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_aliases
202 lines (151 loc) · 5.64 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
######################################
# TIP: SEE TABLE in ~/.bash_profile
######################################
#alias tmux='tmux -2'
alias less='less -R'
alias diff='colordiff'
alias _='sudo'
alias fixmykey='sudo chmod 600 ~/.ssh/id_rsa'
alias yarn='yarnpkg'
# IP addresses
alias homeip="dig +short home.paulsturm.net"
alias localip="ip -4 addr show | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | grep -v '127.0.0.1'"
# Easier updates
update() {
echo "Starting full system update..."
sudo apt update -qq
sudo dist-upgrade -yy
sudo apt-get autoremove -yy
echo "Update complete"
return
}
# easier than man pages...
cheatsh() {
curl cheat.sh/"$1"
}
# random 12 character passwords
alias randompass='cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 12 | head'
# Easier navigation: .., ..., ...., ....., ~ and -
alias ..='cd ..'
alias ...='cd ../..'
alias .3='cd ../../..'
alias .4='cd ../../../..'
alias .5='cd ../../../../..'
alias ~='cd ~'
alias -- -='cd -'
alias 1='cd -'
alias 2='cd -2'
alias 3='cd -3'
alias 4='cd -4'
alias 5='cd -5'
# logins
alias session_opened='grep "session opened for user" /var/log/auth.log'
alias publickey_accepted='grep "Accepted publickey" /var/log/auth.log'
alias password_accepted='grep "Accepted password" /var/log/auth.log'
alias password_failed='grep "Failed password" /var/log/auth.log'
# easy lists
alias ls='ls -lha --color=auto --group-directories-first'
alias grep='grep --color=auto'
# storage
# remaining storage
alias storage="df -h / --output=avail | tail -1 | xargs echo | sed 's/G/ GB/g'"
alias df='df -H'
alias du='du -ch'
# nano
alias nano='nano -l'
alias reboot='sudo reboot'
# One of @janmoesen’s ProTip™s
for method in GET HEAD POST PUT DELETE TRACE OPTIONS; do
# shellcheck disable=SC2139,SC2140
alias "$method"="lwp-request -m \"$method\""
done
# vhosts
alias hosts='sudo nano /etc/hosts'
# copy working directory
alias cwd='pwd | tr -d "\r\n" | xclip -selection clipboard'
# Basically, lets me know what just happened
# --interactive prompt before overwrite
# --verbose explain what is being done
alias cp="cp --interactive --verbose"
alias mv="mv --interactive --verbose"
alias rm="rm --verbose"
# make dir path
alias mkdir='mkdir -pv'
# Pretty print the path
alias path="echo $PATH | tr -s ':' '\n'"
# untar
alias untar='tar xvf'
# Pipe my public key to my clipboard.
alias pubkey="more ~/.ssh/id_rsa.pub | xclip -selection clipboard | echo '=> Public key copied to pasteboard.'"
# Pipe my private key to my clipboard.
alias prikey="more ~/.ssh/id_rsa | xclip -selection clipboard | echo '=> Private key copied to pasteboard.'"
alias timer='echo "Timer started. Stop with Ctrl-D." && date "+%a, %d %b %H:%M:%S" && time cat && date "+%a, %d %b %H:%M:%S"'
alias fdir='find . -type d -name'
alias ff='find . -type f -name'
# ------------------------------------
# Git alias and function
# ------------------------------------
# Go to the root of a project (git root)
alias root='cd $(git rev-parse --show-cdup)'
alias gitundo='git reset --hard && git clean -fd'
alias gs='git status'
alias glog='git log --oneline --graph --color --all --decorate'
# To avoid .git index corruption and preserve UTF-8 BOM
# Touches only those files (-ic0 option), that contain windows line breaks, all other files are skipped
alias fixlineendings='find . -type f -print0 | xargs -0 dos2unix -ic0 | xargs -0 dos2unix -b'
# ------------------------------------
# Docker alias and function
# ------------------------------------
# Get latest container ID
alias dl="docker ps -l -q"
# Get container process
alias dps="docker ps"
# Get process included stop container
alias dpa="docker ps -a"
# Get images
alias di="docker images"
# Get container IP
alias dip="docker inspect --format '{{ .NetworkSettings.IPAddress }}'"
# Run deamonized container, e.g., $dkd base /bin/echo hello
alias dkd="docker run -d -P"
# Run interactive container, e.g., $dki base /bin/bash
alias dki="docker run -i -t -P"
# Execute interactive container, e.g., $dex base /bin/bash
alias dex="docker exec -i -t"
# Stop all containers
dstop() { docker stop $(docker ps -a -q); }
# Remove all containers
drm() { docker rm $(docker ps -a -q); }
# Stop and Remove all containers
alias drmf='docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q)'
# Remove all images
dri() { docker rmi $(docker images -q); }
# Dockerfile build, e.g., $dbu tcnksm/test
dbu() { docker build -t=$1 .; }
# Show all alias related docker
dalias() { alias | grep 'docker' | sed "s/^\([^=]*\)=\(.*\)/\1 => \2/"| sed "s/['|\']//g" | sort; }
# Bash into running container
dbash() { docker exec -it $(docker ps -aqf "name=$1") bash; }
alias pgdb="cd ~/projects/trunk"
alias lucee="cd ~/projects/pgdb-lucee"
alias grepcontent='grep -rni'
# >$ recent_mods . 10
# finds the 10 most recently modified files in the current directory
function recent_mods () { find "${1:-.}" -type f -printf '%TY-%Tm-%Td %TH:%TM %P\n' 2>/dev/null | sort | tail -n "${2:-10}"; }
# remove the need to sudo for WordOps operations
alias wo='sudo -E wo'
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# Get External IP / Internet Speed
alias myip="curl https://ipinfo.io/json" # or /ip for plain-text ip
alias speedtest="curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python -"
# work changes
alias st='/mnt/c/Program\ Files\ \(x86\)/Atlassian/Sourcetree/SourceTree.exe'