-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_alias
229 lines (190 loc) · 4.88 KB
/
.bash_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
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
#!/bin/bash
# HELP
function cs() {
curl "cheat.sh/$1"
}
export -f cs
#############
# Git
#############
alias gs="git status"
alias gcm="git commit -m"
alias gl="git log --oneline --decorate --color"
alias glh="git log --all --graph --decorate --oneline"
alias gst="git stash -u"
alias gust="git restore --staged ."
alias gb="git branch"
alias gc="git checkout"
alias gdiff="git diff"
alias grh="git reset --hard HEAD"
alias gaa='git add .'
alias gaaa='git add -A'
alias gi='git init'
alias gp='git pull'
alias gpsh='git push'
alias gss='git status -s'
function gitcr() {
if [ -z "$1" ]; then
echo -e "\n==> Repo location not supplied\n"
exit 1
fi
for i in {1..10}; do
# brew install coreutils
timeout 5 git clone "$1"
if [ $? -eq 0 ]; then
break
fi
echo -e "\n==> timeout... ${i} retry"
done
}
export -f gitcr
#############
# Node
#############
# TODO nvm
# TODO nrm npm registry manager
alias rmnm="rm -r ./node_modules/"
alias ns='npm start'
alias start='npm start'
alias nr='npm run'
alias run='npm run'
alias ni="npm install"
alias cni="cnpm install"
alias nis='npm i -S'
alias nreload="rm -rf node_modules/ package-lock.json && npm install"
alias ns="kill -9 $(lsof -ti:3000,3001) && npm start"
#############
# Pip
#############
alias pip="pip3"
alias python="python3"
alias pipf="pip3 freeze > requirements.txt"
#############
# Common
#############
alias mkdir='mkdir -v'
alias mv='mv -v'
alias cp='cp -v'
alias rm='rm -v' # rm -i
alias rmnm='rm -rf node_modules > /dev/null'
alias ln='ln -v'
alias type='type -a' # type -a ls
# NAVIGATION
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
# SHORTCUT
alias reload="source ~/.bash_profile"
alias _="sudo"
alias rr="rm -rf"
alias hosts="sudo $EDITOR /etc/hosts"
alias quit="exit"
alias l="ls -la"
alias path="echo -e ${PATH//:/\\n}"
alias ~="cd ~"
alias cddev="cd ~/dev"
alias cdbin="cd ~/bin"
alias cddot="cd ~/dotfiles"
#alias checkdot="~/dotfiles/check.sh"
alias cdnote="cd ~/confluence"
alias cdblog="cd ~/shxo"
alias blog="cd ~/shxo && hexo clean && hexo g && hexo s"
alias note="cd ~/confluence && npm run docs:dev"
alias e?='echo $?'
alias vi='vim'
# Always enable colored `grep` output
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias a='code .'
alias reveal-md="reveal-md --theme night --highlight-theme hybrid --port 1337"
alias o="open ." # Open the current directory in Finder
function ccat() {
local style="monokai"
if [ $# -eq 0 ]; then
pygmentize -P style=$style -P tabsize=4 -f terminal256 -g
else
# shellcheck disable=SC2068
for NAME in $@; do
pygmentize -P style=$style -P tabsize=4 -f terminal256 -g "$NAME"
done
fi
}
function 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 "don't know how to extract '$1'..." ;;
esac
else
echo "'$1' is not a valid file!"
fi
}
# Create a new directory and enter it
function mkd() {
mkdir -p "$@" && cd "$_";
}
function mkcd() {
mkdir $1 && cd $1
}
# `o` with no arguments opens the current directory,
# otherwise opens the given location.
function o() {
if [ $# -eq 0 ]; then
open .;
else
open "$@";
fi;
}
# Intuitive map function
# For example, to list all directories that contain a certain file:
# find . -name .gitattributes | map dirname
alias map="xargs -n1"
# Process
alias pbyport='netstat -vanp tcp | grep'
alias killbyport=''
alias rmjobs='kill -9 $(jobs -p)'
#############
# Hexo
#############
alias hs="hexo clean && hexo g && hexo s"
##################
# HTTP Proxy
##################
alias vpn-enable="export http_proxy='http:https://localhost:8010' && curl cip.cc"
alias vpn-disable="unset http_proxy && curl cip.cc"
alias vpn-status="curl cip.cc"
alias whereami='curl cip.cc'
alias pubip='curl ifconfig.cc; echo'
alias pingg="ping www.google.com"
alias pingb="ping www.baidu.com"
####################################################################
# Color
####################################################################
bldgrn='\e[1;32m' # Bold Green
bldpur='\e[1;35m' # Bold Purple
txtrst='\e[0m' # Text Reset
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
function red {
printf "${RED}$@${NC}\n"
}
function green {
printf "${GREEN}$@${NC}\n"
}
function yellow {
printf "${YELLOW}$@${NC}\n"
}