Browse code

bashrc - v1.9 - Better detect terminal with color capabilities

For details, see Versions section.

Fred authored on19/10/2014 00:41:35
Showing1 changed files
... ...
@@ -1,8 +1,8 @@
1 1
 # Title: .bashrc
2 2
 # Author: Frédéric CHEVALIER <f15.chevalier@gmail.com>
3
-# Version: 1.8
3
+# Version: 1.9
4 4
 # Created in: 2012-05-26
5
-# Modified in: 2014-10-14
5
+# Modified in: 2014-10-18
6 6
 
7 7
 
8 8
 
... ...
@@ -19,6 +19,7 @@
19 19
 # Versions #
20 20
 #==========#
21 21
 
22
+# v1.9 - 2014-10-18: value of TERM variable determined by case statement => this fix 256 color terminal problem / improvement of color capability detection / alias added
22 23
 # v1.8 - 2014-10-14: HISTIGNORE correction and adding / start_agent function output improved
23 24
 # v1.7 - 2014-09-25: start_agent function improved
24 25
 # v1.6 - 2014-08-16: new history entries to ignore / screen and :q aliases
... ...
@@ -96,24 +97,48 @@ shopt -s autocd
96 97
 [[ -x /usr/bin/lesspipe ]] && eval "$(SHELL=/bin/sh lesspipe)"
97 98
 
98 99
 
100
+#--------------------#
101
+# Terminal selection #
102
+#--------------------#
103
+
104
+# To select the right terminal
105
+# (case of distant server that may not possess color capabilty for terminal)
106
+# source: http://stackoverflow.com/questions/6787734/strange-behavior-of-vim-color-inside-screen-with-256-colors
107
+case "$TERM" in
108
+    *-256color)
109
+        alias myssh="TERM=${TERM%-256color} ssh"
110
+        ;;
111
+    *)
112
+        POTENTIAL_TERM=${TERM}-256color
113
+#       POTENTIAL_TERMINFO=${TERM:0:1}/$POTENTIAL_TERM
114
+#       HOME_TERMINFO_DIR=$HOME/.terminfo
115
+
116
+        if [[ $(toe -a | cut -f 1 | grep $POTENTIAL_TERM) ]]
117
+        then
118
+            export TERM=$POTENTIAL_TERM
119
+#       elif [[ -f $HOME_TERMINFO_DIR/$POTENTIAL_TERMINFO ]]
120
+#       then
121
+#           export TERM=$POTENTIAL_TERM
122
+        fi
123
+
124
+        alias myssh="ssh"
125
+        ;;
126
+esac
127
+
128
+unset POTENTIAL_TERM BOX_TERMINFO_DIR HOME_TERMINFO_DIR
129
+
130
+
131
+
99 132
 #---------------#
100 133
 # Color options #
101 134
 #---------------#
102 135
 
103
-# Set a fancy prompt (non-color, unless we know we "want" color)
104
-force_color_prompt=yes
105
-
106
-if [ -n "$force_color_prompt" ]
136
+# Set a fancy prompt if capability present
137
+if [[ -x /usr/bin/tput && $(tput -T$TERM colors) -ge 8 ]]
107 138
 then
108
-    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null
109
-    then
110
-		# We have color support; assume it's compliant with Ecma-48
111
-		# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
112
-		# a case would tend to support setf rather than setaf.)
113
-		color_prompt=yes
114
-    else
115
-		color_prompt=
116
-    fi
139
+    color_prompt=yes
140
+else
141
+	color_prompt=
117 142
 fi
118 143
 
119 144
 if [[ "$color_prompt" == "yes" ]]
... ...
@@ -136,16 +161,16 @@ PS1="${debian_chroot:+($debian_chroot)}$PS1"
136 161
 # Enable colors for man pages (adapt colors as needed)
137 162
 if [[ "$color_prompt" == "yes" ]]
138 163
 then
139
-	export LESS_TERMCAP_mb=$'\e[01;31m'    # blink start
140
-	export LESS_TERMCAP_md=$'\e[01;33m'    # bold start (if white bg: $'\e[01;31m')
141
-	export LESS_TERMCAP_me=$'\e[0m'        # end
142
-	export LESS_TERMCAP_se=$'\e[0m'        # end
143
-	export LESS_TERMCAP_so=$'\e[01;44;33m' # status line start
144
-	export LESS_TERMCAP_ue=$'\e[0m'        # end
145
-	export LESS_TERMCAP_us=$'\e[01;35m'    # underlined start (if white bg: $'\e[01;32m')
164
+    export LESS_TERMCAP_mb=$'\e[01;31m'    # blink start
165
+    export LESS_TERMCAP_md=$'\e[01;33m'    # bold start (if white bg: $'\e[01;31m')
166
+    export LESS_TERMCAP_me=$'\e[0m'        # end
167
+    export LESS_TERMCAP_se=$'\e[0m'        # end
168
+    export LESS_TERMCAP_so=$'\e[01;44;33m' # status line start
169
+    export LESS_TERMCAP_ue=$'\e[0m'        # end
170
+    export LESS_TERMCAP_us=$'\e[01;35m'    # underlined start (if white bg: $'\e[01;32m')
146 171
 fi
147 172
 
148
-unset color_prompt force_color_prompt
173
+unset color_prompt
149 174
 
150 175
 
151 176
 # Enable color support of ls and grep and also add handy aliases
... ...
@@ -184,11 +209,12 @@ alias lla="la -l"
184 209
 
185 210
 # File manipulations
186 211
 alias diff="diff -y --suppress-common-lines"
212
+alias less="less -R"
187 213
 
188 214
 # Internet
189 215
 alias dl="wget -c"
190 216
 alias scp="scp -pr"
191
-alias ssh="ssh -Y"
217
+alias ssh="myssh -Y"
192 218
 alias wf="ssh -i $HOME/.ssh/id_main-server.dsa wf@vaderf.com"
193 219
 alias fwf="ssh fred@vaderf.com"
194 220
 alias heron="ssh fcheval@heron.txbiomedgenetics.org"