-
Notifications
You must be signed in to change notification settings - Fork 2
/
.bashrc
202 lines (166 loc) · 5 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
# .bashrc
###############################################################################
#
# rep <num> <command>
#
# repeat the given command "num" times and break if it fails
#
rep()
{
local i
local num=$1
shift
for ((i = 0; i < num; i++))
do
echo "Step $i"
echo "Going to execute \"$*\""
bash -c "$*"
if [[ $? -ne 0 ]]; then
echo "Command failed"
break
fi
done
}
log_bash_persistent_history()
{
[[ $(history 1) =~ ^\ *[0-9]+\ +(.*+)$ ]]
local command_part="${BASH_REMATCH[1]}"
# strip trailing whitespaces
command_part=$(echo $command_part)
if [ "$command_part" != "$PERSISTENT_HISTORY_LAST" ]; then
lock_persistent_history
echo $(date) "|" "$command_part" >> $PERSISTENT_HISTORY_STORAGE
unlock_persistent_history
export PERSISTENT_HISTORY_LAST="$command_part"
fi
}
load_persistent_history()
{
local tmp=$(mktemp)
cat $PERSISTENT_HISTORY_STORAGE | cut -d"|" -f2- > $tmp
history -r $tmp
rm -f $tmp
}
lock_persistent_history()
{
while ! ln -s $PERSISTENT_HISTORY_STORAGE $PERSISTENT_HISTORY_LOCK 2>/dev/null
do
echo "Waiting for $PERSISTENT_HISTORY_LOCK"
sleep 1
done
}
unlock_persistent_history()
{
rm -f $PERSISTENT_HISTORY_LOCK
}
trim_persistent_history()
{
local tmp=$(mktemp)
lock_persistent_history $tmp
# first, remove duplicates, then trim all except for the last PERSISTENT_HISTORY_DEPTH line
cat $PERSISTENT_HISTORY_STORAGE | sort -k 2 -t "|" | uniq -f 6 | sort -k2,2M -k3,3n -k4,4 -k5,5n | tail -$PERSISTENT_HISTORY_DEPTH > $tmp
mv $tmp $PERSISTENT_HISTORY_STORAGE
unlock_persistent_history
}
###############################################################################
# Source global definitions
#if [ -f /etc/bashrc ]; then
# . /etc/bashrc
#fi
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# User specific aliases and functions
#/etc/bashrc
# System wide functions and aliases
# Environment stuff goes in /etc/profile
# by default, we want this to get set.
# Even for non-interactive, non-login shells.
if [ "`id -gn`" = "`id -un`" -a `id -u` -gt 99 ]; then
umask 002
else
umask 022
fi
PS1="[\u@\h \W]\\$ "
# are we an interactive shell?
if [ "$PS1" ]; then
case $TERM in
xterm*)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
;;
*)
;;
esac
[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
if [ -z "$loginsh" ]; then # We're not a login shell
for i in /etc/profile.d/*.sh; do
if [ -x $i ]; then
. $i
fi
done
fi
fi
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
#export TERM="screen-256color"
unset loginsh
alias ls='ls --color=auto'
alias ll='ls -alh'
alias l='ls -CF'
alias vi='vim'
alias grep='grep --color'
alias rsync='rsync -av --progress'
alias phgrep='cat $PERSISTENT_HISTORY_STORAGE | grep --color'
#[[ ! -z "$DISPLAY" ]] && xhost + &>/dev/null
#export LANG="C"
export LANG="en_US.utf8"
cgrep()
{
local patt="$1"
local path=.
[[ $# -gt 1 ]] && path="$2"
find $path -name "*.[ch]" | xargs egrep --color -n "$patt"
find $path -name "*.cc" | xargs egrep --color -n "$patt"
find $path -name "*.hh" | xargs egrep --color -n "$patt"
}
# The next line updates PATH for the Google Cloud SDK.
source /home/vladz/work/google-cloud-sdk/path.bash.inc
# The next line enables bash completion for gcloud.
source /home/vladz/work/google-cloud-sdk/completion.bash.inc
# export prompt related env for screen
export PROMPT_COMMAND
export PS1
##### EC2 shit
export AWS_ACCESS_KEY=<access key>
export AWS_SECRET_KEY=<secret key>
export AWS_ACCESS_KEY_ID=<access key>
export AWS_SECRET_ACCESS_KEY=<secret key>
export AWS_DEFAULT_REGION=us-east-1
export EC2_HOME=/usr/local/ec2/ec2-api-tools-1.6.13.0/
export PATH=$PATH:$EC2_HOME/bin:$HOME/bin
#export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64
export JAVA_HOME=$(dirname $(dirname $(dirname $(readlink /etc/alternatives/java))))
#export JAVA_OPTS="-Xms64m -Xmx128m"
#export SSH_ASKPASS=/usr/bin/ksshaskpass
#export $(dbus-launch)
export PATH=/opt/darktable/bin:$HOME/.local/bin:$PATH:/usr/lib/ccache:/opt/slickedit-pro2015/bin
if [ -f `which powerline-daemon` ]; then
powerline-daemon -q
POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
. /usr/local/lib/python2.7/dist-packages/powerline/bindings/bash/powerline.sh
fi
export PERSISTENT_HISTORY_STORAGE=$HOME/.persistent_history
export PERSISTENT_HISTORY_LOCK=/tmp/.persistent_history_lock.$USER
export PERSISTENT_HISTORY_DEPTH=20000
# avoid duplicates..
export HISTCONTROL=ignoredups:erasedups
export HISTSIZE=$PERSISTENT_HISTORY_DEPTH
export HISTFILESIZE=$PERSISTENT_HISTORY_DEPTH
trim_persistent_history
load_persistent_history
# append history entries..
shopt -s histappend
if ! echo $PROMPT_COMMAND | grep 'log_bash_persistent_history' &> /dev/null; then
export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}log_bash_persistent_history"
fi