-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaliases
308 lines (258 loc) · 6.26 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
301
302
303
304
305
306
307
308
################################################
# Aliases #
################################################
# Remember platform
platform=$(uname)
# Easy edits to bash/zsh files
alias bashrc="vim ~/.bashrc; source ~/.bashrc"
alias zshrc="vim ~/.zshrc; source ~/.zshrc"
# For BASH only
if [ -n "${BASH+set}" ]; then
alias resource="source ~/.bashrc"
fi
# For ZSH only
if [ -n "${ZSH_NAME+set}" ]; then
alias resource="source ~/.zshrc"
fi
# Easy directory traveral
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ......="cd ../../../../.."
alias .......="cd ../../../../../.."
alias ........="cd ../../../../../../.."
# tiny aliases for misc things
alias c="print '\a'; clear;"
alias e="exit"
alias v="vim"
alias cdd="cd ~/Desktop/"
alias pt="ping 8.8.8.8"
# add support for ctrl+o to open selected file in vim
export FZF_DEFAULT_OPTS="--bind='ctrl-o:execute(vim {})+abort'"
export FZF_DEFAULT_COMMAND='rg --files'
alias f="fzf --preview 'bat --color \"always\" {}'"
vimf() {
file=$(fzf --height 40%)
if [ ! -z "$file" ]; then
vim $file
fi
}
alias vf=vimf
vimr() {
if [ $# -eq 0 ]; then
read search
else
$search = $1
fi
rg $search
file=$(rg -l $search | fzf --height=40% --layout=reverse)
if [ ! -z ${file+x} ]; then
vim $file
fi
}
alias r="rg --no-heading"
# sl fun
#alias choochoo="while true; do /usr/local/opt/sl/bin/sl; done"
function python-server {
python -m SimpleHTTPServer $1
}
function php-server {
php -S localhost:8000 -t .
}
# tmux things
alias tls="tmux ls"
alias tkill="tmux kill-session -t"
tnew() {
if [ $# -eq 0 ] ; then
tmux new
else
tmux new -s $1
fi
}
tatt() {
if [ $# -eq 0 ] ; then
tmux attach
else
tmux attach -t $1 $2
fi
}
alias t="tnew"
# git things
alias gadd="git add"
alias gs="git status"
alias gc="git checkout"
alias gpull="git pull"
alias gpush="git push"
alias gd="git diff"
alias gnotrack="git update-index --assume-unchanged"
alias gtrack="git update-index --no-assume-unchanged"
alias grekt="git reset --hard HEAD"
gpr(){
remote=`git remote -v | grep origin | head -1 | awk '{print $2}' | sed 's/.*:\(.*\)*/\1/' | sed 's/\.git$//'`
branch=`git rev-parse --abbrev-ref HEAD`
open "https://github.com/$remote/compare/${1:-master}...$branch?expand=1"
}
gcom() {
git commit -am $1
}
# Grep for a match, recursively, with colors and numbers
grr() {
egrep -rni --color $1 *
}
http-post() {
curl -s -d \
$2 -H "Content-Type: application/json" \
-X POST \
$1
}
http-put() {
curl -s -d \
$2 -H "Content-Type: application/json" \
-X PUT \
$1
}
http-patch() {
curl -s -d \
$2 -H "Content-Type: application/json" \
-X patch \
$1
}
http-delete() {
curl -s \
-X DELETE \
$1
}
http-get() {
curl -s $1
}
json-post() {
curl -s -d \
$2 -H "Content-Type: application/json" \
-X POST \
$1 | jq
}
json-put() {
curl -s -d \
$2 -H "Content-Type: application/json" \
-X PUT \
$1 | jq
}
json-patch() {
curl -s -d \
$2 -H "Content-Type: application/json" \
-X patch \
$1 | jq
}
json-delete() {
curl -s \
-X DELETE \
$1 | jq
}
json-get() {
curl -s $1 | jq
}
# python venv helper
venv() {
# Deactivate if virtual env is active and return
if [ -n "${VIRTUAL_ENV+set}" ]; then
echo "Deactivating virtual env..."
deactivate
return
fi
# Default to venv dir for virtual env
V_DIR="venv"
# Argument 1 can override default dir
if [ -n "${1+set}" ]; then
V_DIR="$1"
fi
# If folder doesn't exist, make it
if [ ! -d "$V_DIR" ]; then
echo "Creating virtual env in \"$V_DIR\"..."
virtualenv "$V_DIR"
fi
# Activate the virtual env
echo "Activating virtual env..."
source "$V_DIR/bin/activate"
}
venv3() {
# Deactivate if virtual env is active and return
if [ -n "${VIRTUAL_ENV+set}" ]; then
echo "Deactivating virtual env..."
deactivate
return
fi
# Default to venv dir for virtual env
V_DIR="venv"
# Argument 1 can override default dir
if [ -n "${1+set}" ]; then
V_DIR="$1"
fi
# If folder doesn't exist, make it
if [ ! -d "$V_DIR" ]; then
echo "Creating virtual env in \"$V_DIR\"..."
virtualenv -p python3 "$V_DIR"
fi
# Activate the virtual env
echo "Activating virtual env..."
source "$V_DIR/bin/activate"
}
if [[ $platform == 'Linux' ]]; then
# Linux things
alias apt="sudo apt-get"
alias ls='ls --color=auto'
alias l='ls -lahF --color=always'
elif [[ $platform == 'Darwin' ]]; then
# OS X things
alias pb="pbpaste | pbcopy"
alias ls='ls -G'
alias l='ls -lahFG'
alias o="open"
fi
# extract a file
function extract {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
else
if [ -f $1 ] ; then
# NAME=${1%.*}
# mkdir $NAME && cd $NAME
case $1 in
*.tar.bz2) tar xvjf ./$1 ;;
*.tar.gz) tar xvzf ./$1 ;;
*.tar.xz) tar xvJf ./$1 ;;
*.lzma) unlzma ./$1 ;;
*.bz2) bunzip2 ./$1 ;;
*.rar) unrar x -ad ./$1 ;;
*.gz) gunzip ./$1 ;;
*.tar) tar xvf ./$1 ;;
*.tbz) tar xvjf ./$1 ;;
*.tbz2) tar xvjf ./$1 ;;
*.tgz) tar xvzf ./$1 ;;
*.zip) unzip ./$1 ;;
*.Z) uncompress ./$1 ;;
*.7z) 7z x ./$1 ;;
*.xz) unxz ./$1 ;;
*.exe) cabextract ./$1 ;;
*) echo "extract: '$1' - unknown archive method" ;;
esac
else
echo "$1 - file does not exist"
fi
fi
}
alias x="extract"
function docker_clean {
# remove all exited containers
if [[ -n $(docker ps -aq -f status=exited) ]]; then
docker rm $(docker ps -aq -f status=exited)
fi
# remove <none> images
if [[ -n $(docker images -q --filter "dangling=true") ]]; then
docker rmi -f $(docker images -q --filter "dangling=true")
# docker rmi $(docker images | grep "^<none>" | awk '{print $3}')
fi
}
alias dclean="docker_clean"
alias now="date -u +'%Y-%m-%d %H:%M:%SZ'"