-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy path.bashrc
executable file
·472 lines (402 loc) · 13.1 KB
/
.bashrc
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
# default stuff
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
#------------------------------------------------------------------------------
# custom
export IS_WORK=0
export IS_SIMPLE_FONT=0
pathadd() {
if [[ ":$PATH:" != *":$1:"* ]]; then
PATH="${PATH:+"$PATH:"}$1"
fi
}
pathadd "/home/${USER}/bin/"
# export TERM=rxvt-256color
#echo " Welcome corporate rat"
#echo " .~. "
#echo " /V\ "
#echo " // \\\\ "
#echo " /( )\ "
#echo " ^\`~'^ "
#echo
#Other
#=====
# Orange
PS1='\[\e[1;35m\]\u@\h\[\e[m\] \[\e[1;34m\]\w \[\e[1;37m\]'
if test -n "$ZSH_VERSION"; then
PS1='%F{35}%n@%m%f %F{12}%(8~|.../%7~|%~)%f '
fi
# Purple
# PS1="\[\033[38;5;215m\]\u@\h \[$(tput sgr0)\]\[\033[38;5;12m\]\w \[$(tput sgr0)\]"
# Run ssh agent only once, ignore gnome-keyring
if ! pgrep -u "$USER" -f -x "^ssh-agent$" > /dev/null; then
echo "starting ssh agent"
ssh-agent > ~/.ssh-agent-thing
eval "$(<~/.ssh-agent-thing)" /dev/null
fi
if [ -f ~/.ssh-agent-thing ]; then
eval "$(<~/.ssh-agent-thing)" > /dev/null
fi
export GOPATH=~/go ; export PATH=$PATH:$GOBIN ; export GOBIN=$GOPATH/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
alias ls="ls --color --group-directories-first"
alias l="ls -alh --group-directories-first"
alias ll="ls -lh --group-directories-first"
alias lls="ls -lh --color --group-directories-first"
alias cd..="cd .."
alias lsf="ls -al --group-directories-first | grep -i"
alias psf="ps aux -A | grep -i"
alias psmem="ps aux --sort -rss"
alias grepp="grep -Rnsi"
alias c="clear"
alias ip="ip -color=always"
alias ips="ip -color=always -br a"
alias g="git"
alias makep="prettyfier make"
alias cmakep="prettyfier cmake"
alias ninjap="prettyfier ninja"
alias go="prettyfier go"
# easy find
findfunction() {
find 2>/dev/null -L -iname "*$1*" ${@:2}
}
alias findn=findfunction
alias findbig="find ./ -type f -print0 | xargs -0 du | sort -n | tail -n 100 | cut -f2 | xargs -I{} du -sh {}"
alias findbigdir="find ./ -maxdepth 1 -type d -print0 | xargs -0 du --max-depth=1 | sort -n | tail -n 50 | tail -n +1 | cut -f2 | xargs -I{} du -sh {}"
alias sc="sudo systemctl"
alias scg="systemctl | grep -i "
alias sj="sudo journalctl"
alias sl="sudo journalctl -e"
alias sjf="sudo journalctl -f"
alias slf="sudo journalctl -f"
alias sju="sudo journalctl -e -u"
alias slu="sudo journalctl -e -u"
alias sjuf="sudo journalctl -f -u"
alias sluf="sudo journalctl -f -u"
alias sjfu="sudo journalctl -f -u"
alias slfu="sudo journalctl -f -u"
# export http_proxy="http://proxy:9400"
# export https_proxy="https://proxy:9400"
# export ftp_proxy="ftp://proxy:9400"
# export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
# same installation commands
if [ -e /etc/yum.conf ] ; then
alias ainstall="sudo yum install"
alias areinstall="sudo yum reinstall"
alias aremove="sudo yum remove"
alias asearch="sudo yum search"
alias ashow="sudo yum info"
alias alistall="sudo yum installed"
alias update="sudo yum update"
alias upgrade="sudo yum update"
fi
if [ -e /etc/pacman.conf ] ; then
alias pacman="pacman --color always"
alias ainstall="sudo pacman --color always -S"
alias areinstall="sudo pacman --color always -S"
alias aremove="sudo pacman --color always -R"
alias asearch="pacman --color always -Ss"
alias ashow="pacman --color always -Si"
alias ashowfiles="pacman --color always -Qlq"
alias ashowlocal="pacman --color always -Qi"
alias alistall="pacman --color always -Q"
alias alistallexplicit="pacman --color always -Qqe"
alias update="sudo pacman --color always -Qu"
alias upgrade="sudo pacman --color always -Syu"
alias upgradeforce="sudo pacman --color always -Syyu"
fi
if [ -d /etc/apt ] ; then
alias ainstall="sudo apt install"
alias areinstall="sudo apt install --reinstall"
alias aremove="sudo apt-get --purge remove"
alias asearch="apt search"
alias ashow="apt show"
alias alistall="apt --installed list"
alias update="sudo apt update"
alias upgrade="sudo apt upgrade"
alias uu="update && upgrade"
fi
if [ -d /mingw32 ] ; then
alias pacman="pacman --color always"
alias ainstall="pacman --color always -S"
alias areinstall="pacman --color always -S"
alias aremove="pacman --color always -RS"
alias asearch="pacsearch"
alias ashow="pacman --color always -Si"
alias ashowfiles="pacman --color always -Qlq"
alias ashowlocal="pacman --color always -Qi"
alias alistall="pacman --color always -Q"
alias update="pacman -Qu"
alias upgrade="pacman -Syyu"
fi
# git shortcuts
alias gf="git fetch"
alias gfa="git fetch --all"
alias gs="git s"
alias gg="git g"
alias git-nossl="git -c http.sslVerify=false"
# alias git-amend-now='GIT_COMMITTER_DATE="LC_ALL=en_US.utf8 date -R" git commit --amend --date "LC_ALL=en_US.utf8 date -R"'
alias git-amend-now='export YESTERDAYEVENING=$(LC_ALL=en_US.utf8 date -R) export GIT_COMMITTER_DATE="$YESTERDAYEVENING" ; git commit --date "$YESTERDAYEVENING" --amend ; export GIT_COMMITTER_DATE=""'
alias git-amend-yesterday='export YESTERDAYEVENING=$(LC_ALL=en_US.utf8 date --date="`echo $(( 18 + $RANDOM % 4 ))`:`echo $(( $RANDOM % 59))` yesterday") ; export GIT_COMMITTER_DATE="$YESTERDAYEVENING" ; git commit --date "$YESTERDAYEVENING" --amend ; export GIT_COMMITTER_DATE=""'
alias torrent="transmission-cli -w ~/torrent/ "
#dictionary search
alias look="look"
eval $(thefuck --alias)
alias f="fuck"
alias makev="make SHELL='sh -x'"
alias PI="projectInfo"
alias PIF="projectInfo fetch"
alias PIf="projectInfo fetch"
alias redshiftus="redshift -l 0.236966:-97.734886"
alias redshiftcz="redshift -l 49.194991:16.609631"
## set some other defaults ##
alias df="df -hT"
alias du='du -ch'
alias less_="less"
alias less="less -r"
alias grep='grep --color'
alias grep_="grep --color=never"
alias grep="grep --color=always"
alias ..='cd ..'
alias ...='cd ../../'
alias ....='cd ../../../'
alias .....='cd ../../../../'
alias .4='cd ../../../../'
alias .5='cd ../../../../..'
# install colordiff package :)
alias diff='colordiff'
alias dwdiff='dwdiff -c -L -C3'
#12: Show open ports
alias ports='netstat -tulanp'
#Control WebServer
alias rapache2="sudo service apache2 restart"
alias rsshd="sudo service ssh restart"
alias reveal="nautilus . &"
# for badly configured servers
alias ssh_nopubkey="ssh -o PubkeyAuthentication=no"
## pass options to free ##
alias meminfo='free -m -l -t'
## get top process eating memory
alias psmem='ps auxf | sort -nr -k 4'
alias psmem10='ps auxf | sort -nr -k 4 | head -10'
alias updateycm='cd ~/.vim/bundle/YouCompleteMe && git pull && git pull --recurse-submodules && ./install.py --clang-completer'
alias updateycmall='cd ~/.vim/bundle/YouCompleteMe && git pull && git pull --recurse-submodules && ./install.py --clang-completer --gocode-completer --tern-completer'
## get top process eating cpu ##
alias pscpu='ps auxf | sort -nr -k 3'
alias pscpu10='ps auxf | sort -nr -k 3 | head -10'
## Get server cpu info ##
alias cpuinfo='lscpu'
alias vimlog='sed -r "s/\x1B\[([0-9];)?([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" | vim -R -c "set filetype=log nowrap" -'
weather() {
curl -s wttr.in/$1
}
# nice, more readable manual! This is a must
man() {
env \
LESS_TERMCAP_mb=$'\e[01;31m' \
LESS_TERMCAP_md=$'\e[01;38;5;74m' \
LESS_TERMCAP_me=$'\e[0m' \
LESS_TERMCAP_se=$'\e[0m' \
LESS_TERMCAP_so=$'\e[46;30m' \
LESS_TERMCAP_ue=$'\e[0m' \
LESS_TERMCAP_us=$'\e[04;38;5;146m' \
man "$@"
}
# load custom promt and commands
if [ -f "$HOME/.promt" ]; then
. "$HOME/.promt"
fi
# set vi mode
# http://www.catonmat.net/blog/bash-vi-editing-mode-cheat-sheet/
set -o vi
# set color TERM
test $TERM = xterm && TERM=xterm-256color
# bind home and end to ESC+insert on ^ and $
# http://stackoverflow.com/questions/4200800/in-bash-how-do-i-bind-a-function-key-to-a-command
# http://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html
# Not needed on most system, needed on ubuntu... :(
if [ -f /etc/lsb-release ]; then
if [ $(grep Ubuntu /etc/lsb-release | wc -l) != "0" ] ; then
bind -m vi-insert '"\e[1~":"\eI"'
bind -m vi-insert '"\e[4~":"\eA"'
bind -m vi '"\e[1~":"^"'
bind -m vi '"\e[4~":"$"'
fi
fi
# page up and page down
bind -m vi '"\e[5~":"\e[A"'
bind -m vi-insert '"\e[5~":"\e[A"'
bind -m vi '"\e[6~":"\e[B"'
bind -m vi-insert '"\e[6~":"\e[B"'
fsdevice () {
SCRIPT_USER=$USER
MACHINE="NONE"
MOUNT_POINT="$HOME/device"
PORT=22
if [ $# -lt 1 ]; then
echo "fsdevice -u user -m ./mountpoint -p port machine"
fi
# shift
while [[ $# -gt 0 ]] ; do
key="$1"
# echo "#processing: $key"
case $key in
-u|--user)
SCRIPT_USER="$2"
shift # past argument
;;
-m|--mount)
MOUNT_POINT="$2"
shift # past argument
;;
-p|--port)
PORT="$2"
shift # past argument
;;
*)
MACHINE=$1
;;
esac
shift # past argument or value
done
if [ $MACHINE = "NONE" ] ; then echo "missing target machine" ; return 1 ; fi
mkdir -p $MOUNT_POINT 2>/dev/null
# echo ARGS: $MACHINE , $MOUNT_POINT , $SCRIPT_USER , $PORT
fusermount -zu $MOUNT_POINT
# sudo -E sshfs ${SCRIPT_USER}@${MACHINE}:/ -p $PORT $MOUNT_POINT -C -o allow_other \
sshfs ${MACHINE}:/ $MOUNT_POINT -C -o allow_other \
&& echo "Mounted ${SCRIPT_USER}@${MACHINE}:/ at $MOUNT_POINT"
}
fsroot () {
fsdevice -u root $*
}
tmuxf () {
cd ~/.tmux/resurrect
rm last
ln -s `ls | tail -n1` last
cd -
tmux
}
#------------------------------------------------------------------------------
# select best editor
if hash nvim 2>/dev/null; then
export EDITOR=nvim
export SUDO_EDITOR=nvim
export GIT_EDITOR=nvim
# fix Ctrl+H for neovim + tmux
infocmp $TERM | sed 's/kbs=^[hH]/kbs=\\177/' > ~/$TERM.ti ; tic ~/$TERM.ti
alias vim="nvim"
alias suvim="sudo -E nvim"
elif hash vim 2>/dev/null; then
export EDITOR=vim
export SUDO_EDITOR=vim
export GIT_EDITOR=vim
alias suvim="sudo -E vim"
else
export EDITOR=vi
export SUDO_EDITOR=vi
export GIT_EDITOR=vi
alias vim="vi"
alias suvim="sudo -E vi"
fi
#------------------------------------------------------------------------------
# FZF
# fd - cd to selected directory
fd() {
local dir
dir=$(find ${1:-.} -path '*/\.*' -prune \
-o -type d -print 2> /dev/null | fzf +m) &&
cd "$dir"
}
alias fcd="fd"
alias cdf="fd"
# locate
cf() {
local file
file="$(locate -Ai -0 $@ | grep -z -vE '~$' | fzf --read0 -0 -1)"
if [[ -n $file ]]
then
if [[ -d $file ]]
then cd -- $file else
cd -- ${file:h}
fi
fi
}
alias locatef="cf"
# Modified version where you can press
# - CTRL-O to open with `open` command,
# - CTRL-E or Enter key to open with the $EDITOR
# - anything else, cd to that file
fo() {
local out file key
IFS=$'\n' out=$(fzf --query="$1" --exit-0 --expect=ctrl-o,ctrl-e)
key=$(head -1 <<< "$out")
file=$(head -2 <<< "$out" | tail -1)
if [ -n "$file" ]; then
[ "$key" = ctrl-o ] && open "$file" || [ "$key" = ctrl-e ] && ${EDITOR:-vim} "$file" || cd -- $(dirname "$file")
fi
}
alias ff="fo"
# cd to file
fff() {
local file
file=$(fzf)
cd -- $(dirname $file)
echo $file
}
alias fdf="fff"
# fkill - kill process
fkill() {
local pid
pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}')
if [ "x$pid" != "x" ]
then
echo $pid | xargs kill -${1:-9}
fi
}
# fbr - checkout git branch
fbrl() {
local branches branch
branches=$(git branch -vv) &&
branch=$(echo "$branches" | fzf +m) &&
git checkout $(echo "$branch" | awk '{print $1}' | sed "s/.* //")
}
# fbr - checkout git branch (including remote branches)
fbr() {
local branches branch
branches=$(git branch --all | grep -v HEAD) &&
branch=$(echo "$branches" |
fzf-tmux -d $(( 2 + $(wc -l <<< "$branches") )) +m) &&
git checkout $(echo "$branch" | sed "s/.* //" | sed "s#remotes/[^/]*/##")
}
# Setup cdg function
unalias cdg 2> /dev/null
cdg() {
local dest_dir=$(cat ~/.cdg_paths | sed "/^\s*$/d" | fzf )
if [[ $dest_dir != '' ]]; then
cd "$dest_dir"
fi
}
export -f cdg > /dev/null
alias marks="mark -l"
# [ -f ~/.fzf.bash ] && export HISTCONTROL=ignoreboth:erasedups
# [ -f ~/.fzf.bash ] && export HISTCONTROL=ignoreboth
# export HISTCONTROL=ignoredups:erasedups # no duplicate entries
export HISTCONTROL=ignoredups
export HISTSIZE=10000 # big big history
export HISTFILESIZE=10000 # big big history
shopt -s histappend # append to history, don't overwrite it
# Save and reload the history after each command finishes
# export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
if [[ -f ~/.fzf.bash ]]; then
source ~/.fzf.bash
elif [ -d /usr/share/fzf ] ; then
source /usr/share/fzf/completion.bash
source /usr/share/fzf/key-bindings.bash
fi