MY BASH CONFIGURATION FILES


1. MAIN FILE

This is my main bash configuration file (.bashrc):


#!/bin/bash
#******************************************************************************
#*
#*                  MY GLORIOUS BASH CONFIGURATION FILE
#*
#******************************************************************************


  #--------------------------------------------------------------------------
  #                        I. SYSTEM VARIABLES
  #--------------------------------------------------------------------------

# 1) Main Directories
#====================

# a. Work directories
#---------------------
if [ $HOSTNAME == sappcw100 ] ; then
    export work=/usr/data/
    export data=/mnt/data/
    export settings=~/ownCloud/Settings/
    export swingloc=$work/SwING/
elif [ $HOSTNAME == dappcw173 ] || [ $HOSTNAME == dappcw173.extra.cea.fr ] \
      || [ $HOSTNAME == dappcz161 ] || [ $HOSTNAME == dappcz161.extra.cea.fr ]; \
    then
    export work=$HOME
    export data=/mnt/data/
    export settings=~/ownCloud/Settings/
    export swingloc=$work/SwING/
elif [ $HOSTNAME == Birdland ] ; then
    export work=$HOME
    export data=/mnt/data/
    export data=/mnt/backup/
    export settings=~/ownCloud/Settings/
    export swingloc=$work/SwING/
elif [ $HOSTNAME == iclust ] || [ $HOSTNAME == iclustgate.extra.cea.fr ] \
      || [ $HOSTNAME == hubble.extra.cea.fr ] ; then
    export work=/dsm/herschel1/nuages/
    export work1=/dsm/herschel10/nuages/Fred/
    export work2=/dsm/manip2/nuages/Fred/
    export work3=/dsm/herschel1/nuages/Fred/
    export data=$work1
    export settings=~/Settings/
    export swingloc=$work/Codes/SwING/
elif [ ${HOSTNAME:0:7} == feynman ] ; then
    export work=$WORK
    export data=$work
    export settings=/feynman/home/dap/lfemi/xxxxxxxx/Settings/
    export swingloc=$work/SwING/
fi
export astro=$work/Astro/
export f90=$swingloc/Fortran/
export f90ex=$f90/Programs/
export modtemp=$swingloc/Model_templates/
export idlib=$swingloc/IDL/
export pyt=$swingloc/Python/
export pytex=$pyt/Programs/
export SWINGLIBDIR=$swingloc
export SWINGTMPDIR=$SWINGLIBDIR/Model_templates/


# b. PATH
#--------
export PATH=".:$PATH"
export PATH="$PATH:$f90ex"
export PATH="$PATH:$pytex"
export PATH="$PATH:/usr/local/hdf5/bin/"
export PATH="$PATH:$HOME/.cask/bin/"
export PATH="$PATH:$settings"
export PATH="$PATH:$HOME/bin/"


# 2) Applications
#================

# a. LaTeX library
#-----------------
export dirtex=$HOME/ownCloud/TeXstyle/
export tex=$dirtex:$dirtex/Packages_AandA
export TEXINPUTS=".:$tex:"$TEXINPUTS
export BSTINPUTS=".:$tex:"$BSTINPUTS
export BIBINPUTS=".:$tex:"$BIBINPUTS


# b. Python library
#------------------
export PYTHONPATH=".:$pyt/Graphics/:$pyt/Math/:$pyt/Science/:$pyt/Utilities/" 
export PYTHONPATH=$PYTHONPATH":$pyt/Borrowed/"
export PYTHONSTARTUP=$pyt/startup.py


# c. IDL
#-------
LD_LIBRARY_PATH=/usr/local/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/itt/idl/bin/bin.linux.x86_64
export LD_LIBRARY_PATH


# 3) System
#==========
umask 0022

# a. Variables
#-------------
export LC_TIME='fr_FR.UTF-8'
export LC_ALL='fr_FR.UTF-8'


# b. Default printer
#-------------------
export PRINTER='sapcolp1_Bat-709-piece-207'


# 3) Output
#==========
# If the mode is not interactive, we exit, otherwise it makes scp and rsync 
# crachs.
case $- in
    *i*) ;;
      *) return;;
esac


  #--------------------------------------------------------------------------
  #                       II. TERMINAL APPEARANCE
  #--------------------------------------------------------------------------

# 1) LS Colors
#=============
# cf. http://www.bigsoft.co.uk/blog/2008/04/11/configuring-ls_colors
export colgeneral='di=1;4;97;44:ln=1;4;100:ex=1;31:fi=0;37'


# a. Archives, etc.
#------------------
export car='=1;34'
export colarchive='*.tar'$car':*.tgz'$car':*.arc'$car':*.arj'$car':*.taz'$car 
export colarchive=$colarchive':*.lha'$car':*.lz4'$car':*.lzh'$car':*.lzma'$car
export colarchive=$colarchive':*.tlz'$car':*.txz'$car':*.tzo'$car':*.t7z'$car
export colarchive=$colarchive':*.zip'$car':*.z'$car':*.Z'$car':*.dz'$car
export colarchive=$colarchive':*.gz'$car':*.lrz'$car':*.lz'$car':*.lzo'$car
export colarchive=$colarchive':*.xz'$car':*.bz2'$car':*.bz'$car':*.tbz'$car
export colarchive=$colarchive':*.tbz2'$car':*.tz'$car':*.a'$car


