Skip to content

Instantly share code, notes, and snippets.

@automagicaly
Last active September 5, 2018 20:09
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save automagicaly/1298a845759432bf84a8718993bdfb59 to your computer and use it in GitHub Desktop.
Save automagicaly/1298a845759432bf84a8718993bdfb59 to your computer and use it in GitHub Desktop.
git branch on command line
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
#############################################
# Functions
#############################################
get_git_branch(){
# Based on: http://stackoverflow.com/a/13003854/170413
local branch
if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then
if [[ "$branch" == "HEAD" ]]; then
branc='detached* '
fi
symbol=$'\ue725'
#git_branch="($symbol $branch) "
git_branch="($branch) "
else
git_branch=""
fi
}
#############################################
# Configs
#############################################
# swap cap and esc
setxkbmap -option "caps:swapescape"
#############################################
# Exports
#############################################
PROMPT_COMMAND="get_git_branch; $PROMPT_COMMAND"
export PS1="\W \[\e[33m\]\$git_branch\[\e[32m\]➤\[\e[0m\] "
PATH=$HOME/.local/bin:$PATH
export PATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment