Browse code

Bash profile (heron) improved

bash_profile (heron) - v2.2 - see Versions section for details
welcome.msg updated

Fred authored on23/04/2017 23:04:10
Showing2 changed files
... ...
@@ -1,14 +1,15 @@
1 1
 # Title: .bash_profile
2 2
 # Author: Frédéric CHEVALIER <f15.chevalier@gmail.com>
3
-# Version: 2.1
3
+# Version: 2.2
4 4
 # Created in: 2012-05-25
5
-# Modified in: 2016-07-25
5
+# Modified in: 2017-04-23
6 6
 
7 7
 
8 8
 #==========#
9 9
 # Versions #
10 10
 #==========#
11 11
 
12
+# v2.2 - 2017-04-23: server name updated / SSH connection through screen improved / welcome message improved
12 13
 # v2.1 - 2016-07-25: bug about space corrected / exit if not interactive (due to Grid Engine)
13 14
 # v2.0 - 2016-06-12: PATH setup improved / start_agent with multikey management / start_agent calling improved / screen behaviour added / welcome message improved / alias updated
14 15
 # v1.10 - 2015-08-17: Python lib adapted to the current version of Python / Consed env variable added / plocate updated to handle several db / pypm alias added / library path updated
... ...
@@ -53,7 +54,7 @@ alias plocate='locate -d "$mlocate_db"'
53 54
 alias xterm='xterm -bg black -fg white -rightbar -geometry 200x35'
54 55
 
55 56
 alias medusa='ssh medusa'
56
-alias medusa2='ssh medusa2'
57
+alias perseus='ssh perseus'
57 58
 alias mendel='ssh mendel'
58 59
 alias crow='ssh crow'
59 60
 alias bulmer='ssh bulmer'
... ...
@@ -88,14 +89,14 @@ LC_ALL=
88 89
 export PATH=$HOME/local/bin:$HOME/local/share:$HOME/local/usr/local/bin:$PATH     # Personal path
89 90
 
90 91
 # Use of personal /lib* if recent OS
91
-if [[ $HOSTNAME != heron* && $(lsb_release -r | cut -f 2) > 6.4 ]]
92
+if [[ $(lsb_release -r 2> /dev/null | cut -f 2) > 6.4 || $(grep -i "version_id" /etc/os-release 2> /dev/null | cut -d "\"" -f 2) > 6.4 ]]
92 93
 then
93 94
     # Location of bamtools lib (source: http://www.vcru.wisc.edu/simonlab/bioinformatics/programs/install/bamtools.htm)
94 95
     export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$HOME/local/lib:$HOME/local/lib64"
95 96
 fi
96 97
 
97
-# Special paths for medusa and nodes
98
-if [[ $HOSTNAME =~ medusa* || $HOSTNAME =~ compute.* ]]
98
+# Special paths for perseus, medusa and nodes
99
+if [[ $HOSTNAME =~ perseus* || $HOSTNAME =~ medusa* || $HOSTNAME =~ compute.* ]]
99 100
 then
100 101
     # System path
101 102
     export PATH=$PATH:/opt/openmpi/bin:/opt/bio/ncbi/bin:/opt/bio/mpiblast/bin:/opt/bio/hmmer/bin:/opt/bio/EMBOSS/bin:/opt/bio/clustalw/bin:/opt/bio/tcoffee/bin:/opt/bio/phylip/exe:/opt/bio/mrbayes:/opt/bio/fasta:/opt/bio/glimmer/bin:/opt/bio/glimmer/scripts:/opt/bio/gromacs/bin:/opt/bio/gmap/bin:/opt/bio/tigr/bin:/opt/bio/autodocksuite/bin:/opt/bio/wgs/bin:/opt/eclipse:/opt/ganglia/bin:/opt/ganglia/sbin:/opt/rocks/bin:/opt/rocks/sbin:/opt/condor/bin:/opt/condor/sbin:/opt/gridengine/bin/lx26-amd64:/usr/bin:/usr/local/bin:/bin:/usr/java/latest/bin
... ...
@@ -137,6 +138,17 @@ fi
137 138
 
138 139
 export R_LIBS="${R_LIBS_HOME}/${R_version}"
139 140
 
141
+
142
+# OPAM completion
143
+source $HOME/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true
144
+
145
+# Git completion
146
+[[ -s "/etc/bash_completion.d/git" ]] && source /etc/bash_completion.d/git
147
+
148
+# Biom completion
149
+[[ $(which biom &> /dev/null ; echo $?) == 0 ]] && eval "$(_BIOM_COMPLETE=source biom)"
150
+
151
+
140 152
 # SSH environment setup
