Last active
April 13, 2018 18:21
-
-
Save mdlinville/5547beb818ddaadd4c2eb984e0ad74ba to your computer and use it in GitHub Desktop.
Git auto-complete and prompt stuff for .bash_profile
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
# Paste the below into your .bash_profile, make tweaks, and restart your terminal | |
# Change these to where your git-completion.bash and git-prompt.sh live | |
# If you don't have them locally, get them from: | |
# https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh | |
# https://github.com/git/git/blob/master/contrib/completion/git-completion.bash | |
GIT_COMPLETION_FILE="/usr/local/git/current/share/git-core/git-completion.bash" | |
GIT_PROMPT_FILE="/usr/local/git/current/share/git-core/git-prompt.sh" | |
# Git tab-completion | |
if [ -f ${GIT_COMPLETION_FILE} ]; then | |
. ${GIT_COMPLETION_FILE} | |
fi | |
# Stuff to create a basic prompt | |
# Color codes -- to add more, see https://misc.flogisoft.com/bash/tip_colors_and_formatting | |
GREEN='\[\e[32m\]' | |
CYAN='\[\e[36m\]' | |
YELLOW='\[\e[33m\]' | |
RED='\[\e[31m\]' | |
LTGREEN='\[\e[92m\]' | |
LTCYAN='\[\e[96m\]' | |
LTYELLOW='\[\e[93m\]' | |
LTRED='\[\e[91m\]' | |
LTGRAY='\[\e[37m\]' | |
RESET='\[\e[0m\]' | |
# Splitting out the parts of the prompt for maintainability | |
# To change the color of a part of the prompt, change its variable | |
# to one of the above | |
# user | |
PS1_USER="${LTGREEN}\u${RESET}" | |
# at-sign | |
PS1_AT="${LTRED}@${RESET}" | |
# host | |
PS1_HOST="${LTGREEN}\h${RESET}" | |
# current working directory (not full path) | |
PS1_DIR="${CYAN}\W${RESET}" | |
# Git prompt to show extra info when in a git repo | |
if [ -f ${GIT_PROMPT_FILE} ]; then | |
. ${GIT_PROMPT_FILE} | |
# Configure git-prompt | |
export GIT_PS1_SHOWDIRTYSTATE=true | |
export GIT_PS1_SHOWSTASHSTATE=true | |
export GIT_PS1_SHOWCOLORHINTS=true | |
export GIT_PS1_SHOWUNTRACKEDFILES=true | |
# Create the git prompt element of the prompt | |
PS1_GIT_STATUS="${YELLOW}\$(__git_ps1)${RESET}" | |
# Build up the real prompt | |
export PS1="[${PS1_USER}${PS1_AT}${PS1_HOST} ${PS1_DIR}]${PS1_GIT_STATUS}\$ " | |
else # if you don't have git-prompt.sh in the path | |
export PS1="[${PS1_USER}${PS1_AT}${PS1_HOST} ${PS1_DIR}]\$ " | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment