Changes to bash prompt calculation/display.
This commit is contained in:
parent
716793265d
commit
0e830afa2b
63
.bashrc
63
.bashrc
@ -1,33 +1,66 @@
|
|||||||
prompt_command() {
|
# requires the following utilities:
|
||||||
retval=$?
|
# git
|
||||||
branch="";
|
# GNU coreutils (for realpath)
|
||||||
clean="";
|
# BSD basename
|
||||||
|
|
||||||
numcolor="\[\e[0;33m\]"
|
prompt_command() {
|
||||||
red="\[\e[0;31m\]"
|
local retval=$?
|
||||||
sepcolor="\[\e[1;30m\]"
|
local branch="";
|
||||||
yellow="\[\e[0;33m\]"
|
local clean="";
|
||||||
brightyellow="\[\e[1;33m\]"
|
local workingDir="";
|
||||||
brightblue="\[\e[1;34m\]"
|
|
||||||
default="\[\e[0m\]"
|
local numcolor="\[\e[0;33m\]"
|
||||||
green="\[\e[0;32m\]"
|
local red="\[\e[0;31m\]"
|
||||||
|
local sepcolor="\[\e[1;30m\]"
|
||||||
|
local yellow="\[\e[0;33m\]"
|
||||||
|
local brightyellow="\[\e[1;33m\]"
|
||||||
|
local brightblue="\[\e[1;34m\]"
|
||||||
|
local default="\[\e[0m\]"
|
||||||
|
local green="\[\e[0;32m\]"
|
||||||
|
|
||||||
if [[ $retval != 0 ]]; then
|
if [[ $retval != 0 ]]; then
|
||||||
numcolor="\[\e[1;41;33m\]"
|
numcolor="\[\e[1;41;33m\]"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# If we're in a git repo
|
||||||
if git branch &>/dev/null; then
|
if git branch &>/dev/null; then
|
||||||
|
|
||||||
|
local repoDir=`git rev-parse --show-toplevel`
|
||||||
branch="$green$(git branch 2>/dev/null | grep \* | cut -d ' ' -f 2-)"
|
branch="$green$(git branch 2>/dev/null | grep \* | cut -d ' ' -f 2-)"
|
||||||
clean=$(git status | grep clean)
|
clean=$(git status | grep clean)
|
||||||
if [ -z "$clean" ]; then clean="${red}✗"; else clean=""; fi
|
# if [ -z "$clean" ]; then clean="${red}✗"; else clean=""; fi
|
||||||
|
if [ -z "$clean" ]; then clean="${red}++"; else clean=""; fi
|
||||||
|
|
||||||
|
workingDir="$(basename ${repoDir})/"
|
||||||
|
workingDir+=`realpath "--relative-to=${repoDir}" "$(pwd)"`
|
||||||
|
else
|
||||||
|
workingDir=`pwd`
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PS1="${debian_chroot:+($debian_chroot)}$numcolor\!$red \u$sepcolor@${brightblue}\h${default}:${branch}${clean} $default\w$green\$${default} "
|
PS1="$numcolor\!$red \u$sepcolor@${brightblue}\h${default}:${branch}${clean} "
|
||||||
|
|
||||||
unset clean numcolor branch retval
|
# Add a linebreak if the branchname + working dir will make the line
|
||||||
|
# overly long
|
||||||
|
# echo "Branch and working dir length is $(expr ${#branch} + ${#workingDir})"
|
||||||
|
# echo "COLUMNS is $COLUMNS. COLUMNS / 3 is $(expr $COLUMNS / 3)"
|
||||||
|
if (( $(expr ${#branch} + ${#workingDir}) > $(expr $COLUMNS / 3) )); then
|
||||||
|
PS1="\r\n${PS1}\r\n"
|
||||||
|
fi
|
||||||
|
|
||||||
|
PS1+="$default$workingDir"
|
||||||
|
|
||||||
|
# If the working dir is itself too long, put it on it's own line and put
|
||||||
|
# the prompt below it.
|
||||||
|
if (( ${#workingDir} > $(expr $COLUMNS / 3) )); then PS1+="\r\n"; fi
|
||||||
|
|
||||||
|
PS1+="$green\$${default} "
|
||||||
|
|
||||||
|
# PS1="$numcolor\!$red \u$sepcolor@${brightblue}\h${default}:${branch}${clean} $default\w$green\$${default} "
|
||||||
}
|
}
|
||||||
|
|
||||||
PROMPT_COMMAND=prompt_command
|
PROMPT_COMMAND=prompt_command
|
||||||
|
|
||||||
eval "$(thefuck --alias fixit)"
|
eval "$(thefuck --alias fixit)"
|
||||||
set -o vi
|
set -o vi
|
||||||
|
|
||||||
|
source ~/.bash_aliases
|
||||||
|
Loading…
x
Reference in New Issue
Block a user