+## Bash Prompt
+# Shell prompts are not just eye-candy they should show what you need
+# to know most and they should do it in such a way that you don't
+# even notice. This sets up a two-line prompt that reminds you that
+# you're currently logged in as a pkgusr, which pkgusr, which group
+# if that pkgusr has multiple groups and you've newgrp'd, if you're
+# inside a git repo display the branch and other pertinent info, if
+# the previous command had a non-zero exit display the code, display
+# the current time, and current working directory (truncated to
+# prevent "prompt-creep"). Colourised so that often you won't even
+# need to read it to take in the info.
+
+# Colours (doesn't include black (30))
+CO="\[\e[0m\]" # Colour Off
+RED="\[\e[0;31m\]" # Red
+GRN="\[\e[0;32m\]" # Green
+YEL="\[\e[0;33m\]" # Yellow
+BLU="\[\e[0;34m\]" # Blue
+MAG="\[\e[0;35m\]" # Magenta
+CYN="\[\e[0;36m\]" # Cyan
+WTE="\[\e[0;37m\]" # White
+# Bold (bright)
+BRED="\[\e[1;31m\]" # Bold Red
+BGRN="\[\e[1;32m\]" # Bold Green
+BYEL="\[\e[1;33m\]" # Bold Yellow
+BBLU="\[\e[1;34m\]" # Bold Blue
+BMAG="\[\e[1;35m\]" # Bold Magenta
+BCYN="\[\e[1;36m\]" # Bold Cyan
+BWTE="\[\e[1;37m\]" # Bold White
+
+# Some pkgusrs may use extra groups so the prompt should reflect that.
+# This function adds the group name to the prompt if necessary.
+_sg()
+{
+ [[ $(id -gn) != $(id -un) ]] && echo "$WTE:$CYN$(id -gn)"
+}
+
+# This function, called from $PROMPT_COMMAND, puts all the pieces of
+# the prompt together.
+make_prompt()
+{
+ rc=$? # Return code from previous cmd
+ [[ $rc -gt 0 ]] && prc="$BWTE[$BRED$rc$BWTE] " || prc=
+
+ local sg gitp p
+
+ # Using a subgroup
+ sg=$(_sg)
+
+ # Git
+ [[ -f /etc/pkgusr/git-prompt ]] && gitp=$(__git_ps1) || gitp=
+
+ p="pkgusr"
+
+ # Build up the PS1
+ PS1="$BWTE[$WTE$p $BWTE($CYN\u$sg$BWTE)]" # [pkgusr (usr:grp)]
+ PS1+="$CO" # reset to not mess up git prompt
+ PS1+="$gitp" # (gitstuff)
+ PS1+="\n$prc$BYEL\A$WTE:$BMAG\w$BWTE>$CO " # [rc]TIME:CWD>
+}
+
+# The git goodies
+[[ -f /etc/pkgusr/git-prompt ]] && source /etc/pkgusr/git-prompt
+GIT_PS1_SHOWDIRTYSTATE=true
+GIT_PS1_SHOWSTASHSTATE=true
+GIT_PS1_SHOWUNTRACKEDFILES=true
+GIT_PS1_SHOWUPSTREAM=auto
+GIT_PS1_DESCRIBE_STYLE=branch
+GIT_PS1_SHOWCOLORHINTS=true
+
+# So the prompt doesn't fly off the right-hand edge of the screen
+# when you're down a long directory tree.
+PROMPT_DIRTRIM=4
+
+# Finally, make the prompt happen!
+PROMPT_COMMAND=make_prompt
+
+
+## Pretty colours for ls