Browse code

bashrc - v1.10 - Improve less command

Fred authored on20/04/2015 22:45:58
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.9
3
+# Version: 1.10
4 4
 # Created in: 2012-05-26
5
-# Modified in: 2014-10-18
5
+# Modified in: 2015-04-19
6 6
 
7 7
 
8 8
 
... ...
@@ -19,6 +19,7 @@
19 19
 # Versions #
20 20
 #==========#
21 21
 
22
+# v.1.10 - 2015-04-19: one archive format added to the extract function / less behaviour improved / alias updated
22 23
 # 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
23 24
 # v1.8 - 2014-10-14: HISTIGNORE correction and adding / start_agent function output improved
24 25
 # v1.7 - 2014-09-25: start_agent function improved
... ...
@@ -62,7 +63,7 @@ export HISTCONTROL=ignoreboth
62 63
 
63 64
 # Ignore some controlling instructions
64 65
 # The '&' is a special pattern which suppresses duplicate entries.
65
-export HISTIGNORE=$'[ \t]*:&:[fb]g:l[slar]:l:ll[ar]:exit:q:?q:s:ns:screen*'
66
+export HISTIGNORE=$'[ \t]*:&:[fb]g:l[slar]:l:ll[ar]:exit:q:?q:s:ns:screen -X*'
66 67
 
67 68
 # Whenever displaying the prompt, write the previous line to disk
68 69
 #export PROMPT_COMMAND="history -a"
... ...
@@ -170,13 +171,11 @@ then
170 171
     export LESS_TERMCAP_us=$'\e[01;35m'    # underlined start (if white bg: $'\e[01;32m')
171 172
 fi
172 173
 
173
-unset color_prompt
174
-
175 174
 
176 175
 # Enable color support of ls and grep and also add handy aliases
177
-if [[ -x /usr/bin/dircolors ]]
176
+if [[ -x /usr/bin/dircolors && "$color_prompt" == "yes" ]]
178 177
 then
179
-    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
178
+    [[ -r ~/.dircolors ]] && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
180 179
 
181 180
     alias ls="ls --color=auto --group-directories-first -h -C"
182 181
     alias dir="dir --color=auto"
... ...
@@ -209,15 +208,14 @@ alias lla="la -l"
209 208
 
210 209
 # File manipulations
211 210
 alias diff="diff -y --suppress-common-lines"
212
-alias less="less -R"
213 211
 
214 212
 # Internet
215 213
 alias dl="wget -c"
216 214
 alias scp="scp -pr"
217 215
 alias ssh="myssh -Y"
218
-alias wf="ssh -i $HOME/.ssh/id_main-server.dsa wf@vaderf.com"
219
-alias fwf="ssh fred@vaderf.com"
220
-alias heron="ssh fcheval@heron.txbiomedgenetics.org"
216
+alias wf="ssh wf"
217
+alias fwf="ssh fwf"
218
+alias heron="ssh heron"
221 219
 
222 220
 # Disk space
223 221
 alias df="df -h"
... ...
@@ -314,17 +312,18 @@ alias cd=cd_func
314 312
 
315 313
 # Extract function
316 314
 function extract {
317
-	if [[ -f $1 ]]
315
+	if [[ -f "$1" ]]
318 316
 	then
319 317
 		case $1 in
320
-			*.tar.bz2 | *.tbz2	) tar xvjf $1 ;;
321
-			*.tar.gz | *.tgz	) tar xvzf $1 ;;
322
-			*.tar				) tar xvf $1 ;;
323
-			*.gz				) gunzip $1 ;;
324
-			*.bz2				) bunzip2 $1 ;;
325
-			*.rar				) rar x $1 ;;
326
-			*.zip | *.7z		) unzip $1 ;;
327
-			*.Z					) uncompress $1 ;;
318
+			*.tar.bz2 | *.tbz2	) tar xvjf "$1" ;;
319
+			*.tar.gz | *.tgz	) tar xvzf "$1" ;;
320
+			*.tar				) tar xvf "$1" ;;
321
+			*.gz				) gunzip "$1" ;;
322
+			*.bz2				) bunzip2 "$1" ;;
323
+			*.rar				) rar x "$1" ;;
324
+            *.xz                ) tar xvJf "$1" ;;
325
+			*.zip | *.7z		) unzip "$1" ;;
326
+			*.Z					) uncompress "$1" ;;
328 327
 			*					) echo "don't know how to extract '$1'..." ;;
329 328
 		esac
330 329
 	else
... ...
@@ -378,12 +377,13 @@ function start_agent {
378 377
     # SSH agent environment
379 378
     echo -e "\n${msg1}"
380 379
     ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
381
-    echo -e "${msg2}\n\n"
380
+    echo -e "${msg2}\n"
382 381
     chmod 600 "${SSH_ENV}"
383 382
     source "${SSH_ENV}" > /dev/null
384 383
 
385 384
     # SSH key add ($@: useful to add ssh-add options like lifetime directly through start_agent)
386 385
     ssh-add $@ 
386
+    echo ""
387 387
 }
388 388
 
389 389
 
... ...
@@ -417,3 +417,39 @@ export R_HISTSIZE=$HISTSIZE
417 417
 # SSH environment
418 418
 export SSH_ENV="$HOME/.ssh/ssh_agent_$HOSTNAME"
419 419
 
420
+
421
+# LESS environment
422
+if [[ "$color_prompt" == yes ]]
423
+then
424
+    export LESS="-RM "
425
+
426
+    # Pretty less function
427
+    function pless {
428
+        # Pygmentize version
429
+        #pygmentize -f 256 -P style=friendly $@ | less -R
430
+
431
+        # Vim version
432
+        /usr/share/vim/vim$(vim --version | grep -o -m 1 "[[:digit:]]\.[[:digit:]]" | sed "s/\.//g")/macros/less.sh "$@"
433
+    }
434
+
435
+    # Dependency: lesspipe.sh
436
+    ## source: http://www-zeuthen.desy.de/~friebel/unix/lesspipe.html
437
+    if [[ -x $(which lesspipe.sh 2> /dev/null) ]]
438
+    then
439
+        unset LESSOPEN
440
+        #eval "$(SHELL=/bin/sh lesspipe.sh)"
441
+        export LESSOPEN="| lesspipe.sh %s 2> /dev/null" # Avoid pigmentize message when lexer not found
442
+
443
+        if [[ -x $(which pygmentize 2> /dev/null) ]]
444
+        then
445
+            export LESSCOLORIZER="pygmentize"
446
+        elif [[ -x $(which code2color 2> /dev/null) ]]
447
+        then
448
+            export LESSCOLORIZER="code2color"
449
+        fi
450
+    fi
451
+fi
452
+
453
+
454
+# Unset variables previously created
455
+unset color_prompt