# b. Images, films, etc.
#-----------------------
export cim='=1;35'
export colimage=':*.jpg'$cim':*.jpeg'$cim':*.JPG'$cim':*.gif'$cim
export colimage=$colimage':*.bmp'$cim':*.pbm'$cim':*.pgm'$cim':*.ppm'$cim
export colimage=$colimage':*.tga'$cim':*.xbm'$cim':*.xpm'$cim':*.tif'$cim
export colimage=$colimage':*.tiff'$cim':*.png'$cim':*.svg'$cim':*.svgz'$cim
export colimage=$colimage':*.mng'$cim':*.pcx'$cim':*.mov'$cim':*.mpg'$cim
export colimage=$colimage':*.mpeg'$cim':*.m2v'$cim':*.mkv'$cim':*.webm'$cim
export colimage=$colimage':*.ogm'$cim':*.mp4'$cim':*.m4v'$cim':*.mp4v'$cim
export colimage=$colimage':*.vob'$cim':*.qt'$cim':*.nuv'$cim':*.wmv'$cim
export colimage=$colimage':*.asf'$cim':*.rm'$cim':*.rmvb'$cim':*.flc'$cim
export colimage=$colimage':*.avi'$cim':*.fli'$cim':*.flv'$cim':*.gl'$cim
export colimage=$colimage':*.dl'$cim':*.xcf'$cim':*.xwd'$cim':*.yuv'$cim
export colimage=$colimage':*.cgm'$cim':*.emf'$cim':*.ogv'$cim':*.ogx'$cim
export colimage=$colimage':*.aac'$cim':*.au'$cim':*.flac'$cim':*.m4a'$cim
export colimage=$colimage':*.mid'$cim':*.midi'$cim':*.mka'$cim':*.mp3'$cim
export colimage=$colimage':*.mpc'$cim':*.ogg'$cim':*.ra'$cim':*.wav'$cim 
export colimage=$colimage':*.oga'$cim':*.opus'$cim':*.spx'$cim':*.xspf'$cim
export colimage=$colimage':*.wbmp'$cim


# c. All types of data
#----------------------
export cda='=1;33'
export coldata='*.h5'$cda':*.fits'$cda':*.csv'$cda':*.xls'$cda':*.xlsx'$cda
export coldata=$coldata':*.bib'$cda':*.ics'$cda':*.dat'$cda':*.xdr'$cda
export coldata=$coldata':*.xml'$cda':*.shelf'$cda':*.ods'$cda


# d. Codes
#---------
export cco='=1;97'
export colcode='*.f90'$cco':*.f'$cco':*.pro'$cco':*.py'$cco':*.sh'$cco':*.c'$cco
export colcode=$colcode':*.el'$cco':*.mk'$cco':*makefile'$cco':*.pbs'$cco
export colcode=$colcode':*.tpl'$cco':*.css'$cco':*.pmx'$cco':*.ly'$cco
export colcode=$colcode':*.cfg'$cco


# e. Text edition
#-----------------
export cte='=1;32'
export coltext='*.org'$cte':*.tex'$cte':*.txt'$cte':*.odt'$cte':*.odp'$cte
export coltext=$coltext':*.doc'$cte':*.docx'$cte':*.ppt'$cte':*.pptx'$cte
export coltext=$coltext':*.rtf'$cte':*.utf'$cte':*.asc'$cte':*.lytex'$cte


# f. Documents
#-------------
export cdo='=1;36'
export coldoc='*.pdf'$cdo':*.eps'$cdo':*.md'$cdo':*.html'$cdo':*.php'$cdo


# g. Miscellaneous
#-----------------
export cot='=1;93'
export colother='*.sty'$cot':*.cls'$cot':*.bst'$cot


# h. Particular cases we don't want to color
#-------------------------------------------
export cop='=0;37'
export colpartic='*.synctex.gz'$cop':*.o'$cop':*.mod'$cop


# i. Export
#----------
export LS_COLORS=$colarchive':'$colimage':'$coldata':'$colcode':'$coltext
export LS_COLORS=$LS_COLORS':'$coldoc':'$colother':'$colpartic':'$colgeneral


# 2) Prompt
#==========
# My own ANSI colors and formatting functions
source $settings/pretty_bash.sh

# Prompt format
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

# All colors must be between "\[" and "\]" in order to avoid bugs with lines
# longer than the page width
PS1="\["$lightyellow"\]┌─ "
PS1=$PS1"\["$reset$bold$lightmagenta"\][\D{%a %d %b, %R}]\["$reset"\]"
PS1=$PS1"\["$lightyellow"\]\n├"
PS1=$PS1"$(eval printf %.0s─ '{2..'"${COLUMNS:-$(tput cols)}"\}; echo)"
PS1=$PS1"\n├─ \["$bold$lightcyan"\]\u\["$default"\]@\["$lightyellow"\]\h" 
PS1=$PS1"\["$default"\]:\["$bold$lightgreen"\]\w\n\["$lightyellow"\]└─ "
PS1=$PS1"\["$reset$bold$lightred"\]["$SHELL"]\$\["$reset"\] "
PROMPT_DIRTRIM=4


# 3) XTERM
#=========
# No duplicata or lines starting with a blank in the history
HISTCONTROL=ignoreboth

# Do not overwrite history
shopt -s histappend

# Size of history
HISTSIZE=1000
HISTFILESIZE=2000

# Check the window size
shopt -s checkwinsize


  #--------------------------------------------------------------------------
  #                          III. ALIAS AND MACROS
  #--------------------------------------------------------------------------

# 1) Managing Directories
#========================

# a. Basic aliases
#-----------------
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias l='ls -osFh'
alias h=$settings'ls.sh'
alias la='ls -oAsh'
alias lr='ls -osFhR'
alias ..='cd ..'


# b. Shortcuts to frequent directories
#-------------------------------------
# Most frequently used directory
# Each alias can be used without argument: cda gets you to ~/Astro.
# It can also be used with an argument (directory or file within ~/Astro) and
# autocompletion will work

