-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash_alias
More file actions
297 lines (232 loc) · 6.54 KB
/
Copy pathbash_alias
File metadata and controls
297 lines (232 loc) · 6.54 KB
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
# Bash
# --------------------------------------------------------------------
alias agl="ag -l"
alias cp="cp -v"
alias df="df -kTh"
alias du="du -hs | sort -h"
alias f="open -a Finder ./"
alias grep="grep --color=auto"
alias hosts="sudo vim /etc/hosts"
alias killall="pkill -u $USER"
alias ll="ls -lapshF --color=auto" #long list
alias lr="ls -lpR --color=auto" #recursive
alias ls="ls -pF --color=auto" #colors
alias lt="ls -lat --color=auto" #sort time
alias mkdir="mkdir -pv"
alias o="open"
alias path="echo -e ${PATH//:/\\n}"
alias ps="ps aux"
alias psg="ps aux | grep -v grep | grep -i -e VSZ -e"
alias rgl="rg -l --colors 'path:fg:green' --colors 'path:style:bold'"
alias rgi="rg --no-ignore --colors 'path:fg:green' --colors 'path:style:bold'"
alias tree="tree -Csuh" #alternative to recursive ls
## unzip everything
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
## display files in scrollable columns
lsm() {
# 34 for 2 columns
# 19 for 3 columns
ls -Fc | perl -lne 's/(.{34}).*/$1... /s ; print' | column -x | more
}
## mkdir and then enter folder
md() {
mkdir -p $1 && cd $1
}
## git mv when in repo, \mv elsewhere
mv() {
if git rev-parse --is-inside-work-tree > /dev/null 2>&1 ; then
git mv -v "$@" 2> /dev/null || $(which mv) -iv "$@"
else
$(which mv) -iv "$@"
fi
}
## source config files
re () {
source ~/.bashrc
source ~/.profile
if [ -f ~/.alias ]; then
source ~/.alias
fi
echo "sourced .rc files"
}
## git rm when in repo, \rm elsewhere
# also tar a back-up and put it in /tmp
rm() {
ARGS="$@"
# backup
while [ ! $# -eq 0 ] # while there are arguments
do
if [[ $1 != "-"* ]] ; then # if not an inline argument
BACKUP_FILE_NAME="${1%/}.tar.bz2" # create back-up file-name (breaks for dirs)
if [ -f $BACKUP_FILE_NAME ]; then # if the file exists
tar -jcf $BACKUP_FILE_NAME $1 # tar
mv -f $BACKUP_FILE_NAME /tmp > /dev/null # silently move tar to /tmp
fi
fi
shift # next argument
done
if git rev-parse --is-inside-work-tree > /dev/null 2>&1 ; then
git rm $ARGS 2> /dev/null || $(which rm) -iv $ARGS
else
$(which rm) -iv $ARGS
fi
}
# config files
# --------------------------------------------------------------------
alias abbrc='vim ~/.abbrev.vim'
alias agrc='vim ~/.agignore'
alias aliasrc='vim ~/.alias'
alias bashrc='vim ~/.bashrc'
alias eslintrc='vim ~/.eslintrc'
alias gitrc='vim ~/.gitconfig'
alias inputrc='vim ~/.inputrc'
alias maprc='vim ~/.map.vim'
alias plugrc='vim ~/.plugs.vim'
alias rgrc='vim ~/.ripgreprc'
alias sshrc='vim ~/.ssh/config'
alias stylelintrc='vim ~/.stylelintrc'
alias tmuxrc='vim ~/.tmux.conf'
alias vimrc='vim ~/.vimrc'
# env
# --------------------------------------------------------------------
alias ee="set -a; source .env; set +a"
alias ue="unset $(grep -v '^#' .env | sed -E 's/(.*)=.*/\1/' | xargs)"
# FZF & search
# --------------------------------------------------------------------
# fzf file helper
fff() {
if [ $# -eq 0 ] ; then
FILENAME=$(fzf -1 -m -i --preview 'cat {}')
else
FILENAME=$(fzf -1 -m -i --preview 'cat {}' -q $@)
fi
if [ -n "$FILENAME" ] ; then
echo $FILENAME
fi
}
# open all files containing query
vg() {
if [ ! $# -eq 0 ] ; then
vim -o $(rg -l "$@" | fzf -1 -m -i --preview "cat {} | rg -C 1 $@")
fi
}
# search and open file
vs() {
FILE=$(fff "$@")
if [ -n "$FILE" ] ; then
vim -o $FILE
fi
}
vv() {
FILE=$(fff "$@")
if [ -n "$FILE" ] ; then
vim -O $FILE
fi
}
# Java
# --------------------------------------------------------------------
jv() {
FILE=$(fff "$@")
if [ -n "$FILE" ] ; then
DIRNAME=$(dirname "${FILE}")
CLASSNAME=$(basename "${FILE}" .java)
FILE=$(basename "${FILE}")
cd $DIRNAME > /dev/null && \
javac $FILE && \
java $CLASSNAME && \
cd - > /dev/null
fi
}
# Javascript
# --------------------------------------------------------------------
alias bundlesize="npx webpack --json | npx webpack-bundle-size-analyzer"
nd() {
FILE=$(fff "$@")
if [ -n "$FILE" ] ; then
node $FILE
fi
}
# manpages
# --------------------------------------------------------------------
# add color
man() {
env LESS_TERMCAP_mb=$'\E[01;31m' \
LESS_TERMCAP_md=$'\E[01;31m' \
LESS_TERMCAP_me=$'\E[0m' \
LESS_TERMCAP_se=$'\E[0m' \
LESS_TERMCAP_so=$'\E[01;44;33m' \
LESS_TERMCAP_ue=$'\E[0m' \
LESS_TERMCAP_us=$'\E[01;32m' \
man "$@"
}
# Nethack
# --------------------------------------------------------------------
alias nethack='telnet nethack.alt.org'
# Network
# --------------------------------------------------------------------
alias myip='curl ip.appspot.com'
# show TCP unly (no UDP), and don't translate IP addrs and ports numbers to names
alias tcpports="sudo lsof -i tcp -nP"
# Python
# --------------------------------------------------------------------
alias pep8='pep8 --show-source --show-pep8 '
py() {
FILE=$(fff "$@")
if [ -n "$FILE" ] ; then
python $FILE
fi
}
# SSH keygen
# --------------------------------------------------------------------
keygen() {
ssh-keygen -t rsa -b 4096 -C "$@"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
}
# Tmux
# --------------------------------------------------------------------
alias takeover='tmux detach -a' # detach from all other session
alias share='tmux new-session -t 0'
# Typos
# --------------------------------------------------------------------
alias suod='sudo'
alias sduo='sudo'
alias vm='mv'
alias sl='ls'
alias got='git'
alias grp='grep'
# Vim
# --------------------------------------------------------------------
alias lv='vim $(ls -tp | grep -v /$ | head -1)'
alias rmswp='rm -rf ~/.vim/swap/*.swp' # delete all .swp files
alias v="vim"
alias va="vim -o" # multiple files in splits
alias vd="vim -d" # diff
# Virtualenv
# --------------------------------------------------------------------
alias virtualize='source bin/activate' # virtualenv shortcut
venv() {
if [ ! -d "venv" ] ; then
virtualenv venv
fi
source venv/bin/activate
}