PEAT Online Course -
Test-Driven Development
using Kotlin (DELUXE EDITION)

  • Theory 'n' practice
  • Test-driven method
  • Acceptance criteria
  • Learn to code mastery
  • Ace that job interview
  • Free updates
AVAILABLE NOW
VIMEO ON-DEMAND

My favourite Bash profile Linux and Mac OS X updated for 2018

19 February 2018 Comments off

6 minutes

1188

As a platform engineer, I want to keep a copy of a my favourite Linux Bash Profile in my blog on the public web, so that I do not have to keep making it up from scratch every time I configure a Virtual Machine.

## MY FAVOURITE BASH PROFILE ~/.bash_profile
### Based of the https://www.xenonique.co.uk/blog/2018/02/19/my-favourite-bash-profile-linux-and-mac-os-x-updated-for-2018/ 
### and https://www.xenonique.co.uk/blog/2012/06/29/favourite-linux-and-unix-bash-aliases/


# Load workspace HTTP proxy configuration, if any
if [ -f ${HOME}/.workspace-http-proxy.sh.env ]; then
    . ${HOME}/.workspace-http-proxy.sh.env
fi

set -o emacs
# Do not exit on EOF. To exit the shell type `exit'
set -o ignoreeof
# Do not allow output redirection (>) to overwrite an existing file
set -o noclobber
# set the core limit
ulimit -c 10240

# As a platform engineer, I want to upgrade SHELL history to "remember long time"
set history=1024
set savehist=1024

## Olde skool :-/  export LDFLAGS='-lpthread' #Old skool 
## Slackware: export LS_OPTIONS='--8bit --color=tty -F -b -T 0'
## export LS_OPTIONS='--color=tty -F -b --author'
export LS_OPTIONS='-F'

# Aliases
alias ls="/bin/ls $LS_OPTIONS"
alias ll='ls -l'
alias lsd='ls -ld'
alias la='ls -a'
alias lf='ls -F'
alias lr='ls -alFRt'
alias lx='ls -xF'
alias llar='ls -laFR'
alias lt='ls -lartF'
alias lrt='ls -lrt'

alias home='cd ${HOME}'
alias up='cd ..'
alias up2='cd ../..'
alias up3='cd ../../..'
alias up4='cd ../../../..'
alias up5='cd ../../../../..'
alias pe='printenv'
alias senv='env | sort'
alias pu='pushd'
alias po='popd'
alias pud='pushd .'
alias rot='pushd +1'
alias jobs='jobs -l'
alias mroe=more
alias lses=less
alias lsse=less
alias l=ls
alias f=file
alias c=cat
alias m=more
alias j=jobs
alias k=kill
alias d=dirs
alias h=history
alias his=history
alias hm='history | less'
alias sy3='sync; sync; sync; echo "sync 3 times ..."'
alias del='rm -i'
alias bye=exit
alias ciao=exit

## Some quick GIT alias
alias gpull='git pull origin master'
alias gpush='git push origin master'
# As a platform engineer, I want to configure Git cache to remember my password for one month on average
alias set_git_cache='git config --global credential.helper "cache --timeout=2548800" '

alias macjava=/usr/libexec/java_home

