Created
December 5, 2018 17:39
-
-
Save BadAsstronaut/46c34e5c37366e94a725ea9990fb1d0b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ---------------------------- SSH agent settings | |
| source ~/.git-completion.bash | |
| env=~/.ssh/agent.env | |
| agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; } | |
| agent_start () { | |
| (umask 077; ssh-agent >| "$env") | |
| . "$env" >| /dev/null ; } | |
| agent_load_env | |
| # agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running | |
| agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?) | |
| if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then | |
| agent_start | |
| ssh-add | |
| elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then | |
| ssh-add | |
| fi | |
| unset env | |
| # ---------------------------- Prompt settings | |
| # get current status of git repo | |
| function parse_git_dirty { | |
| status=`git status 2>&1 | tee` | |
| dirty=`echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?"` | |
| untracked=`echo -n "${status}" 2> /dev/null | grep "Untracked files" &> /dev/null; echo "$?"` | |
| ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"` | |
| newfile=`echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "$?"` | |
| renamed=`echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo "$?"` | |
| deleted=`echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "$?"` | |
| bits='' | |
| if [ "${renamed}" == "0" ]; then | |
| bits=">${bits}" | |
| fi | |
| if [ "${ahead}" == "0" ]; then | |
| bits="*${bits}" | |
| fi | |
| if [ "${newfile}" == "0" ]; then | |
| bits="+${bits}" | |
| fi | |
| if [ "${untracked}" == "0" ]; then | |
| bits="?${bits}" | |
| fi | |
| if [ "${deleted}" == "0" ]; then | |
| bits="x${bits}" | |
| fi | |
| if [ "${dirty}" == "0" ]; then | |
| bits="!${bits}" | |
| fi | |
| if [ ! "${bits}" == "" ]; then | |
| echo " ${bits}" | |
| else | |
| echo "" | |
| fi | |
| } | |
| COLOR_RED="\[\033[0;31m\]" | |
| COLOR_VIOLET="\[\033[0;35m\]" | |
| COLOR_GREEN="\[\033[1;32m\]" | |
| COLOR_BLUE="\[\033[0;34m\]" | |
| COLOR_CYAN="\[\033[0;36m\]" | |
| COLOR_WHITE="\[\033[0;37m\]" | |
| COLOR_RESET="\[\033[0m\]" | |
| function get_status_color { | |
| if [ "${1}" == "" ]; then | |
| echo $COLOR_GREEN | |
| else | |
| echo $COLOR_RED | |
| fi | |
| } | |
| # get current branch in git repo | |
| function parse_git_branch { | |
| BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'` | |
| if [ ! "${BRANCH}" == "" ] | |
| then | |
| STAT=`parse_git_dirty` | |
| COLOR=`get_status_color ${STAT}` | |
| PS1="${PS1}${COLOR} <${BRANCH}${STAT}> " | |
| fi | |
| } | |
| function set_prompt { | |
| PS1="\n$COLOR_WHITE\u $COLOR_VIOLET\h: $COLOR_CYAN\w" | |
| parse_git_branch | |
| PS1="${PS1}\n$COLOR_BLUE>$COLOR_RESET " | |
| } | |
| PROMPT_COMMAND=set_prompt | |
| # ---------------------------- Utility Functions | |
| AWS_PEM=~/.ssh/groupworks_aws_dev.pem | |
| AWS_USER=ec2-user | |
| function aws_ssh { | |
| ssh -i $AWS_PEM $AWS_USER@$1 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment