| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,361 @@ |
| 1 |
+# Title: .bashrc |
|
| 2 |
+# Author: Frédéric CHEVALIER <f15.chevalier@gmail.com> |
|
| 3 |
+# Version: 1.0 |
|
| 4 |
+# Created in: 2014-06-22 |
|
| 5 |
+# Modified in: |
|
| 6 |
+ |
|
| 7 |
+ |
|
| 8 |
+ |
|
| 9 |
+#==========# |
|
| 10 |
+# Comments # |
|
| 11 |
+#==========# |
|
| 12 |
+ |
|
| 13 |
+# ~/.bashrc: executed by bash(1) for non-login shells. |
|
| 14 |
+# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) |
|
| 15 |
+# for examples |
|
| 16 |
+ |
|
| 17 |
+ |
|
| 18 |
+ |
|
| 19 |
+#==========# |
|
| 20 |
+# Versions # |
|
| 21 |
+#==========# |
|
| 22 |
+ |
|
| 23 |
+# v1.0: file reorganization / aliases added |
|
| 24 |
+# v0.0: creation |
|
| 25 |
+ |
|
| 26 |
+ |
|
| 27 |
+ |
|
| 28 |
+#=======================# |
|
| 29 |
+# User specific options # |
|
| 30 |
+#=======================# |
|
| 31 |
+ |
|
| 32 |
+# If not running interactively, don't do anything |
|
| 33 |
+[ -z "$PS1" ] && return |
|
| 34 |
+ |
|
| 35 |
+# Enable programmable completion features |
|
| 36 |
+if [ -f /etc/bash_completion ] && ! shopt -oq posix |
|
| 37 |
+then |
|
| 38 |
+ . /etc/bash_completion |
|
| 39 |
+fi |
|
| 40 |
+ |
|
| 41 |
+# Set variable identifying the chroot you work in (used in the prompt below) |
|
| 42 |
+if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ] |
|
| 43 |
+then |
|
| 44 |
+ debian_chroot=$(cat /etc/debian_chroot) |
|
| 45 |
+fi |
|
| 46 |
+ |
|
| 47 |
+ |
|
| 48 |
+#-----------------# |
|
| 49 |
+# History options # |
|
| 50 |
+#-----------------# |
|
| 51 |
+ |
|
| 52 |
+# Ignore duplicates and spaces |
|
| 53 |
+export HISTCONTROL=ignoreboth |
|
| 54 |
+ |
|
| 55 |
+# Ignore some controlling instructions |
|
| 56 |
+# The '&' is a special pattern which suppresses duplicate entries. |
|
| 57 |
+export HISTIGNORE=$'[ \t]*:&:[fb]g:exit' |
|
| 58 |
+# export HISTIGNORE=$'[ \t]*:&:[fb]g:exit:ls' # Ignore the ls command as well |
|
| 59 |
+ |
|
| 60 |
+# Whenever displaying the prompt, write the previous line to disk |
|
| 61 |
+#export PROMPT_COMMAND="history -a" |
|
| 62 |
+ |
|
| 63 |
+# Maximum command retain in the .bash_history file |
|
| 64 |
+export HISTSIZE=2000 |
|
| 65 |
+ |
|
| 66 |
+# Add timestamps for each command |
|
| 67 |
+export HISTTIMEFORMAT="$(echo -e '\e[0;32m')[ %d/%m/%Y %H:%M:%S ] $(echo -e '\e[0m') " |
|
| 68 |
+ |
|
| 69 |
+# Append to the history file, don't overwrite it |
|
| 70 |
+shopt -s histappend |
|
| 71 |
+ |
|
| 72 |
+# Allow edition of history command |
|
| 73 |
+shopt -s histverify |
|
| 74 |
+ |
|
| 75 |
+ |
|
| 76 |
+#---------------# |
|
| 77 |
+# Shell options # |
|
| 78 |
+#---------------# |
|
| 79 |
+ |
|
| 80 |
+# Adjust each LINES and COLUMNS after each command |
|
| 81 |
+shopt -s checkwinsize |
|
| 82 |
+ |
|
| 83 |
+# Manage typing error |
|
| 84 |
+shopt -s cdspell |
|
| 85 |
+ |
|
| 86 |
+# Avoid cd usage |
|
| 87 |
+#shopt -s autocd |
|
| 88 |
+ |
|
| 89 |
+# Make less more friendly for non-text input files, see lesspipe(1) |
|
| 90 |
+[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" |
|
| 91 |
+ |
|
| 92 |
+## Key binding |
|
| 93 |
+#bind '"\e[1~": beginning-of-line' # home |
|
| 94 |
+#bind '"\e[2~": overwrite-mode' # insert |
|
| 95 |
+#bind '"\e[3~": delete-char' # del |
|
| 96 |
+#bind '"\e[4~": end-of-line' # end |
|
| 97 |
+#bind '"\e[5~": history-search-backward' # page up |
|
| 98 |
+#bind '"\e[6~": history-search-forward' # page down |
|
| 99 |
+#bind '"\e[A": up-line-or-history' # arrow up |
|
| 100 |
+#bind '"\e[B": down-line-or-history' # arrow down |
|
| 101 |
+#bind '"\e[C": forward-char' # arrow right |
|
| 102 |
+#bind '"\e[D": backward-char' # arrow left |
|
| 103 |
+ |
|
| 104 |
+#bind '"\e[H": beginning-of-line' # home (xterm) |
|
| 105 |
+#bind '"\e[F": end-of-line' # end (xterm) |
|
| 106 |
+ |
|
| 107 |
+#bind '"^R": history-incremental-search-backward' |
|
| 108 |
+ |
|
| 109 |
+ |
|
| 110 |
+#---------------# |
|
| 111 |
+# Color options # |
|
| 112 |
+#---------------# |
|
| 113 |
+ |
|
| 114 |
+# Set a fancy prompt (non-color, unless we know we "want" color) |
|
| 115 |
+force_color_prompt=yes |
|
| 116 |
+ |
|
| 117 |
+if [ -n "$force_color_prompt" ] |
|
| 118 |
+then |
|
| 119 |
+ if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null |
|
| 120 |
+ then |
|
| 121 |
+ # We have color support; assume it's compliant with Ecma-48 |
|
| 122 |
+ # (ISO/IEC-6429). (Lack of such support is extremely rare, and such |
|
| 123 |
+ # a case would tend to support setf rather than setaf.) |
|
| 124 |
+ color_prompt=yes |
|
| 125 |
+ else |
|
| 126 |
+ color_prompt= |
|
| 127 |
+ fi |
|
| 128 |
+fi |
|
| 129 |
+ |
|
| 130 |
+if [ "$color_prompt" = yes ] |
|
| 131 |
+then |
|
| 132 |
+ if [ -n "$SSH_CONNECTION" ] |
|
| 133 |
+ then |
|
| 134 |
+ PS1='\[\e[31m\][$(date +%H:%M) \u@\e[01;35m\h\e[00;36m:\[\e[33m\]\W\[\e[31m\]]\[\e[00m\]\$ ' |
|
| 135 |
+ else |
|
| 136 |
+ PS1='\[\e[36m\][$(date +%H:%M) \u@\e[01;35m\h\e[00;36m:\[\e[33m\]\W\[\e[36m\]]\[\e[00m\]\$ ' |
|
| 137 |
+ fi |
|
| 138 |
+else |
|
| 139 |
+ PS1='[$(date +%H:%M) \u@\h:\W]\$ ' |
|
| 140 |
+fi |
|
| 141 |
+ |
|
| 142 |
+ |
|
| 143 |
+# Add chroot if present |
|
| 144 |
+PS1="${debian_chroot:+($debian_chroot)}$PS1"
|
|
| 145 |
+ |
|
| 146 |
+ |
|
| 147 |
+# Enable colors for man pages (adapt colors as needed) |
|
| 148 |
+if [ "$color_prompt" = yes ] |
|
| 149 |
+then |
|
| 150 |
+ export LESS_TERMCAP_mb=$'\e[01;31m' # blink start |
|
| 151 |
+ export LESS_TERMCAP_md=$'\e[01;33m' # bold start (if white bg: $'\e[01;31m') |
|
| 152 |
+ export LESS_TERMCAP_me=$'\e[0m' # end |
|
| 153 |
+ export LESS_TERMCAP_se=$'\e[0m' # end |
|
| 154 |
+ export LESS_TERMCAP_so=$'\e[01;44;33m' # status line start |
|
| 155 |
+ export LESS_TERMCAP_ue=$'\e[0m' # end |
|
| 156 |
+ export LESS_TERMCAP_us=$'\e[01;35m' # underlined start (if white bg: $'\e[01;32m') |
|
| 157 |
+fi |
|
| 158 |
+ |
|
| 159 |
+unset color_prompt force_color_prompt |
|
| 160 |
+ |
|
| 161 |
+ |
|
| 162 |
+# Enable color support of ls and grep and also add handy aliases |
|
| 163 |
+if [ -x /usr/bin/dircolors ] |
|
| 164 |
+then |
|
| 165 |
+ test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" |
|
| 166 |
+ |
|
| 167 |
+ alias ls='ls --color=auto --group-directories-first -h -C' |
|
| 168 |
+ alias dir='dir --color=auto' |
|
| 169 |
+ alias vdir='vdir --color=auto' |
|
| 170 |
+ |
|
| 171 |
+ alias grep='grep --color=auto' |
|
| 172 |
+ alias fgrep='fgrep --color=auto' |
|
| 173 |
+ alias egrep='egrep --color=auto' |
|
| 174 |
+ |
|
| 175 |
+ alias tree='tree -C' |
|
| 176 |
+fi |
|
| 177 |
+ |
|
| 178 |
+ |
|
| 179 |
+ |
|
| 180 |
+#=======================# |
|
| 181 |
+# User specific aliases # |
|
| 182 |
+#=======================# |
|
| 183 |
+ |
|
| 184 |
+# Listing files |
|
| 185 |
+alias l="ls" |
|
| 186 |
+alias ll="ls -l" |
|
| 187 |
+alias lr="l --recursive" |
|
| 188 |
+alias llr="ll --recursive" |
|
| 189 |
+alias la="ls -A" |
|
| 190 |
+alias lla="la -l" |
|
| 191 |
+ |
|
| 192 |
+# Moving in directories |
|
| 193 |
+alias ..='cd ..' |
|
| 194 |
+alias ....='cd ../..' |
|
| 195 |
+ |
|
| 196 |
+# Internet |
|
| 197 |
+alias dl="wget -c" |
|
| 198 |
+alias scp='scp -pr' |
|
| 199 |
+alias ssh='ssh -Y' |
|
| 200 |
+alias wf='ssh wf@vaderf.com' |
|
| 201 |
+alias wf2='ssh wf2@192.168.1.65' |
|
| 202 |
+alias fwf='ssh fred@vaderf.com' |
|
| 203 |
+alias heron='ssh fcheval@heron.txbiomedgenetics.org' |
|
| 204 |
+ |
|
| 205 |
+# Disk space |
|
| 206 |
+alias df='df -h' |
|
| 207 |
+alias du='du -h' |
|
| 208 |
+ |
|
| 209 |
+# Safety aliases |
|
| 210 |
+#alias rm="rm --interactive" |
|
| 211 |
+ |
|
| 212 |
+# Misc short aliases |
|
| 213 |
+alias c="cat" |
|
| 214 |
+alias g="grep" |
|
| 215 |
+alias h="head -15" |
|
| 216 |
+alias t="tail -15" |
|
| 217 |
+ |
|
| 218 |
+ |
|
| 219 |
+# You may want to put all your additions into a separate file like |
|
| 220 |
+# ~/.bash_aliases, instead of adding them here directly. |
|
| 221 |
+# See /usr/share/doc/bash-doc/examples in the bash-doc package. |
|
| 222 |
+ |
|
| 223 |
+if [ -f ~/.bash_aliases ] |
|
| 224 |
+then |
|
| 225 |
+ . ~/.bash_aliases |
|
| 226 |
+fi |
|
| 227 |
+ |
|
| 228 |
+ |
|
| 229 |
+#=========================# |
|
| 230 |
+# User specific functions # |
|
| 231 |
+#=========================# |
|
| 232 |
+ |
|
| 233 |
+# cd improvment function |
|
| 234 |
+# This function defines a 'cd' replacement function capable of keeping, |
|
| 235 |
+# displaying and accessing history of visited directories, up to 10 entries. |
|
| 236 |
+# To use it, try 'cd --'. |
|
| 237 |
+# acd_func 1.0.5, 10-nov-2004 |
|
| 238 |
+# Petar Marinov, http:/geocities.com/h2428, this is public domain |
|
| 239 |
+function cd_func {
|
|
| 240 |
+ local x2 the_new_dir adir index |
|
| 241 |
+ local -i cnt |
|
| 242 |
+ |
|
| 243 |
+ if [[ $1 == "--" ]] |
|
| 244 |
+ then |
|
| 245 |
+ dirs -v |
|
| 246 |
+ return 0 |
|
| 247 |
+ fi |
|
| 248 |
+ |
|
| 249 |
+ the_new_dir=$1 |
|
| 250 |
+ [[ -z $1 ]] && the_new_dir=$HOME |
|
| 251 |
+ |
|
| 252 |
+ if [[ ${the_new_dir:0:1} == '-' ]]
|
|
| 253 |
+ then |
|
| 254 |
+ # Extract dir N from dirs |
|
| 255 |
+ index=${the_new_dir:1}
|
|
| 256 |
+ [[ -z $index ]] && index=1 |
|
| 257 |
+ adir=$(dirs +$index) |
|
| 258 |
+ [[ -z $adir ]] && return 1 |
|
| 259 |
+ the_new_dir=$adir |
|
| 260 |
+ fi |
|
| 261 |
+ |
|
| 262 |
+ # '~' has to be substituted by ${HOME}
|
|
| 263 |
+ [[ ${the_new_dir:0:1} == '~' ]] && the_new_dir="${HOME}${the_new_dir:1}"
|
|
| 264 |
+ |
|
| 265 |
+ # Now change to the new dir and add to the top of the stack |
|
| 266 |
+ pushd "${the_new_dir}" > /dev/null
|
|
| 267 |
+ [[ $? -ne 0 ]] && return 1 |
|
| 268 |
+ the_new_dir=$(pwd) |
|
| 269 |
+ |
|
| 270 |
+ # Trim down everything beyond 11th entry |
|
| 271 |
+ popd -n +11 2>/dev/null 1>/dev/null |
|
| 272 |
+ |
|
| 273 |
+ # Remove any other occurence of this dir, skipping the top of the stack |
|
| 274 |
+ for ((cnt=1; cnt <= 10; cnt++)) |
|
| 275 |
+ do |
|
| 276 |
+ x2=$(dirs +${cnt} 2>/dev/null)
|
|
| 277 |
+ [[ $? -ne 0 ]] && return 0 |
|
| 278 |
+ [[ ${x2:0:1} == '~' ]] && x2="${HOME}${x2:1}"
|
|
| 279 |
+ if [[ "${x2}" == "${the_new_dir}" ]]
|
|
| 280 |
+ then |
|
| 281 |
+ popd -n +$cnt 2>/dev/null 1>/dev/null |
|
| 282 |
+ cnt=cnt-1 |
|
| 283 |
+ fi |
|
| 284 |
+ done |
|
| 285 |
+ |
|
| 286 |
+ return 0 |
|
| 287 |
+} |
|
| 288 |
+ |
|
| 289 |
+alias cd=cd_func |
|
| 290 |
+ |
|
| 291 |
+ |
|
| 292 |
+# Extract function |
|
| 293 |
+function extract {
|
|
| 294 |
+ if [[ -f $1 ]] |
|
| 295 |
+ then |
|
| 296 |
+ case $1 in |
|
| 297 |
+ *.tar.bz2 | *.tbz2 ) tar xvjf $1 ;; |
|
| 298 |
+ *.tar.gz | *.tgz ) tar xvzf $1 ;; |
|
| 299 |
+ *.tar ) tar xvf $1 ;; |
|
| 300 |
+ *.gz ) gunzip $1 ;; |
|
| 301 |
+ *.bz2 ) bunzip2 $1 ;; |
|
| 302 |
+ *.rar ) rar x $1 ;; |
|
| 303 |
+ *.zip | *.7z ) unzip $1 ;; |
|
| 304 |
+ *.Z ) uncompress $1 ;; |
|
| 305 |
+ * ) echo "don't know how to extract '$1'..." ;; |
|
| 306 |
+ esac |
|
| 307 |
+ else |
|
| 308 |
+ echo "'$1' is not a valid file!" |
|
| 309 |
+ fi |
|
| 310 |
+} |
|
| 311 |
+ |
|
| 312 |
+ |
|
| 313 |
+# Trash function |
|
| 314 |
+function trash {
|
|
| 315 |
+ # Check if trash-cli is installed otherwize check for already existing .trash |
|
| 316 |
+ if [[ $(which trash-put) ]] |
|
| 317 |
+ then |
|
| 318 |
+ alias trash='trash-put' |
|
| 319 |
+ else |
|
| 320 |
+ if [[ -d $HOME/.trash/ ]] |
|
| 321 |
+ then |
|
| 322 |
+ alias trash='mv $1 -t $HOME/.trash/' |
|
| 323 |
+ else |
|
| 324 |
+ echo -e "\n\tNo trash set up: trash-cli not installed or $HOME/.trash/ does not exist.\n" |
|
| 325 |
+ fi |
|
| 326 |
+ fi |
|
| 327 |
+} |
|
| 328 |
+ |
|
| 329 |
+ |
|
| 330 |
+# Backup function |
|
| 331 |
+function bk {
|
|
| 332 |
+ if [[ -f "$1" || -d "$1" ]] |
|
| 333 |
+ then |
|
| 334 |
+ mydate=$(date +%F) |
|
| 335 |
+ cp -R "$1" "$1.bk_$mydate" |
|
| 336 |
+ else |
|
| 337 |
+ echo -e "$1 is not a file or a directory" |
|
| 338 |
+ fi |
|
| 339 |
+} |
|
| 340 |
+ |
|
| 341 |
+ |
|
| 342 |
+ |
|
| 343 |
+#================================================# |
|
| 344 |
+# User specific environment and startup programs # |
|
| 345 |
+#================================================# |
|
| 346 |
+ |
|
| 347 |
+# Editor |
|
| 348 |
+if [[ $(which vim) ]] |
|
| 349 |
+then |
|
| 350 |
+ export EDITOR="vim" |
|
| 351 |
+else |
|
| 352 |
+ export EDITOR="nano" |
|
| 353 |
+fi |
|
| 354 |
+ |
|
| 355 |
+ |
|
| 356 |
+# Personalized PATH |
|
| 357 |
+export PATH="$HOME/.local/bin:$PATH" |
|
| 358 |
+ |
|
| 359 |
+ |
|
| 360 |
+# LaTeX environment |
|
| 361 |
+export TEXMFHOME=$HOME/.texmf |
|
| 0 | 362 |
\ No newline at end of file |