-
Notifications
You must be signed in to change notification settings - Fork 1
/
bashrc
136 lines (118 loc) · 4.01 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
# If we want to setup belle2 right away
if [ "$SETUP_BELLE2" = "yes" ]; then
. ~/belle2/software/setup.sh
bcd
fi
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
#Make sure that there are no duplicates in path variables
#Optionally, the arguments 2 and 3 are prepended and appended respectively for
#use with append_path and prepend_path
function clean_path (){
eval OLD_PATH=\$$1
#This line is kind of long and awkward ...
NEW_PATH=`echo "$2$OLD_PATH$3" | awk -F: '{for (i=1;i<=NF;i++) { if ( !x[$i]++ ) { if(i>1) printf(":"); printf("%s",$i); }}}'`
export $1=$NEW_PATH
}
#Append value to path variable and remove duplicates
function append_path (){
clean_path $1 "" :$2
}
#Prepend value to path variable and remove duplicates
function prepend_path (){
clean_path $1 $2: ""
}
export SOFTWARE_WORK=~/work
export SOFTWARE_LOCAL=~/local
prepend_path PATH ~/.local/bin:$SOFTWARE_WORK/config/bin:$SOFTWARE_LOCAL/bin
prepend_path LD_LIBRARY_PATH $SOFTWARE_LOCAL/lib
export EDITOR=vim
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=5000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
function prompt_command () {
RETURN=$?
if [ $RETURN -ne 0 ]; then
echo -e "\nreturncode: \033[0;31m$RETURN\033[00m";
fi
return $RETURN
}
PROMPT_DIRTRIM=3
PROMPT_END='$'
PROMPT_INFO='\w'
PROMPT_USER=''
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ] || [ -n "$SSH_CONNECTION" ]; then
PROMPT_INFO="\[\e[32m\]\h\[\e[39;1;23m\]:\w"
fi
if [ $(whoami) != 'ritter' ]; then
PROMPT_USER="\u@"
fi
PS1="\[\e[1m\][$PROMPT_USER$PROMPT_INFO]\$PROMPT_END\[\e[0m\] "
case "$TERM" in
xterm*|rxvt*)
PROMPT_COMMAND="prompt_command"
PS1="\[\e]0;$PROMPT_USER\h:\w \$PROMPT_END\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# colored GCC warnings and errors
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
alias vnc='xtightvncviewer -encodings "copyrect tight hextile zlib corre rre raw"'
alias belle2=". ~/belle2/software/setup.sh"
function my_alert(){
python <<EOT
import re
from gi.repository import Notify
ret = $?
#get last command name, replacing ' with \'
cmd = '$(history 1 | sed "s/'/\\\\'/g")'
#replace the entry number at the beginning and the alert command at the end
cmd = re.sub("^\\s*\\d+\\s*|(;|&&|\\|\\|)\\s*alert\\s*$","", cmd)
#set title and icon according to return value
title = (ret==0) and "finished" or ("failed (%d)" % ret)
icon = (ret==0) and "dialog-information" or "dialog-error"
#send notification
Notify.init("alert")
n = Notify.Notification.new("Command "+ title, cmd, icon)
n.show()
EOT
}