-
Notifications
You must be signed in to change notification settings - Fork 0
/
bashrc
120 lines (97 loc) · 2.92 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
# Universal Mercury .bashrc
# Christopher Harrison <[email protected]>
# Prevent file clobbering with redirection
set -C
# History keeping
export HISTSIZE=50000
export HISTFILESIZE=50000
export HISTCONTROL=ignoredups:erasedups
shopt -s histappend
# Proxying
export http_proxy="http://wwwcache.sanger.ac.uk:3128"
export HTTP_PROXY="${http_proxy}"
export https_proxy="${http_proxy}"
export HTTPS_PROXY="${http_proxy}"
export no_proxy=localhost,127.0.0.1,.internal.sanger.ac.uk
# Prompt
_hgi_group() {
local group="$(groups | cut -d" " -f1)"
[[ "${group}" = "hgi" ]] || printf ":%s" "${group}"
}
_hgi_abbreviate_pwd() {
local pwd="$1"
echo "${pwd}" \
| awk -v LIMIT="${HGI_ABBREVIATE_LIMIT-2}" '
BEGIN { FS = OFS = "/" }
{ fields = NF }
$1 == "" { fields-- }
LIMIT == 0 || fields <= LIMIT { print $0 }
LIMIT > 0 && fields > LIMIT {
printf("...")
for (i = NF - LIMIT; i < NF; i++)
printf("%s%s", OFS, $(i + 1))
}
'
}
export PS1='\u$(_hgi_group)@\h $(_hgi_abbreviate_pwd "\w")$ '
# Editor
export EDITOR="vim"
# Aliases
alias sort="LC_ALL=C sort"
# What user are we?
readonly HGI_USER="${SUDO_USER-${LC_HGI_USER-NONE}}"
export HGI_USER
# What farm are we on?
declare HGI_FARM="NONE"
if command -v lsclusters >/dev/null; then
HGI_FARM="$(lsclusters | awk 'NR == 2 { print $1 }')"
# Default farm environment variables
export LSB_DEFAULTGROUP="mercury-grp"
export KRB5CCNAME="$(echo ~mercury/.krb5ccache/credentials)"
fi
export HGI_FARM
# Where is the universal .bashrc?
export HGI_RC="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
# Source user, host and farm-specific RC files
_hgi_source() {
local directory="$1"
[[ -d "${directory}" ]] || return
# Prepend to PATH
[[ -d "${directory}/bin" ]] && export PATH="${directory}/bin:${PATH}"
# Source
# n.b., We duplicate stdin to FD 3 and pass that in to the source's
# stdin; this avoids the blocking of our stdin that read consumes
local _rc
exec 3<&0
while read -r _rc; do
source "${_rc}" <&3
done < <(find "${directory}/rc" -type f -o -type l 2>/dev/null | sort -n)
exec 3<&-
}
# Convenience function for sourcing user scripts
hgi-user() {
local user="$1"
_hgi_source "${HGI_RC}/user/${user}"
}
declare _RC_DIR
for _RC_DIR in \
"${HGI_RC}/farm/${HGI_FARM}" \
"${HGI_RC}/host/${HOSTNAME}" \
"${HGI_RC}/user/${HGI_USER}"
do _hgi_source "${_RC_DIR}"; done
unset _RC_DIR
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/software/hgi/installs/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/software/hgi/installs/anaconda3/etc/profile.d/conda.sh" ]; then
. "/software/hgi/installs/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/software/hgi/installs/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
export WR_CONFIG_DIR=/nfs/hgi/wr/lsf