All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.home.shell.rc Maven / Gradle / Ivy

There is a newer version: 4.0.3
Show newest version
# Stool shell code

${{setenv.rc}}

__stageName() {
  grep \"name\" "$1"/.backstage/config.json | cut -d':' -f2 | cut -d'"' -f2
}

__stageDir() {
  local dir="$1"
  while [ "${dir}" != "/" ] ; do
    if [ -d "${dir}"/.backstage ] ; then
      echo -n "${dir}"
      return
    fi
    dir="$(dirname "${dir}")"
  done
  echo -n ""
  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
}

__stageIndicator() {
  local stage="$1"
  if [ "x${stage}" != "x" ] ; then
    local name="$(__stageName "${stage}")"
    echo -n "{${name}} "
  # else
  #   no stage -> no indicator
  fi
}

if [ "x$BASH" != "x" ] ; then
    if [ -z "${STOOL_NO_PROMPT}" ] ; then
        if [ -z ${STOOL_OLD_PROMPT_COMMAND} ] ; then
            . ${{stool.home}}/bash.complete
            export STOOL_OLD_PROMPT_COMMAND=${PROMPT_COMMAND}
            __stoolPromptUpdate() {
                local NO_COLOR="\033[0m"
                eval "${STOOL_OLD_PROMPT_COMMAND}"
                local dir=$(pwd)
                if [ "x${dir}" != "x${__STAGE_DIR}" ] ; then
                  # cwd has changed, update stage dir
                  export __STAGE_DIR="$(__stageDir "$dir")"
                fi
                if [ "x${STOOL_PS1}" = "x" ] ; then
                  # We're called for the first time: setup PS1.
                  # Note that we have to delay this setup until the first PROMPT_COMMAND invocation to give users a chance to customize
                  # PS1 settings (e.g. in their ~/.bashrc for interactive shells)
                  export STOOL_PS1="${PS1}"
                  PS1="\[\$(__stageIndicatorColor \${__STAGE_DIR})\]\$(__stageIndicator \${__STAGE_DIR})\[${NO_COLOR}\]${STOOL_PS1}"
                # else
                #   already initialized, nothing to do
                fi
            }
            PROMPT_COMMAND=__stoolPromptUpdate
        # else
        #   CAUTION: already initialized, do nothing, it would cause an infinite loop
        #            because __stoolPromptCommand calls itself ::stoolPromptCommand from $STOOL_OLD_PROMPT_COMMAND
        fi
    # else
    #   do nothing, the user does not want stool prompt
    fi
fi




© 2015 - 2024 Weber Informatics LLC | Privacy Policy