# Switch between JDK 8,9,10 and 11
function checkSetJdk() {
    if [ $# -ne 0 ]; then
        /usr/libexec/java_home -v $@ > /dev/null 2>&1
        status=$?
        if [ $status -ne 0 ]; then
            echo "*ERROR*: Sorry, this version of the JDK [$@] does not exist. (status:$status)" 1>&2
            return 1
        else
            removeFromPath '/System/Library/Frameworks/JavaVM.framework/Home/bin'
            if [ -n "${JAVA_HOME+x}" ]; then
                removeFromPath $JAVA_HOME
            fi
            export JAVA_HOME=`/usr/libexec/java_home -v $@`
            # echo -e "\n*FINAL* setting JAVA_HOME to ${JAVA_HOME}"

            # Does the older JRE folder exist
            if [ -d ${JAVA_HOME}/jre ]; then
                export PATH=$JAVA_HOME/jre/bin:$PATH
            fi
            export PATH=$JAVA_HOME/bin:$PATH
            # echo -e "\n*FINAL* setting PATH to $PATH"
        fi
    fi
 }


function removeFromPath() {
    export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")
    ### echo -e "\n*DEBUG setting now to PATH=$PATH"
}


## See this Apple Support Discussion https://discussions.apple.com/thread/4158054
alias restart-webcam='sudo killall VDCAssistant'


alias vibashpro='vi ~/.bash_profile'
alias rebashpro='. ~/.bash_profile'

## Where is GO Language installed?
export GO_HOME=/opt/go

## Where is Java installed?
export JAVA_HOME=`/usr/libexec/java_home`
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0/jdk1.8.0_181
export JAVA8_HOME=/usr/lib/jvm/jdk1.8.0/jdk1.8.0_181

export JAVAFX_HOME=${JAVA_HOME}

# Where is Scala installed (Mac OS X)?
## export SCALA_HOME=/Library/opt/scala/scala-2.11.7
export SCALA_HOME=${HOME}/.sdkman/candidates/sbt/current

# Where is SBT installed (Mac OS X)?
## export SBT_HOME=/Library/opt/sbt/sbt-0.13.12
export SBT_HOME=${HOME}/.sdkman/candidates/sbt/current/bin/sbt

# Where is Groovy installed (SDK Man)
## export GROOVY_HOME=${HOME}/.sdkman/groovy/current
export GROOVY_HOME=${HOME}/.sdkman/candidates/groovy/current

# Where is Ant installed (Mac OS X)?
export ANT_HOME=${HOME}/.sdkman/candidates/ant/current

# Where is Maven installed (Mac OS X)?
export M2_HOME=${HOME}/.sdkman/candidates/maven/current

# https://stackoverflow.com/questions/13161387/set-the-permgen-size-for-the-child-jvm-processes-that-maven-will-spin-off
export MAVEN_OPTS="-XX:MaxPermSize=256m -Xms512m -Xmx1024m"

# Where is Gradle installed (Mac OS X)?
export GRADLE_HOME=${HOME}/.sdkman/candidates/gradle/current

# Where is Node installed?
export NODE_PATH=/usr/local/lib/node_modules

## Where is IntelliJ installed?
export INTELLIJ_HOME=/opt/intellij-idea

## Define PATH
export PATH=.:${HOME}/bin:${HOME}/.local/bin:\
${SCALA_HOME}/bin:${SBT_HOME}/bin:\
${GROOVY_HOME}/bin:${M2_HOME}/bin:${ANT_HOME}/bin:${GRADLE_HOME}/bin:\
${GO_HOME}/bin:\
${JAVA_HOME}/bin:${JAVA_HOME}/jre/bin:\
${INTELLIJ_HOME}/bin:\
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

## Keep a copy of the original PATH
export ORIGINAL_PATH=${HOME}/bin:${HOME}/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

### This is the original PS1 on Debian (e.g Ubuntu or Linux Mint)
#### "${debian_chroot:+($debian_chroot)}\u@\h \w \$ "
export SAVED_PS1="${debian_chroot:+($debian_chroot)}\u@\h \w [\$HISTCMD] \$ "

## Ansi Color XTerm (tested on LinuxMint )
## See also https://askubuntu.com/questions/558280/changing-colour-of-text-and-background-of-terminal
#export PS1="\e[38;5;034m\u@\h \e[0m\e[38;5;039m\W\e[0m [\$HISTCMD] > "

# Add the Git Bash completion, if it exists

if [ -f ${HOME}/git-completion.bash -a -r ${HOME}/git-completion.bash ]; then
    #### echo ${HOME}/git-completion.bash (see also https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash )
    . ${HOME}/git-completion.bash
fi

#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
[[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh"

## This is for Ruby Version Manager
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

## This is for Node Version Manager
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

## END

That was my user story from last week.

Addendum

I want to also share this BASH configuration in Home office and Work office situation. In work office, like you I work behind a HTTP Proxy so I extracted shell as an environment script to source-in.

## File: ~/.workspace-http-proxy.sh.env
## set the proxy connections# set the proxy connections# set the proxy connections
#export HTTP_PROXY='https://user2018:Pass2018@corporateproxy.com:8080'
#export HTTPS_PROXY='https://user2018:Pass2018@corporateproxy.com:8080'
#export NO_PROXY="localhost, 127.0.0.1, 10.24*, *corporateproxy.com, *.corp"
#export http_proxy=${HTTP_PROXY}
#export https_proxy=${HTTPS_PROXY}
#export ALL_PROXY=${HTTPS_PROXY}
#export no_proxy=$NO_PROXY

Save this this shell source scripts as ${HOME}/.workspace-http-proxy.sh.env and then the file private to your user with the command: chmod 600 ${HOME}/.workspace-http-proxy.sh.env.

Have fun and enjoy your day.

+PP+

Hey all! Thanks for visiting. I provide fringe benefits to interested readers: checkout consultancy, training or mentorship Please make enquiries by email or
call +44 (0)7397 067 658.

Due to the Off-Payroll Working plan for the UK government, I am enforcing stricter measures on contracts. All potential public sector GOV.UK contracts engagements must be approved by QDOS and/or SJD Accounting. Please enquire for further information.