# 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.
+# prevent "prompt-creep"), and set the Xterm title. 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
[[ $(id -gn) != $(id -un) ]] && echo "$WTE:$CYN$(id -gn)"
}
+# Set the Xterm title
+_settitle()
+{
+ [[ "$TERM" = "xterm" ]] && echo "\[\e]2;PKG(\u)\a\]"
+}
+
# 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
+ # Normally you'd define your local vars at the top of the function,
+ # well I normally do, but in this case it will overwrite the value
+ # of '$?' so we need to preserve it first.
+ local gitp p prc sg title
+
+ # Previous cmd's return code, but only if it was non-zero
+ [[ $rc -gt 0 ]] && prc="$BWTE[$BRED$rc$BWTE] " || prc=
# Using a subgroup
sg=$(_sg)
p="pkgusr"
+ # Xterm title
+ title=$(_settitle)
+
# 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>
+ PS1+="$title" # Xterm title
}
# The git goodies