141 153
 SSH_KEY_LIST="$HOME/.ssh/key_list"  # File with full path of keys (one per line) to load with start_agent
142 154
 [[ -f "$SSH_KEY_LIST" ]] && SSH_KEYS=($(cat $SSH_KEY_LIST))
... ...
@@ -165,37 +177,32 @@ fi
165 177
 
166 178
 # Display forwarding
167 179
 # dependency: proxy-dsiplay
168
-if [[ ! ($HOSTNAME =~ medusa* || $HOSTNAME =~ compute.*) && -n "$DISPLAY" && $(which proxy-display &> /dev/null; echo $?) == 0 ]]
180
+if [[ ! ($HOSTNAME =~ perseus* || $HOSTNAME =~ medusa* || $HOSTNAME =~ compute.*) && -n "$DISPLAY" && $(which proxy-display &> /dev/null; echo $?) == 0 ]]
169 181
 then
170 182
     proxy-display :99
171 183
 fi
172 184
 
173 185
 # Improvement of screen usage (prevent screen session withing screen session)
174
-if [[ -n $STY || -f /tmp/${USER}_sty.lock ]]
186
+if [[ -n $STY || -n $LC_STY ]]
175 187
 then
176
-    # Create a screen lock with level of screen
177
-    if [[ -f /tmp/${USER}_sty.lock ]]
188
+    # Create a screen variable with level of screen
189
+    if [[ -z $LC_STY ]]
178 190
     then
179
-        export LC_STY=$(($(cat /tmp/${USER}_sty.lock) + 1))
180
-    else
181 191
         export LC_STY=1
182 192
     fi
183 193
 
184 194
     # ssh function to change the behaviour of ssh
185 195
     function ssh {
186
-        /usr/bin/ssh $@ "echo $LC_STY > /tmp/${USER}_sty.lock" &&
187
-        /usr/bin/ssh -t $@ "cd \"$PWD\" && exec $SHELL -l"
196
+        /usr/bin/ssh -t $@ "export LC_STY=$(($LC_STY + 1)) && cd \"$PWD\" && exec $SHELL -l"
188 197
     }
189 198
 
190 199
     # Alias updated
191 200
     for i in $(alias | grep "screen" | cut -d " " -f 2 | cut -d "=" -f 1)
192 201
     do
193
-        eval "alias $i=\"echo You are already running in a screen session.\""
202
+        eval "alias $i=\"echo You are already in a screen session.\""
194 203
     done
195 204
 
196 205
     [[ $LC_STY -gt 1 ]] && function screen { echo -e "This would start a within screen session. This is not recommanded. But if you need it, call $(which screen)." ; }
197
-
198
-    [[ -f /tmp/${USER}_sty.lock ]] && rm /tmp/${USER}_sty.lock
199 206
 fi
200 207
 
201 208
 
... ...
@@ -210,10 +217,7 @@ nb=$(printf "%${#name}s\n" "" | sed "s/ /=/g")
210 217
 # Server message
211 218
 if [[ ! $HOSTNAME =~ compute.* && -z $STY && -z $LC_STY ]]
212 219
 then
213
-    nb=$nb=======
214
-    echo -e "\n\n"
215
-    cat .welcome.msg | sed "s/HOSTNAME/$(echo $name Server | sed "s/^[m,h]/\U&/")/" | sed "s/=\*/$nb/g"
216
-    echo -e "\n"
220
+    bash .welcome.msg
217 221
 fi
218 222
 
219 223
 # Info on disk space and cores
... ...
@@ -224,11 +228,11 @@ then
224 228
     for i in $mydisk
225 229
     do
226 230
         [[ ! $(df -h 2> /dev/null | grep "$i ") ]] && continue
227
-        echo -e "\033[33mSpace available on $i [%/Total/free]:\033[00m $(df -h 2> /dev/null | grep "$i " | awk '{print $5" / "$2" / "$4}')"
231
+        echo -e "\033[33mSpace available on $i [% Used/Total/Free]:\033[00m $(df -h 2> /dev/null | grep "$i " | awk '{print $5" / "$2" / "$4}')"
228 232
     done
229 233
     echo ""
230 234
 
231
-    if [[ ($name == "medusa" || $name == "medusa2") && (-z $LC_STY || $LC_STY != 1) ]]
235
+    if [[ ($name == "perseus" || $name == "medusa2") && (-z $LC_STY || $LC_STY != 1) ]]
232 236
     then
