Skip to content

Instantly share code, notes, and snippets.

@lcs-felix
Forked from fwfurtado/.bash_profile
Created August 3, 2017 23:01
Show Gist options
  • Save lcs-felix/a3fec59bb12e789654b6b3aeceaa5ce5 to your computer and use it in GitHub Desktop.
Save lcs-felix/a3fec59bb12e789654b6b3aeceaa5ce5 to your computer and use it in GitHub Desktop.
#!/bin/bash
clear
__green=$(tput setaf 2)
__red=$(tput setaf 1)
__reset=$(tput sgr0)
# return colored actual branch
__getActualBranch(){
if git branch &>/dev/null && true || false; then
branch=$(git branch 2>/dev/null | grep -e "^\* " | sed 's/^\* //')
echo -e "$__green[$__red $branch $__green]$__reset"
fi
}
#Define prompt + branch
export PS1="$__green\w$__reset\n\h$__red@$__reset\u \$(__getActualBranch) \$$__reset "
#Define o tamanho máximo de colunas no terminal
stty cols 1000
_DEBUG="off"
__DEBUG(){
[ "$_DEBUG" == "on" ] && sleep 1 && echo -e "$__red$@$__reset"
}
__INFO(){
[ "$_DEBUG" == "on" ] && sleep 1 && echo -ne "$__green$@$__reset"
}
__OK(){
[ "$_DEBUG" == "on" ] && echo -e "$__green[ $__resetOK $__green]$__reset"
}
__FAIL(){
[ "$_DEBUG" == "on" ] && echo -e "$__green[ $__redFAIL $__green]$__reset"
}
__INFO "Check homebrew is installed"
if ! hash brew 2>/dev/null; then
__FAIL
__DEBUG Intalling Homebrew via CURL
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
else
__OK
fi
__INFO "Check java is installed"
if ! hash java 2>/dev/null; then
__FAIL
__DEBUG "Installing java via homebrew"
brew cask install java
else
__OK
fi
__INFO "Check mas (Mac App Store) is installed"
if ! hash mas 2>/dev/null; then
__FAIL
__DEBUG "Installing mas via homebrew"
brew install mas
__DEBUG "Does signin in mac app store"
mas signin [email protected] --dialog
else
__OK
fi
__INFO "Check Xcode is installed"
if [[ -z $(mas list | grep -i xcode) ]]; then
__FAIL
__DEBUG "Installing Xcode via mas"
mas install $(mas search xcode | grep -iE '\d+? xcode$' | sed 's/[^0-9]//g') --force
else
__OK
fi
__INFO "Check gist is installed"
if ! hash gist 2>/dev/null; then
__FAIL
__DEBUG "Installing gist via homebrew"
brew install gist
else
__OK
fi
__INFO "Verifying that the bash_completions directory exists"
if [ ! -d ~/.bash_completions ]; then
__FAIL
__DEBUG "Make directory bash_completions"
mkdir ~/.bash_completions
__DEBUG "Getting id of gist for completions file"
id=$(gist -l feh-wilinando | grep bash-completions | sed -e 's/https:\/\/gist\.github\.com\///' -e 's/ bash-completions//')
gist --read $id maven-completion.bash > ~/.bash_completions/maven-completion.bash
gist --read $id docker-completion.bash > ~/.bash_completions/docker-completion.bash
gist --read $id git-completion.bash > ~/.bash_completions/git-completion.bash
else
__OK
fi
# Load completions
__INFO "Load completions file"
for completion in ~/.bash_completions/*.bash
do
source $completion
done
__OK
# Dockerized alias
__INFO "Check docker is installed"
if ! hash docker 2>/dev/null; then
__FAIL
__DEBUG "Downlaod Docker.dmg file"
curl -O https://download.docker.com/mac/stable/Docker.dmg
__DEBUG "Attach Docker.dmg to Volumes"
hdiutil attach Docker.dmg -mountpoint /Volumes/Docker/
__DEBUG "Copy Docker.app/ to /Applications"
cp -R /Volumes/Docker/Docker.app/ /Applications/Docker.app/
__DEBUG "Detach volume from Docker"
hdiutil detach /Volumes/Docker/
__DEBUG "Remove Docker.dmg file"
rm Docker.dmg
__DEBUG "Start Docker Engine"
open /Applications/Docker.app/
else
__OK
fi
__INFO "Check if docker is able to pull images"
if docker images &>/dev/null; then
__OK
__INFO "Check maven image exists"
if [[ -z $(docker images -q maven) ]]; then
__FAIL
__DEBUG "Pull maven image"
docker pull maven
else
__OK
fi
alias mvn="docker run --rm -v ~/.m2:/root/.m2 -v $(pwd):/project -w /project maven mvn $@"
__INFO "Check mysql image exists"
if [[ -z $(docker images -q mysql) ]]; then
__FAIL
__DEBUG "Pull mysql image"
docker pull mysql
else
__OK
fi
else
__FAIL
fi
alias mysql.start="docker run -d -v ~/.var/lib/mysql:/var/lib/mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -p 3306:3306 --name mysql-dockerized mysql"
alias mysql="docker exec -it mysql-dockerized mysql $@"
alias mysql.stop="docker stop mysql-dockerized && docker rm mysql-dockerized"
#General alias
alias ls="ls -l"
alias grep="grep --color=auto"
if [ "$_DEBUG" == "on" ]; then
sed -i '' -E '/sed/!s/_DEBUG="on"/_DEBUG="off"/g' ~/.bash_profile
fi
#General export
export CLICOLOR=1
export LSCOLORS=Ehfxcxdxbxegedabagacad
export PATH=$PATH:~/Library/Android/sdk/platform-tools
export PATH=$PATH:~/Library/Android/sdk/tools
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment