We're very pleased that you want to get in touch with us. Please fill in the form below:

or   Close this form  
Some content

Peter Pilgrim :: Java Champion :: Digital Developer Architect

I design Java EE and Scala software solutions for the blue-chip clients and private sector

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, unfortunately, I am no longer accepting standard GOV.UK contract engagements for the public sector. Please enquire for further information.

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

19 February 2018 No comments

8 minutes


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 http://www.xenonique.co.uk/blog/2012/06/29/favourite-linux-and-unix-bash-aliases/

## set the proxy connections# set the proxy connections# set the proxy connections
#export HTTP_PROXY='http://user2018:Pass2018@corporateproxy.com:8080'
#export HTTPS_PROXY='http://user2018:Pass20188@corporateproxy.com:8080'
#export NO_PROXY="localhost,, 10.24*, *corporateproxy.com, *.corp"

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

## export LDFLAGS='-lpthread'
## Slackware: export LS_OPTIONS='--8bit --color=tty -F -b -T 0'
## export LS_OPTIONS='--color=tty -F -b --author'
## export LS_OPTIONS='-F'
export LS_OPTIONS='--color=tty -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 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 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_161
export JAVA8_HOME=/usr/lib/jvm/jdk1.8.0/jdk1.8.0_161


# Where is Scala installed (Mac OS X)?
export SCALA_HOME=/Library /opt/scala/scala-2.11.7

# Where is SBT installed (Mac OS X)?
export SBT_HOME=/Library/opt/sbt/sbt-0.13.12

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

# Where is Ant installed (Mac OS X)?
export ANT_HOME=/Library/opt/apache-ant-1.9.6

# Where is Maven installed (Mac OS X)?
export M2_HOME=/Library/opt/apache-maven-3.3.3

# http://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/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:\

## 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] > "

## See also https://stackoverflow.com/questions/2024884/commandline-overwrites-itself-when-the-commands-get-too-long
case `uname -s` in
    darwin | Darwin )
        # MAC OS X
        ## See also this article: https://stackoverflow.com/questions/28782394/how-to-get-osx-shell-script-to-show-colors-in-echo
        ## echo "This is a Darwin (Apple Mac OS X)"

        # This is not MAC OS X
        ## echo "This is not Darwin"


# 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

git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'
git config --global alias.hdiff 'diff HEAD^ HEAD'
git config --global alias.hd 'diff HEAD^ HEAD'

# Show me all git commits in short form
git config --global alias.ls 'log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%C(cyan)\\ [%cn]" --decorate'
# Show me all git all changed files in short format
git config --global alias.ll 'log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%C(cyan)\\ [%cn]" --decorate --numstat'
# Show me changes list with no colours if I need to chain the out put with Unix pipes:
git config --global alias.lnc 'log --pretty=format:"%h\\ %s\\ [%cn]"'
# Show me changes with dates
git config --global alias.lds 'log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%C(cyan)\\ [%cn]" --decorate --date=short'
# Show me the history of a file, with diffs
git config --global alias.filelog 'log -u'
git config --global alias.fl 'log -u'
# Show me modified files in the last commit
git config --global alias.dl '!git ll -1'
# Find me a file in the codebase e.g. 'git ff foo.java' or 'git ff build.gradle'
git config --global alias.ff '!git ls-files | grep -i '
## Grep the entire codebase for a particular string ignore case!  e.g 'git agrep "mt103"''
git config --global alias.agrep 'grep -Ii'

# List all of my Git aliases, because sometimes I forget them
git config --global alias.la '!git config -l | grep alias | cut -c 7- | sort'

# Git stash
git config --global alias.sl 'stash list '
git config --global alias.sa 'stash apply '
git config --global alias.ss 'stash save '

## Reset aliases
# Reset the current HEAD to the specified state (How do I undo the most recent commit I made in Git that I have not yet pushed? 😉 *PP*
# See  also https://stackoverflow.com/questions/927358/how-to-undo-the-most-recent-commits-in-git
git config --global alias.r 'reset'
# Reset softly to the previous checked in version
git config --global alias.r1 'reset HEAD^'
# Reset softly to the previous-previous checked in version
git config --global alias.r2 'reset HEAD^^'
# *WARNING* Advanced users only see https://stackoverflow.com/questions/9529078/how-do-i-use-git-reset-hard-head-to-revert-to-a-previous-commit
# Perhaps, get clarification from your Anchor beforehand
# Reset by throwing away your uncommited changes, perhaps stash them first
git config --global alias.rh 'reset --hard'
# Reset hard to the previous version
git config --global alias.rh1 'reset HEAD^ --hard'
# Reset hard to the previous-previous version
git config --global alias.rh2 'reset HEAD^^ --hard'

## The next alias does not work on FIRM stock self-service Git *PP* 01-March-2018
# git config --global alias.glog log --pretty=format:"%h %s" --graph

## From Ales Setinc
##   "I found this little visual hack for "git log" command. I find it very useful, especial if you add it to your .bash_profile as a new command. Check the image attached."
## 🙂
alias git-log='git log --graph --pretty="format:%C(yellow)%h%Cred%d%Creset %s %C(green)(%ar) %C(cyan)%an%Creset"'
alias gitlog=git-log
alias glog=git-log

# Something for Linux and Mac OS X to remember credential login for a period of timeout *PP* 01-March-2018
alias setup_git_cache='git config --global credential.helper "cache --timeout=2548800" '

# fini

[[ -s "/Users/peterpilgrim/.sdkman/bin/sdkman-init.sh" ]] && source "/Users/peterpilgrim/.sdkman/bin/sdkman-init.sh"

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

That was my user story from last week.

Have fun and enjoy your day.


Contents of this blog entry are under copyright © 2017 by Peter Pilgrim and associates. For enquiries after republishing, please contact us for permission. All requests for syndicated content will be ignored /dev/null, consider yourself warned!

I help to design, create and build JVM components and services that are behind popular e-commerce websites.

My Blurb

Please get in touch , directly, to establish hire availability, contract & consulting opportunities.

Speaking at Your Conference

Contact by invitation

What Peter Does