-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbashrc
More file actions
executable file
·156 lines (135 loc) · 4.78 KB
/
bashrc
File metadata and controls
executable file
·156 lines (135 loc) · 4.78 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
#!/bin/sh
# run on non-interactive logins
umask 002 # mask off world write
shopt -s checkwinsize # reassess window size between commands
shopt -s cdspell # fix 'cd folder' spelling mistakes
alias ls="BLOCK_SIZE=\'1 ls -1F --color" # enable thousands grouping
alias l='ls'
alias ll='ls -l'
alias lrt='ls -rt'
alias llrt='ls -lrt'
alias la='ls -A'
alias lla='ls -lA'
alias ..='cd ..'
alias -- -='cd -'
alias g=git
alias gs='git st'
alias gd='git di'
alias gc='git di --cached'
alias gf='git f'
function _du { [[ $# > 1 ]] && (du $@ | sort -n) || (du $@ * | sort -n); }
alias dh='_du -shc'
alias dm='_du -smc'
alias dk='_du -skc'
alias gdb='gdb --quiet'
alias hd='od -Ax -tx1z -v' # hexdump
function m { matlab -nodesktop -nosplash; }
function mdb { matlab -Dgdb; }
function unpacked { git init; git add .; git ci -m 'unpacked'; }
export GREP_OPTIONS=--color=auto
export GREP_COLOR="1;33;40" # yellow on black
alias r='stty sane'
function s { local cmd="screen -ADR $(whoami)"; [[ $# == 0 ]] && $cmd || ssh -t $@ $cmd; }
function x { local cmd="screen -Ax $(whoami)"; [[ $# == 0 ]] && $cmd || ssh -t $@ $cmd; }
function line { sed "$1q;d" $2; } # line <line> [file]
function rmline { sed -i'' -e "$1d" $2; } # rmline <line> [file]
function buffer { (test -t 1 && less -F - || cat) } # stdin to less if terminal
function tmpdir { pushd `mktemp -d -t tmpXXX`; }
function mkdircd { mkdir -p $1 && cd $1; }
function calc { echo "$@" | bc -l; } # math with floats
function e { emacsclient -t $@; }
alias unansi='sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"' # strip ansi color escape sequences
function c { cal -3 $@; }
function dos2unix { sed -i '' -e 's///g' $@; }
function gb {
fmt='%ci %h %C(yellow)%ar%C(reset)%C(green)%d%C(reset) %C(red)%an%Creset %s'
for k in `git branch -av | sed 's/^..[^ ]* *\([a-f0-9]*\) .*$/\1/'| sort -u`; do
echo `git log -1 --pretty="$fmt" $k`;
done | sort -nr | sed 's/^[^ %]* [^ ]* [^ ]* //' | buffer;
}
function matrix { tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR="1;32" grep --color "[^ ]"; }
# http://www.gnu.org/software/src-highlite/source-highlight.html#Using-source_002dhighlight-with-less
export LESS="-iFmRSX" #QR
export LESSOPEN="|lesspipe.sh %s" # special less file hooks
export LESSCLOSE=
if [[ `uname -m` == x86_64 ]]; then ARCH=64; fi
if [[ `uname` == Darwin ]]; then
alias ls='ls -1GF' # Darwin hates '--color' parameter
c() { cal $@; }
fi
# timestap history
export HISTFILE=~/.bash_history
echo "# $(date)" >>$HISTFILE
export HISTFILESIZE=1000
export HISTSIZE=1000
export HISTCONTROL=ignoreboth # Don't store duplicate adjacent items in the history
export PROMPT_COMMAND="history -a && history -r" # each cmd updates hist on disk
# 'history -r' slows down the prompt
# adapted from github.com/huyng/bashmarks
touch ~/.bookmarks
. ~/.bookmarks
function mark { # mark current directory
tmp=$(mktemp -t tmpXXX)
mv ~/.bookmarks $tmp
grep -v "export DIR_$1=" $tmp >~/.bookmarks
echo "export DIR_$1='$PWD'" >>~/.bookmarks
}
function j { # jump to bookmark
. ~/.bookmarks
cd "$(eval $(echo echo $(echo \$DIR_$1)))"
}
function list { # list bookmarks (with dirname)
. ~/.bookmarks
env | grep "^DIR_" | cut -c5- | grep -E --color "^[^=]*"
}
function _list { # list bookmarks (without dirname)
. ~/.bookmarks
env | grep "^DIR_" | cut -c5- | grep "^.*=" | cut -f1 -d "="
}
function _jump { # completion command for jump
local curw
COMPREPLY=()
curw=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=($(compgen -W '`_list`' -- $curw))
return 0
}
complete -F _jump j
shopt -s progcomp
# setup git prompt if possible (set default first)
# ${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\]
export PS1='\[\033[1G\e[33m\]\h\[\e[0m\].\[\033[32m\]\W\[\033[0m\] \$ '
[ -r ~/.git-prompt.sh ] && source ~/.git-prompt.sh
[ -r ~/.git-completion.sh ] && source ~/.git-completion.sh
export PS1='\[\033[1G\e[33m\]\h\[\e[0m\].\[\033[32m\]\W\[\033[0m\]$(__git_ps1 "{%s}") \$ '
set visual-bell none
BLOCK_SIZE='si'
# setup PATH (top of list is highest precedence)
[[ `uname` =~ CYGWIN.* ]] || PATH= # windows already set PATH
for p in \
$HOME/.bin \
/usr/local/matlab/bin \
/usr/local/bin \
/usr/local/sbin \
/opt/local/bin \
/opt/local/sbin \
/usr/bin \
/usr/sbin \
/bin \
/sbin \
/usr/X/bin \
/usr/X11R6/bin \
/usr/local/java/default/bin \
; do
[ -x $p ] && PATH=$PATH:$p
done
unset p
export PATH=${PATH##:}
export MANPATH=/usr/share/man:/usr/local/man:/opt/local/man
export INFOPATH=/usr/local/info:/usr/share/info:/opt/local/info
[ $TERM == "screen.rxvt" ] && export TERM=xterm-256color
export PAGER=less
export VISUAL='emacsclient'
export EDITOR='emacsclient'
export ALTERNATE_EDITOR=vim
export NETHACKOPTIONS # for screen fun