Skip to content

Instantly share code, notes, and snippets.

@ar-to
Created October 12, 2018 18:58
Show Gist options
  • Save ar-to/70f7c124b48ade315065ffe799f222a0 to your computer and use it in GitHub Desktop.
Save ar-to/70f7c124b48ade315065ffe799f222a0 to your computer and use it in GitHub Desktop.
Useful scripts for .bash_profile on OSX
#Below is a function to add current git branch name to bash prompt
#It also changes default setting of \h:\W \u\$
#source: https://coderwall.com/p/fasnya/add-git-branch-name-to-bash-prompt
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "
#The following functions are used to run git push origin w/branch w/o parenthesis as used in the ps1 prompt
parse_git_branch_two() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \1/' #removes () from branch name
}
#function to run the git push script
function gpush {
echo git push origin $(parse_git_branch_two)
read -r -p "Are you sure? [Y/n]: " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
git push origin $(parse_git_branch_two)
echo worked!
else
return
fi
}
#aliases
alias project_status='open -e ~/Documents/Projects\ Status.rtf'
alias gs='git status'
alias uc='git add -u && git commit -m'
#This appends scripts path to $PATH: for custom scripts to run with source script.sh
export PATH="$HOME/scripts:$PATH"
#This loads rbenv ruby package manager: install rbenv firsts via brew install rbenv
eval "$(rbenv init -)"
#This loads nvm node package manager
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
#set db path for mongodb
export MONGO_PATH=/usr/local/mongodb
export PATH=$PATH:$MONGO_PATH/bin
#set default editor
export EDITOR='vim'
#to initiate python version manager on login: install via brew install pyenv
eval "$(pyenv init -)"
#to initiate docker-machine and have it run the default vm:
#install docker & docker-machine via brew install ||
#install docker via .dmg to avoid this
eval "$(docker-machine env default)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment