Skip to content

Commit

Permalink
Git prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronryank committed Nov 9, 2017
1 parent 8e38703 commit a4b1f28
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 2 deletions.
15 changes: 15 additions & 0 deletions .bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export PATH=$PATH:./
alias ..='cd ..'

# set colors
CBlack="\[\e[30m\]"
CBBlack="\[\e[1;30m\]"
CRed="\[\e[31m\]"
CBRed="\[\e[1;31m\]"
CGreen="\[\e[32m\]"
Expand All @@ -22,6 +24,19 @@ CCyan="\[\e[36m\]"
CBCyan="\e[\1;36m\]"
CReset="\[\e[0m\]"

BGRed="\[\e[41m\]"
BGBRed="\[\e[1;41m\]"
BGGreen="\[\e[42m\]"
BGBGreen="\[\e[1;42m\]"
BGYellow="\[\e[43m\]"
BGBYellow="\[\e[1;43m\]"
BGBlue="\[\e[44m\]"
BGBBlue="\[\e[1;44m\]"
BGPurple="\[\e[45m\]"
BGBPurple="\[\e[1;45m\]"
BGCyan="\[\e[46m\]"
BGBCyan="\e[\1;46m\]"

# test color setup (pretty)
__test_colors_prompt ()
{
Expand Down
70 changes: 70 additions & 0 deletions git-prompt.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# repo@branch (HEAD) files changed

# set the prompt command
PROMPT_COMMAND=__prompt_command

# yes
export PATH=$PATH:./
alias ..='cd ..'

# set colors
CBlack="\[\e[30m\]"
CBBlack="\[\e[1;30m\]"
CRed="\[\e[31m\]"
CBRed="\[\e[1;31m\]"
CGreen="\[\e[32m\]"
CBGreen="\[\e[1;32m\]"
CYellow="\[\e[33m\]"
CBYellow="\[\e[1;33m\]"
CBlue="\[\e[34m\]"
CBBlue="\[\e[1;34m\]"
CPurple="\[\e[35m\]"
CBPurple="\[\e[1;35m\]"
CCyan="\[\e[36m\]"
CBCyan="\e[\1;36m\]"
CReset="\[\e[0m\]"

BGRed="\[\e[41m\]"
BGBRed="\[\e[1;41m\]"
BGGreen="\[\e[42m\]"
BGBGreen="\[\e[1;42m\]"
BGYellow="\[\e[43m\]"
BGBYellow="\[\e[1;43m\]"
BGBlue="\[\e[44m\]"
BGBBlue="\[\e[1;44m\]"
BGPurple="\[\e[45m\]"
BGBPurple="\[\e[1;45m\]"
BGCyan="\[\e[46m\]"
BGBCyan="\e[\1;46m\]"

# test color setup (pretty)
__test_colors_prompt ()
{
PS1=""
PS1+="${CRed}red${CReset} "
PS1+="${CGreen}green${CReset} "
PS1+="${CYellow}yellow${CReset} "
PS1+="${CBlue}blue${CReset} "
PS1+="${CPurple}purple${CReset} "
PS1+="${CCyan}cyan${CReset} "
}

# set up PS1
__prompt_command ()
{
PS1="\n"

local isgit=$(git rev-parse --git-dir --is-inside-git-dir --is-bare-repository --is-inside-work-tree --short HEAD 2>/dev/null)
local gitdir=$(git rev-parse --git-dir)

if [ -z "$isgit" ]; then
PS1+="nogit ${CBBlue}\w${CReset} ${CGreen}\s\$${CReset} "
else
if [ $(cat ${gitdir}/description) != "Unnamed repository; edit this file 'description' to name the repository." ]; then
PS1+="${CGreen}$(cat ${gitdir}/description)${CReset}${CPurple}@${CReset}"
fi
PS1+="${CBBlack}$(__git_ps1 '%s')${CReset} "
PS1+="${CBYellow}($(git show-ref -s12))${CReset} "
PS1+="${CBRed}$(git status -s | grep -c '')${CReset} "
fi
}
4 changes: 2 additions & 2 deletions simple-info.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# prompt skeleton file
# exit code, time, directory, git branch, $/#

# set the prompt command
PROMPT_COMMAND=__prompt_command
Expand Down Expand Up @@ -93,4 +93,4 @@ __prompt_command ()
# \W current directory name
# \! command number
# \@ pretty time
# \$ $ or #
# \$ $ or #

0 comments on commit a4b1f28

Please sign in to comment.