Skip to content

Instantly share code, notes, and snippets.

@mbrowniebytes
Created March 29, 2021 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbrowniebytes/098d3eae919b4b8065d8556f21dc807e to your computer and use it in GitHub Desktop.
Save mbrowniebytes/098d3eae919b4b8065d8556f21dc807e to your computer and use it in GitHub Desktop.
Configure your bash profile for git
# change me vars
ec2_name="ec2namechangeme"
# use vim
export EDITOR=vim
alias vi="vim"
# allow tab auto complete w/ sudo
if [[ "$HOME" == "/home/ec2-user" ]]; then
complete -cf sudo
fi
# git status
git_status="n"
# existing git file in most distros
git_prompt=/usr/share/git-core/contrib/completion/git-prompt.sh
if [[ -f $git_prompt ]]; then
source $git_prompt
export GIT_PS1_SHOWDIRTYSTATE=true # + staged, * unstaged
export GIT_PS1_SHOWUNTRACKEDFILES=true # % untracked files
export GIT_PS1_SHOWUPSTREAM="auto" # < behind, > ahead, <> diverged, = no difference
export GIT_PS1_SHOWSTASHSTATE=true # $ something is stashed
git_status="y"
fi
unset git_prompt
# export PS1="[\u@\h \W]\$" # default
PS1="\u@${ec2_name} "
PS1+="\[\033[01;34m\]\${PWD#\$HOME/}\[\033[00m\]"
if [ $git_status = "y" ]; then
PS1+=" \[\033[0;32m\]\$(__git_ps1 '\''(%s)'\'')\[\033[00m\]"
fi
PS1+="\n\[\033[0;32m\]└─►\[\033[00m\] "
export PS1
PATH=$PATH:$HOME/bin:/usr/bin:/usr/local/bin
export PATH
unset USERNAME
alias git-log="git log --pretty=oneline"
alias git-preview-files="git fetch; git diff --name-only HEAD..@{u}"
alias git-preview-diff="git fetch; git diff HEAD..@{u}"
@mbrowniebytes
Copy link
Author

To change the bash prompt on your AWS EC2 instance from the default of

[ec2-user@ip-10-1-1-1 ~]$

to

ec2-user@ec2-name /data/cool-app (development=)
└─►

Add as temp_bash_profile.sh

Note, ''' = '

Update ec2_name="ec2name" to the name of your ec2 ie super-cool-service

vim temp_bash_profile.sh

Append to existing bash profile
using sed

sed -i '/# User specific environment and startup programs/ r temp_bash_profile.sh' ~/.bash_profile

or edit and add to the end

vim ~/.bash_profile

Test and see results

source ~/.bash_profile

ec2-user@ec2-name /data/cool-app (development=)
└─►

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment