Skip to content

Instantly share code, notes, and snippets.

@useless-stuff
Last active January 4, 2019 11:25
Show Gist options
  • Save useless-stuff/f5b3ba75a54089ef460f381c99296726 to your computer and use it in GitHub Desktop.
Save useless-stuff/f5b3ba75a54089ef460f381c99296726 to your computer and use it in GitHub Desktop.
BASH - Bash user profile
########################################################################
# BASH TOOLS
# _
# ./ | _________________
# / / / __________ //\_
# /' / | (__________) ||.' `-.________________________
# / / | __________ ||`._.-'~~~~~~~~~~~~~~~~~~~~~~~~`
# / \ \__(__________)__\\/
# | `\
# | | ___________________
# | |___________________...-------'''- - - =- - = - = `.
# /| | \- = = - -= - = - =- = - =|
# ( | | |= -= - = - = - = - =--= = - = =|
# \| |___________________/- = - -= =_- =_-=_- -=_=-=_=_= -|
# | | ```-------...___________________.'
# |________|
# \ / _
# | | ,,,,,,, /=\
# ,-' `-, /\___________ (\\\\\\\||=|
# | | \/~~~~~~~~~~~` ^^^^^^^ \=/
# `--------' `
########################################################################
# Functions in this .profile
# It will change your PS1 in order to have the branch name + color at the end (white= whatever branch / yellow[blinking] = test / red[blinking] = master)
#
# Commands in this .profile
# git_log_hash = it swhows the git commit list with the short hash code
# git_tree = it shows am prettified version of git tree
# weather = shoes London wheter's ( just in case you are a lazy nerd )
######################################################################
REACT_EDITOR=phpstorm
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
### Shows branch name in PS1
red='\033[31;5m';
white='\033[0;97m';
yellow='\033[33;5m';
default='\033[0;m';
blue='\033[0;34m';
magenta='\033[0;35m';
cyan='\033[0;36m';
green='\033[0;32m';
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
set_ps1_git_branch_color(){
BRANCH=$(parse_git_branch)
if [ -z $BRANCH ]; then
return 0
fi
if [ $BRANCH = "(master)" ]; then
echo -e "${red}${BRANCH}${default}" | sed -E 's/[()]+//g'
return 0
fi
if [ $BRANCH = "(test)" ]; then
echo -e "${yellow}${BRANCH}${default}" | sed -E 's/[()]+//g'
return 0
fi
echo -e "${white}${BRANCH}${default}" | sed -E 's/[()]+//g'
}
export PS1="${cyan}\h ${magenta}\u ${green}\w\$(set_ps1_git_branch_color)${default} \$(getTerraformWorkspace) \n\\$ \[$(tput sgr0)\]"
parseTerraform() {
if [ -e .terraform ]; then
terraform workspace show 2> /dev/null
fi
}
getTerraformWorkspace() {
WS=$(parseTerraform)
if [ -z "$WS" ]; then
return 0
fi
if [ $WS = "prod" ]; then
echo -e "${default}terraform: ${red}${WS}${default}"
return 0
fi
if [ $WS = "dev" ]; then
echo -e "${default}terraform: ${white}${WS}${default}"
return 0
fi
if [ $WS = "local" ]; then
echo -e "${default}terraform: ${white}${WS}${default}"
return 0
fi
echo -e "${red}⚠️ terraform bad workspace ${WS} ⚠️ ${default}"
}
# GIT
### Short hash id list
alias git_log_hash="git log --pretty=oneline --abbrev-commit"
alias git_tree="git log --oneline --graph --decorate --all"
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
# WEATHER
alias weather="curl wttr.in/London"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment