templates.home.shell.rc Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of main Show documentation
Show all versions of main Show documentation
Stool's main component. Java Library, cli, setup code.
# Stool shell code
${{setenv.rc}}
stageIndicator() {
local NO_COLOR="\033[0m"
local dir="$(pwd)"
local name="$(stageName "$dir")"
if [ "$name" != none ] ; then
echo -e -n $(stageIndicatorColor "$dir")
echo -n "{$name} "
echo -e -n ${NO_COLOR}
# else
# no stage -> no indicator
fi
}
stageName() {
local dir="$1"
while [ "$dir" != "/" ] ; do
if [ -d "$dir"/.backstage ] ; then
local name="$(grep \"name\" "$dir"/.backstage/config.json | cut -d':' -f2 | cut -d'"' -f2)"
echo -n "${name}"
return
fi
dir="$(dirname "$dir")"
done
echo -n none
return
}
stageIndicatorColor() {
local RED="\033[0;31m"
local BLUE="\033[44;1;37m"
local dir="$1"
if [ ! -e "$dir" ] ; then
echo -n -e "$BLUE"
else
if [ `uname` = Darwin ] ; then
local fmt=-f
else
local fmt=--format
fi
if [ $(id -u) = "$(stat -L $fmt %u "$dir")" ] ; then
echo -n ""
else
echo -n -e "$RED"
fi
fi
}
if [ "x$BASH" != "x" ] ; then
if [ -z $STOOL_OLD_PROMPT_COMMAND ] ; then
. ${{stool.home}}/bash.complete
export STOOL_OLD_PROMPT_COMMAND=$PROMPT_COMMAND
stoolPromptCommand() {
eval "$STOOL_OLD_PROMPT_COMMAND"
stageIndicator
}
PROMPT_COMMAND=stoolPromptCommand
# else
# CAUTION: already initialized, I'd cause an infinite loop because stoolPromptCommand calls itself stoolPromptCommand from $STOOL_OLD_PROMPT_COMMAND
fi
fi