# Astro
cda() { 
    if [ -z "$1" ] ; then
        cd $HOME/Astro
    else
        cd $HOME/Astro/$1
    fi
        }
_cda_()
{
    local CDA_DIR=$HOME/Astro
    local cmd=$1 cur=$2 pre=$3
    local arr i file
    arr=( $( cd "$CDA_DIR" && compgen -f -- "$cur" ) )
    COMPREPLY=()
    for ((i = 0; i < ${#arr[@]}; ++i)); do
        file=${arr[i]}
        if [[ -d $CDA_DIR/$file ]]; then
            file=$file/
        fi
        COMPREPLY[i]=$file
    done
}
complete -F _cda_ -o nospace cda

# Documents
cdd() { 
    if [ -z "$1" ] ; then
        cd $HOME/Documents
    else
        cd $HOME/Documents/$1
    fi
        }
_cdd_()
{
    local CDD_DIR=$HOME/Documents
    local cmd=$1 cur=$2 pre=$3
    local arr i file
    arr=( $( cd "$CDD_DIR" && compgen -f -- "$cur" ) )
    COMPREPLY=()
    for ((i = 0; i < ${#arr[@]}; ++i)); do
        file=${arr[i]}
        if [[ -d $CDD_DIR/$file ]]; then
            file=$file/
        fi
        COMPREPLY[i]=$file
    done
}
complete -F _cdd_ -o nospace cdd

# Fortran
cdf() { 
    if [ -z "$1" ] ; then
        cd $f90
    else
        cd $f90/$1
    fi
        }
_cdf_()
{
    local CDF_DIR=$f90
    local cmd=$1 cur=$2 pre=$3
    local arr i file
    arr=( $( cd "$CDF_DIR" && compgen -f -- "$cur" ) )
    COMPREPLY=()
    for ((i = 0; i < ${#arr[@]}; ++i)); do
        file=${arr[i]}
        if [[ -d $CDF_DIR/$file ]]; then
            file=$file/
        fi
        COMPREPLY[i]=$file
    done
}
complete -F _cdf_ -o nospace cdf

# owncloud
cdo() { 
    if [ -z "$1" ] ; then
        cd $HOME/ownCloud
    else
        cd $HOME/ownCloud/$1
    fi
        }
_cdo_()
{
    local CDO_DIR=$HOME/ownCloud
    local cmd=$1 cur=$2 pre=$3
    local arr i file
    arr=( $( cd "$CDO_DIR" && compgen -f -- "$cur" ) )
    COMPREPLY=()
    for ((i = 0; i < ${#arr[@]}; ++i)); do
        file=${arr[i]}
        if [[ -d $CDO_DIR/$file ]]; then
            file=$file/
        fi
        COMPREPLY[i]=$file
    done
}
complete -F _cdo_ -o nospace cdo

# Python
cdp() { 
    if [ -z "$1" ] ; then
        cd $pyt
    else
        cd $pyt/$1
    fi
        }
_cdp_()
{
    local CDP_DIR=$pyt
    local cmd=$1 cur=$2 pre=$3
    local arr i file
    arr=( $( cd "$CDP_DIR" && compgen -f -- "$cur" ) )
    COMPREPLY=()
    for ((i = 0; i < ${#arr[@]}; ++i)); do
        file=${arr[i]}
        if [[ -d $CDP_DIR/$file ]]; then
            file=$file/
        fi
        COMPREPLY[i]=$file
    done
}
complete -F _cdp_ -o nospace cdp

# Downloads
cdt() { 
    if [ -z "$1" ] ; then
        cd $HOME/Downloads
    else
        cd $HOME/Downloads/$1
    fi
        }
_cdt_()
{
    local CDT_DIR=$HOME/Downloads
    local cmd=$1 cur=$2 pre=$3
    local arr i file
    arr=( $( cd "$CDT_DIR" && compgen -f -- "$cur" ) )
    COMPREPLY=()
    for ((i = 0; i < ${#arr[@]}; ++i)); do
        file=${arr[i]}
        if [[ -d $CDT_DIR/$file ]]; then
            file=$file/
        fi
        COMPREPLY[i]=$file
    done
}
complete -F _cdt_ -o nospace cdt


# c. Creates a directory in $1 and link it in the current directory
#------------------------------------------------------------------
# For instance:
#  - cd ~/New_place
#  - mkln ~/Real_data/Pipo 
# will create directory ~/New_place/Pipo symbolically linked to ~/Real_data/Pipo
mkln() { ln -s $1 ; }


# d. Clean-up file names
#-----------------------
# Replace whites and other special characters in all files of the current 
# directory
unspace() { find -maxdepth 1 -name "* *" | rename 's/ /_/g'
            find -maxdepth 1 -name "*,*" | rename 's/,/_/g'
            find -maxdepth 1 -name "*'*" | rename "s/'/_/g"
            find -maxdepth 1 -name "*[*" | rename 's/\[/_/g'
            find -maxdepth 1 -name "*]*" | rename 's/\]/_/g'
            find -maxdepth 1 -name "*(*" | rename 's/\(/_/g'
            find -maxdepth 1 -name "*)*" | rename 's/\)/_/g' ; }


# e. Archive a directory
#-----------------------
mktar() { tar -czvf $1.tar.gz $1 ; }


# f. Clean-up
#------------
alias ex='exit'
alias rrm='rm *~ .*~'
uselessext='*.aux *.dvi *.log *.mx? *.out *.toc *.synctex.gz *.bbl *.blg '
uselessext=$uselessext'*.nav *.snm'
alias larm='rm '$uselessext
alias frm='rm *.o *.mod *.out'
alias rmpyc='rm '$pytlib'*/__pycache__/*.pyc'


# h. Other
#---------
# Open the HDR
alias hdr='okular ${astro}/HDR/Manuscript/hdr.pdf &> /dev/null &'

# Open a scrap file to take notes
alias scratch='emacs ~/Downloads/scratch.org &> /dev/null &'

# Debugging
echocou() { 
    if [ -z "$1" ] ; then
        echo "Coucou"; 
    else
        echo "Coucou" $1
    fi
           }
export -f echocou


# 2) Script execution
#=====================
# Shell script banner
export colban=$yellow$bold
export colbban=$bblue
if [ $HOSTNAME == sappcw100 ]; then
    export pad="            "
else
    export pad="      "
fi
scriptbanner () {
    echo
    printf "${colbban}${colban}"
    printf "${emptyline}\n"
    center "${1}"
    printf "${emptyline}${reset}\n" 
    echo ; }
export -f scriptbanner

# Displaying info in shell scripts
export colinfo=$green$bold
scriptinfo () {
    printf "${colinfo}${1}${reset}\n" ; }
export -f scriptinfo

# Highlighting file names in info
export colfil=$blue$bold
scriptfile () {
    printf "${colfil}${1}${colinfo}\n" ; }
export -f scriptfile

# Displaying warnings in shell scripts
export colwarn=$red$bold
scriptwarning () {
    printf "$blink${colwarn}${1}${reset}\n" ; }
export -f scriptwarning


# a. Mount different volumes
#---------------------------
# USB key containing the GPG directories
dirpkey=/media/$USER/Privkey
mpkey_nosudo () { 
  mount -t ext4 --uuid 8ef196c3-6afb-49d2-9324-b9d756775a47 $dirpkey
  chown -R $USER $dirpkey; } 
alias mpkey="sudo bash -c '$(declare -f mpkey_nosudo); mpkey_nosudo'"
alias umpkey="sudo umount $dirpkey"

# External back-up black disk
export mountopt='-t ntfs -o dmask=027,fmask=137,uid='$USER # reformat as ext4
export volback='/dev/sda1'  # <= use UUID!...
export dirback='/media/'$USER'/Mingus/'
alias mback='sudo mount '$mountopt' '$volback' '$dirback
alias umback='sudo umount '$volback


# b. Synchronizing
#-----------------
alias ralias=$settings'bashrc.sh'
alias syncal='~/ownCloud/Organisation/cron_script.sh'
alias backup=$settings"general_backup.sh -d"


# c. Compiling
#-------------
sla () {
  scriptbanner "    SILENT PDFLaTeX COMPILING OF FILE $1" 
  : | pdflatex -halt-on-error $1 | grep '^!.*' -A200 --color=always
}
lab () { 
  scriptbanner "    COMPILING (PDFLaTeX and BibTeX) FILE $1" 
  pdflatex $1
  bibtex $1
  edit_bbl.py --TeXfile $1
  pdflatex $1
  pdflatex $1
  pdflatex $1 ; }
luab () { 
  scriptbanner "    COMPILING (LuaLaTeX and BibTeX) FILE $1" 
  lualatex $1
  bibtex $1
  edit_bbl.py --TeXfile $1
  lualatex $1
  lualatex $1
  lualatex $1 ; }
lam () { 
  scriptbanner "    COMPILING (MusixTeX) FILE $1" 
  rm -f *.mx*
  lualatex $1
  musixflx $1
  lualatex $1
  lualatex $1 ; }
compf () { 
  scriptbanner "             COMPILING THE WHOLE FORTRAN LIBRARY" 
  if [ $HOSTNAME != iclust ] && [ $HOSTNAME != iclustgate.extra.cea.fr ] \
       && [ $HOSTNAME != hubble.extra.cea.fr ] \
       && [ ${HOSTNAME:0:7} != feynman ] ; then 
      cd $f90ex
      make
      cd -
  else
      if [ -e $HOME/make.out ] ; then
          rm -f $HOME/make.out
      fi
      sbatch $HOME/make_SwING_SLURM.sh
  fi
  echo ; }
mkr () { make $1 
         $1 ; }
compswing () {
  scriptbanner "             COMPILING WITH THE SWING LIBRAY" 
  h5fc -Wall -O3 $1.f90 -o $1 -lswing -L${f90ex} -I${f90ex} ; }


# d. Update on Iclust
#--------------------
# Detect if we are on the CEA network or if we need to go through hubble
netw=$(nslookup -name $HOSTNAME | grep "cea.fr")
if [ ${#netw} == 0 ] ; then
    export atclust=xxxxxxxx@hubble.extra.cea.fr
    export atclust2=xxxxxxxx@hubble.extra.cea.fr
    export atfeyn=xxxxxxxx@hubble.extra.cea.fr
else
    export atclust=xxxxxxxx@hubble
    export atclust2=xxxxxxxx@iclust
    export atfeyn=xxxxxxxx@feynman.extra.cea.fr
fi
export swingclu=/dsm/herschel1/nuages/Codes/SwING/
export swingfeyn=/feynman/work/dap/lfemi/xxxxxxxx/SwING

# Update the main $HOME settings
setclust () { 
  scriptbanner "UPDATING $HOME ON THE OLD CLUSTER" 
  # On the old /dsm
  rsync -e ssh -avuh ~/.bash_profile $atclust:/home/xxxxxxxx/.bash_profile
  rsync -e ssh -avuh $settings/bashrc.sh \
    $atclust:/home/xxxxxxxx/.bashrc
  rsync -e ssh -avuh $settings/Clust/make_SwING*.sh \
    $atclust:/home/xxxxxxxx/
  rsync -e ssh -avuh ~/.vim* $atclust:/home/xxxxxxxx
  rsync -e ssh -avuh --delete ~/.emacs.d/ $atclust:/home/xxxxxxxx/.emacs.d
  rsync -e ssh -avuh --delete $settings $atclust:/home/xxxxxxxx/Settings
  rsync -e ssh -avuh --delete $dirtex $atclust:/home/xxxxxxxx/TeXstyle
  rsync -e ssh -avuh --delete ~/ownCloud/Manuals/ \
    $atclust:/home/xxxxxxxx/Manuals ; 
  scriptbanner "UPDATING $HOME ON FEYNMAN" 
  # On the new feynman
  rsync -e ssh -avuh ~/.bash_profile \
        $atfeyn:/feynman/home/dap/lfemi/xxxxxxxx/.bash_profile
  rsync -e ssh -avuh $settings/bashrc.sh \
    $atfeyn:/feynman/home/dap/lfemi/xxxxxxxx/.bashrc
  rsync -e ssh -avuh $settings/Clust/make_SwING*.sh \
    $atfeyn:/feynman/home/dap/lfemi/xxxxxxxx/
  rsync -e ssh -avuh ~/.vim* $atfeyn:/feynman/home/dap/lfemi/xxxxxxxx/
  rsync -e ssh -avuh --delete ~/.emacs.d/ \
    $atfeyn:/feynman/home/dap/lfemi/xxxxxxxx/.emacs.d
  rsync -e ssh -avuh --delete $settings \
    $atfeyn:/feynman/home/dap/lfemi/xxxxxxxx/Settings
  rsync -e ssh -avuh --delete $dirtex \
    $atfeyn:/feynman/home/dap/lfemi/xxxxxxxx/TeXstyle
  rsync -e ssh -avuh --delete ~/ownCloud/Manuals/ \
    $atfeyn:/feynman/home/dap/lfemi/xxxxxxxx/Manuals ; }

# Update the SwING library
swing2clust () { 
  # scriptbanner "UPDATING THE SwING LIBRARY ON THE OLD CLUSTER" 
  # rsync -e ssh -avuh --delete --exclude *.o --exclude *.mod --exclude .git \
  #     $swingloc $atclust:$swingclu
  scriptbanner "UPDATING THE SwING LIBRARY ON FEYNMAN" 
  rsync -e ssh -avuh --delete --exclude *.o --exclude *.mod --exclude .git \
        $swingloc $atfeyn:$swingfeyn ; }

# Update the model templates from the cluster
modtemp2here () { 
  scriptbanner "UPDATING THE LOCAL MODEL TEMPLATES FROM THE CLUSTER" 
  rsync -e ssh -avuh --delete --exclude .git \
        $atfeyn:$swingfeyn/Model_templates/ $modtemp ; }


# e. Mount the cluster directories
#---------------------------------
export mntclu=/mnt/Clust
export mncl1=$mntclu/Herschel10
export mncl2=$mntclu/Manip2
export mncl3=$mntclu/Herschel1
export mncl4=$mntclu/SwING
export mncl5=$mntclu/Home
alias cdc='cd $mntclu'

# Mount work directories
mclust () { sshfs $atclust:/dsm/herschel10/nuages/Fred $mncl1
            sshfs $atclust2:/dsm/manip2/nuages/Fred $mncl2
            sshfs $atclust:/dsm/herschel1/nuages/Fred $mncl3
            sshfs $atclust:/dsm/herschel1/nuages/Codes/SwING $mncl4
            sshfs $atclust:/home/xxxxxxxx $mncl5 ; }

# Unmount the directories
umclust () { fusermount -u $mncl1
             fusermount -u $mncl2
             fusermount -u $mncl3
             fusermount -u $mncl4 
             fusermount -u $mncl5 ; }


# f. Miscellaneous
#-----------------
# Suspend activity
if [ $HOSTNAME == sappcz161 ] ; then
    sus() { delay=${1:-0h}
            scriptbanner "Suspending Activity in "$delay
            sleep $delay
            sudo pm-suspend ; } # pm-suspend-hybrid est mieux mais ne marche pas
else
    sus() { delay=${1:-0h}
            scriptbanner "Suspending Activity in "$delay
            sleep $delay
            systemctl suspend ; }
fi

# Hibernate
hib() { delay=${1:-0h}
        scriptbanner "Hibernating in "$delay
        sleep $delay
        systemctl hibernate ; }


# 3) Applications
#================

# a. Text editors
#-----------------
em() { emacs "$@" & }
em2() { emacs -geometry 166x55 "$@" & }
emnw() { emacs -nw "$@" ; }
emdb() { emacs --debug-init "$@" & }
ged() { gedit "$@" & }
export EDITOR=vi # crontab text editor, launched with crontab -e
alias templ='l ~/.templates/'

# To use less with files containing more than jsut text
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"                    

# Nerd-dictation
export NERD=$HOME'/bin/nerd-dictation/'
export NERDEN=$HOME'/bin/nerd-dictation/vosk-model-en-us-0.22'
export NERDFR=$HOME'/bin/nerd-dictation/vosk-model-fr-0.22'
alias nden=$NERD'nerd-dictation begin --vosk-model-dir='$NERDEN' &'
alias ndfr=$NERD'nerd-dictation begin --vosk-model-dir='$NERDFR' &'
emnden() { nden 
           em ./nerdUS.txt ; }
emnden() { ndfr 
           em ./nerdFR.txt ; }
alias nde=$NERD'nerd-dictation end'

# Say
sayen() { espeak ${1} ; }
sayfr() { espeak -vfr ${1} ; }


# b. Viewing graphical documents
#-------------------------------
pdf() { okular "$@" &> /dev/null & }
pdf2() { evince "$@" &> /dev/null & }
ima() { display "$@" & }
ima2() { ristretto "$@" & }
fits() { ds9 "$@" & }
vid() { vlc "$@" &> /dev/null & }
htm() { brave-browser "$@" &> /dev/null & }
libo() { libreoffice "$@" & }
alias zoom='zoom &'
alias brave='brave-browser &'
alias chrome='google-chrome &> /dev/null &'


# c. IDL
#-------
alias idl64='/usr/local/itt/idl/bin/bin.linux.x86_64/idl'
if [ $HOSTNAME == sappcw100 ] ; then
    alias iidl7='idl64 $idlib/idl_init.pro'
    alias iidl='idl86 $idlib/idl_init.pro'
elif [ $HOSTNAME == dappcw173 ] || [ $HOSTNAME == dappcw173.extra.cea.fr ] \
     || [ $HOSTNAME == dappcz161 ] || [ $HOSTNAME == dappcz161.extra.cea.fr ] \
     || [ $HOSTNAME == Birdland ] ; then
    alias iidl='idl64 $idlib/idl_init.pro'
elif [ $HOSTNAME == iclust ] || [ $HOSTNAME == iclustgate.extra.cea.fr ] \
       || [ $HOSTNAME == hubble.extra.cea.fr ] \
       || [ ${HOSTNAME:0:7} == feynman ] ; then
    iidl() { module add cports
             module add idl 
             idl $idlib/idl_init.pro ; }
fi


# d. Python
#----------
alias ipy='ipython3 --no-confirm-exit --matplotlib'


# e. Other
#----------
alias APT='~/bin/APT_2022.7.3/APT &'
alias TF='~/Desktop/TrueFireInstaller.AppImage &'
alias owncloud='/opt/ownCloud/ownCloud/bin/owncloud &'
if [ $HOSTNAME == dappcz161 ] ; then
    alias qprompt="~/bin/qprompt-v1.0-2c9752c-v1.0-linux-64-gcc.AppImage &"
fi
alias metro='gtick &> /dev/null &'


# 4) Network
#===========

# a. CUPS printing
#-----------------
# For each command:
# - First argument: PDF file name
# - Second (optional) argument: page list (format 2,3-5,16)
colp1() { 
    if [ -z "$2" ] ; then
        lp -d sapcolp1 -o media=A4 -o sides=two-sided-long-edge -o job-sheets=none $1 ;
    else
        lp -d sapcolp1 -o media=A4 -o sides=two-sided-long-edge -o job-sheets=none $1 -P $2 ;
    fi
        }
colp1A3() { 
    if [ -z "$2" ] ; then
        lp -d sapcolp1 -o media=A3 -o sides=two-sided-long-edge -o fit-to-page -o job-sheets=none $1 ;
    else
        lp -d sapcolp1 -o media=A3 -o sides=two-sided-long-edge -o fit-to-page -o job-sheets=none $1 -P $2 ;
    fi
        }
colp2() { 
    if [ -z "$2" ] ; then
        lp -d saplexcolp2 -o media=A4 -o sides=two-sided-long-edge -o job-sheets=none $1 ;
    else
        lp -d saplexcolp2 -o media=A4 -o sides=two-sided-long-edge -o job-sheets=none $1 -P $2 ;
    fi
        }
colp2A3() { 
    if [ -z "$2" ] ; then
        lp -d sapcolp1 -o media=A3 -o sides=two-sided-long-edge -o fit-to-page -o job-sheets=none $1 ;
    else
        lp -d sapcolp1 -o media=A3 -o sides=two-sided-long-edge -o fit-to-page -o job-sheets=none $1 -P $2 ;
    fi
        }
colp3() { 
    if [ -z "$2" ] ; then
        lp -d saplexcolp3 -o media=A4 -o sides=two-sided-long-edge -o job-sheets=none $1 ;
    else
        lp -d saplexcolp3 -o media=A4 -o sides=two-sided-long-edge -o job-sheets=none $1 -P $2 ;
    fi
        }
nb1() { 
    if [ -z "$2" ] ; then
        lp -d saplexcolp2 -o media=A4 -o sides=two-sided-long-edge -o job-sheets=none $1 ;
    else
        lp -d saplexcolp2 -o media=A4 -o sides=two-sided-long-edge -o job-sheets=none $1 -P $2 ;
    fi
        }
nb1A3() { 
    if [ -z "$2" ] ; then
        lp -d sapnb1 -o media=A3 -o sides=two-sided-long-edge -o fit-to-page -o job-sheets=none $1 ;
    else
        lp -d sapnb1 -o media=A3 -o sides=two-sided-long-edge -o fit-to-page -o job-sheets=none $1 -P $2 ;
    fi
        }
alias lps1='lpstat -o sapcolp1'
alias lps2='lpstat -o saplexcolp2'
alias lps3='lpstat -o saplexcolp3'
alias lpsnb='lpstat -o sapnb1'


# b. Connecting
#--------------
alias chal='ssh -X xxxxxxxx@challenger.extra.cea.fr'
alias hub='ssh -X xxxxxxxx@hubble.extra.cea.fr'
alias fhub='sftp xxxxxxxx@hubble.extra.cea.fr'
alias icg='ssh -X xxxxxxxx@iclustgate'
alias ficg='sftp xxxxxxxx@iclustgate'
alias fey='ssh -X xxxxxxxx@feynmanmaster01'
alias ffey='sftp xxxxxxxx@feynmanmaster01'
alias iclust='ssh -X xxxxxxxx@iclust'
alias ficlust='sftp xxxxxxxx@iclust'
alias coast='ssh -X xxxxxxxx@irfucoast'
alias fcoast='sftp xxxxxxxx@irfucoast'
alias omac='ssh -X xxxxxxxx@sapmcr126'
alias fomac='sftp xxxxxxxx@sapmcr126'
alias ftpcea='ftp ftp.cea.fr'
alias vpncea='fortisslvpn_cli --server mobietendu-ea.cea.fr:443 --vpnuser xxxxxxxx@extra.cea.fr'


# c. SSH with GPG
#----------------
if [ $HOSTNAME  == dappcw173 ] || [ $HOSTNAME == dappcw173.extra.cea.fr ] \
   || [ $HOSTNAME  == dappcz161 ] || [ $HOSTNAME == dappcz161.extra.cea.fr ] \
   || [ $HOSTNAME == Birdland ] ; then
    export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
    gpgconf --launch gpg-agent
fi


  #--------------------------------------------------------------------------
  #                   V. BANNER WHEN OPENING A SESSION
  #--------------------------------------------------------------------------

# 1) Welcome Message
#===================

# a. Calendar
#------------
# This uses my python program
colcal=$lightgreen
if [ $HOSTNAME != iclust ] && [ $HOSTNAME != iclustgate.extra.cea.fr ] \
     && [ $HOSTNAME != hubble.extra.cea.fr ] \
     && [ ${HOSTNAME:0:7} != feynman ] ; then
    pcal.py --no_banner
fi


# b. Banner
#----------
# Empty line over the terminal width
emptylinestr="printf ' %.0s' {1..$(tput cols)}"
export emptyline=$(eval $emptylinestr)

# Display
echo
printf "${colbban}${colban}"
printf "${emptyline}\n"
center "Bienvenue, Frédéric Galliano"
printf "${emptyline}\n"
center "Connecté sur "$HOSTNAME" en tant que "$USER
center "${SHELL} sur $(uname -o)"
center "Nous sommes le $(date)"
printf "${emptyline}${reset}\n"
echo


# 2) Disk usage
#==============
disk_usage.sh
alias dus="disk_usage.sh"


# 3) Random citation
#===================
# This uses my python program
echo
if [ $HOSTNAME == dappcw173 ] || [ $HOSTNAME == dappcz161 ] \
     || [ $HOSTNAME == dappcz161.extra.cea.fr ] \
     || [ $HOSTNAME = Birdland ] ; then
    random_citation.py --no_banner
fi

2. HIGHLIGHTING

My .bashrc calls this pretty_bash.sh file:


#!/bin/bash
#******************************************************************************
#*
#*               IMPROVING THE READABILITY OF THE COMMAND LINE
#*
#******************************************************************************


  #---------------------------------------------------------------------------
  #                               COLORS
  #---------------------------------------------------------------------------

# cf. https://misc.flogisoft.com/bash/tip_colors_and_formatting


# 1) Format
#----------
# Escape character
export esc='\e' # \e, \033 ou \x1b

# Return to the default setting
export reset=$esc'[0m'

# Different emphasis
export bold=$esc'[1m'
export dim=$esc'[2m'
export underline=$esc'[4m'
export blink=$esc'[5m'


# 2) Font colors
#---------------
export default=$esc'[39m'
export black=$esc'[30m'
export red=$esc'[31m'
export green=$esc'[32m'
export yellow=$esc'[33m'
export blue=$esc'[34m'
export magenta=$esc'[35m'
export cyan=$esc'[36m'
export lightgrey=$esc'[37m'
export darkgrey=$esc'[90m'
export lightred=$esc'[91m'
export lightgreen=$esc'[92m'
export lightyellow=$esc'[93m'
export lightblue=$esc'[94m'
export lightmagenta=$esc'[95m'
export lightcyan=$esc'[96m'
export white=$esc'[97m'


# 3) Background colors
#---------------------
export bdefault=$esc'[49m'
export bblack=$esc'[40m'
export bred=$esc'[41m'
export bgreen=$esc'[42m'
export byellow=$esc'[43m'
export bblue=$esc'[44m'
export bmagenta=$esc'[45m'
export bcyan=$esc'[46m'
export blightgrey=$esc'[47m'
export bdarkgrey=$esc'[100m'
export blightred=$esc'[101m'
export blightgreen=$esc'[102m'
export blightyellow=$esc'[103m'
export blightblue=$esc'[104m'
export blightmagenta=$esc'[105m'
export blightcyan=$esc'[106m'
export bwhite=$esc'[107m'


  #---------------------------------------------------------------------------
  #                               FORMATING
  #---------------------------------------------------------------------------

# Center text printed on the terminal
center() {
    termwidth="$(tput cols)"
    padding="$(printf '%0.1s' ' '{1..500})"
    printf '%*.*s %s %*.*s\n' 0 "$(((termwidth-2-${#1})/2))" "$padding" "$1" 0 \
           "$(((termwidth-1-${#1})/2))" "$padding\n"
          }
export -f center


  #---------------------------------------------------------------------------
  #                                 MISCELLANOUS
  #---------------------------------------------------------------------------

# Countdown functions to be put before launching important commands
countdown() {
    i=${1:-10}
    pref=${2:-$bold$yellow"    🕑 "$blink" ➱ Starting"}
    color=${3:-$red$bold}
    echo " "
    while [[ $i -ge 0 ]]
      do
        echo -e "\r "$pref" in "$reset$color$i"s \c"$reset
        sleep 1
        i=$(expr $i - 1)
    done
    echo -e "\r "$pref" now!..."$reset"\n"
}
export -f countdown

3. DISK USAGE

My .bashrc also calls this disk_usage.sh file:


#!/bin/bash
#*******************************************************************************
#*
#*                      SMALL SCRIPT SHOWING DISK USAGE
#*
#*******************************************************************************


# Créé le 20 janv. 2020


coldf=$lightred
colhl=$lightcyan
if [ $HOSTNAME != iclust ]; then
    echo
    printf "${coldf}$bold"
    center "REMPLISSAGE DES DISQUES"
    echo
    printf "${coldf}${pad}         Taille       Disponible      Utilisé "
    printf "   Fraction Utilisée\n"
    if [ $HOSTNAME == sappcw100 ] ; then
        dirdf=( /local/home/galliano /usr/data/Astro /mnt/data )
        dirname=( "HOME" "DATA" "RUNS" ) 
    elif [ $HOSTNAME == dappcw173 ] \
          || [ $HOSTNAME == dappcw173.extra.cea.fr ] ; then
        dirdf=( /local/home/fgallian )
        dirname=( "HOME" ) 
    elif [ $HOSTNAME == dappcz161 ] \
          || [ $HOSTNAME == dappcz161.extra.cea.fr ] ; then
        dirdf=( /local/home/fgallian /mnt/data )
        dirname=( "HOME" "DATA" ) 
    elif [ $HOSTNAME == Birdland ] ; then
        dirdf=( /home/fred /mnt/data/ /mnt/backup )
        dirname=( "HOME" "DATA" "BACK" ) 
    fi
    for i in "${!dirname[@]}"
    do
        sizedir=$(df -h --output=size ${dirdf[$i]} | sed 1d)
        availdir=$(df -h --output=avail ${dirdf[$i]} | sed 1d)
        useddir=$(df -h --output=used ${dirdf[$i]} | sed 1d)
        pcentdir=$(df -h --output=pcent ${dirdf[$i]} | sed 1d)
        printf "${coldf}${pad}${bold}${dirname[$i]}${colhl}     "
        printf "${sizedir}            "
        printf "${availdir}      ${useddir}                 ${pcentdir}%\n"
    done
    echo -e $reset
fi

4. FANCY LS

My fancy ls is set up by this ls.sh file:


#!/bin/bash
#*******************************************************************************
#
#                 FANCY PERSONNAL LS WITH USEFUL SIZE INFO
#
#*******************************************************************************


  #----------------------------------------------------------------------------
  # 1) AUTHOR: F. Galliano
  #
  # 2) DESCRIPTION: my fancy ls
  #
  # 3) HISTORY:
  #    - aug. 2019: created (version 1.00).
  #----------------------------------------------------------------------------


# 1) ARGUMENTS
#-------------
# Argument
if [ -z "$*" ]; then 
  dirarg=.
else
  dirarg=$1
fi

# Read the optional arugments
KW="-ohF"
while getopts ":ha" opt; do
  case $opt in
    h) echo "PERSONNAL BASH LS SCRIPT"
       echo " - print the manual: ls.sh -h"
       echo " - list the content of the current directory: ls.sh"
       echo " - list the content of directory <dir>: ls.sh <dir>"
       exit
    ;;
    \?) echo "Invalid option -$OPTARG" >&2
    ;;
  esac
done


# 2) HEADER
#----------
# Print the full path of the directory
readlink -f $dirarg \
  | awk '{ printf("           \033[0;4;33mRépertoire:")
           printf("\033[0;1;33m %s\033[0m\n", 
                  $1) }'

# Print the number of directories inside
( find $dirarg -maxdepth 1 -type d ! -path $dirarg | wc -l
  find $dirarg -maxdepth 1 -type d ! -path $dirarg -name ".*" | wc -l ) \
  | awk 'BEGIN { printf("\033[0;4;33mNombre de répertoires:") }
         { if (NR==1) { NTOT=$1 }
           if (NR==2) { NHIDDEN=$1 } }
         END { NSHOWN = NTOT - NHIDDEN
               printf("\033[0;1;33m %6i\033[0;33m (apparent)", NSHOWN)
               printf("\033[0;1;33m %6i\033[0;33m (caché)\n", NHIDDEN) }'

# Print the number of files inside
( find $dirarg -maxdepth 1 -type f | wc -l
  find $dirarg -maxdepth 1 -type f -name ".*" | wc -l ) \
  | awk 'BEGIN { printf("   \033[0;4;33mNombre de fichiers:") }
         { if (NR==1) { NTOT=$1 }
           if (NR==2) { NHIDDEN=$1 } }
         END { NSHOWN = NTOT - NHIDDEN
               printf("\033[0;1;33m %6i\033[0;33m (apparent)", NSHOWN)
               printf("\033[0;1;33m %6i\033[0;33m (caché)\n", NHIDDEN) 
               printf("\033[0m") }'


# 3) MODIFIED LS
#---------------
(du -sh --apparent-size $dirarg/* ; ls $KW --color=always $dirarg ) \
  | awk '{ if ($1 == "total")
             {LS = 1} 
           else if (!LS) 
             { COUNT+=1
               SIZES[COUNT] = $1
               if (length($1) > maxlen1) {maxlen1 = length($1)} }
           else 
              { COUNTLS+=1
                sub($2,"",$0)
                sub($3,sprintf("\033[1;33m%s\033[0m",SIZES[COUNTLS]),$3)
                sub("août","août ",$4)
                sub("déc.","déc. ",$4)
                printf("%12s  %8s  %16s  %2s  %-5s  %-5s   %s\n", 
                       $1, $2, $3, $5, $4, $6, $7) } }'


# 4) END
#-------
# Print the total size
du -sh $dirarg \
  | awk '{ printf("        \033[0;4;33mTaille totale:")
           printf("\033[0;1;33m %6s\033[0m\n",$1) }'

BACK

Author: F. Galliano
Last update: 31 mai 2024