233 237
         echo -e "\033[33mCores available:\033[00m\n"
234 238
         qstat -g c
... ...
@@ -1,23 +1,37 @@
1
-  P. ::.::::i:i:i:i:i:::LF  .O@v  
2
-  iBriLZXFqG0ZNEEGZOZGNPr  7B@i   
3
-   :@BG57               i0@BL     
4
-     7B@Mkr;vkEZ2r. .LO@BN:       
5
-       ,XB@XLvJ,.:5M@M5:          
6
-          :PMM0SL77v              
7
-        .:Lk0jivq0PY7i:.          
8
-     .7O@@BFi. .:vq@B@BMkLi.      
9
-   ,rO@PX5uukP0qX2Uu11SFOBMF2r         ===================*=========
10
-  ujBO                   .uMN8@i 
11
-  @G@G5B@B@B@B@B@@@B@B@@@G0B@8OB.              Welcome on HOSTNAME
12
-  8@qMX,                    .EN@L 
13
-   Y@Mk7. ,:i:iirirrr;rirr:  2@B       ===================*=========
14
-     LM@MXJ2q@OGZOMBMMOMNr:7O@E   
15
-       .UM@ZUr:         .Y@Bq,    
16
-           rkMO82v:, ,LGMS:       
17
-               ikG8ESv;r:         
18
-             .:72EP7L0q1YJ7i.     
19
-          iuOM@B@Ek2SqMB@MME1JL   
20
-       :L0Eu,              iFS2@7 
21
-    .rG@@M5vYUSkPSXkXkXSX1JruMPU@.
22
-  :iFBY7rrrLvLvYLLLLvYvYLLLLiLUJ@:
23
- r1FB                        .7PP 
1
+#!/bin/bash
2
+
3
+name="${HOSTNAME%%.*}"
4
+#nb=$(printf "%${#name}s\n" "" | sed "s/ /=/g")
5
+nb=$(echo $name | sed "s/./=/g")
6
+
7
+myuptime=$(uptime | sed "s/  */ /g ; s/,/\\n/g" | sed -n "1p" | sed "s/.*up //g" |sed -r "s/([0-9]*)/\\\e[1;92m\1\\\e[0m/g")
8
+myusers=$(uptime | sed "s/  */ /g ; s/,/\\n/g" | sed "s/^ *//g" | sed -n "2p" | sed -r "s/([0-9]*)/\\\e[1;92m\1\\\e[0m/g")
9
+myOS=$(lsb_release -d 2> /dev/null | sed "s/  */\\t/g" | cut -f 2-| sed "s/\\t/ /g")
10
+[[ -z "$myOS" ]] && myOS=$(grep "PRETTY_NAME=" /etc/os-release 2> /dev/null | cut -d "\"" -f 2)
11
+
12
+
13
+echo -e "
14
+  P. ::.::::i:i:i:i:i:::LF  .O@v  
15
+  iBriLZXFqG0ZNEEGZOZGNPr  7B@i   
16
+   :@BG57               i0@BL     
17
+     7B@Mkr;vkEZ2r. .LO@BN:       
18
+       ,XB@XLvJ,.:5M@M5:          
19
+          :PMM0SL77v              
20
+        .:Lk0jivq0PY7idd:.        
21
+     .7O@@BFi. .:vq@B@BMkjp.     
22
+   ,rOO                   MF2r         ===================${nb}=========
23
+  ujBO@PX5uukP0qX2Uu11SFO.uMN8@i 
24
+  @G@G5B@B@B@B@B@@@B@B@@@G0B@8OB.              Welcome on \e[1;35m$name\e[0m
25
+  8@qMX,                    .EN@L 
26
+   Y@Mk7. ,:i:iirirrr;rirr:  2@B       ===================${nb}=========
27
+     LM@MXJ2q@OGZOMBMMOMNr:7O@E   
28
+       .UM@ZUr:         .Y@Bq,    
29
+           rkMO82v:, ,LGMS:                 \e[36mUptime\e[0m: $myuptime 
30
+               ikG8ESv;r:                    \e[36mUsers\e[0m: $myusers
31
+             .:72EP7L0q1YJ7i.                   \e[36mOS\e[0m: $myOS 
32
+          iuOM@B@Ek2SqMB@MME1JL   
33
+       :L0Eu,              iFS2@7 
34
+    .rG@@M5vYUSkPSXkXkXSX1JruMPU@.
35
+  :iFBY7rrrLvLvYLLLLvYvYLLLLiLUJ@:
36
+ r1FB                        .7PP
37
+"