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

files.profile Maven / Gradle / Ivy

The newest version!
# Stool shell code

__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
}

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

__stageLinked() {
  local home
  if [ "x${STOOL_HOME}" != "x" ]; then
    home=$STOOL_HOME
  else
    home=$HOME/.stool
  fi
  local found=$(find -L $home/backstages -maxdepth 1 -samefile $1/.backstage -print 2>/dev/null)
  if [ "x$found" != "x" ] ; then
    echo "0"
  else
    echo "1"
  fi
}

if [ "x$BASH" != "x" ] ; then
    if [ -z "${STOOL_NO_PROMPT}" ] ; then
        if [ -z ${STOOL_OLD_PROMPT_COMMAND} ] ; then
            export STOOL_OLD_PROMPT_COMMAND=${PROMPT_COMMAND}
            __stoolPromptUpdate() {
                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")"
                  if [ $(__stageLinked $__STAGE_DIR) != "0" ] ; then
                    export __STAGE_DIR=""
                  fi
                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="\$(__stageIndicator \${__STAGE_DIR})${STOOL_PS1}"
                # else
                #   already initialized, nothing to do
                fi
            }
            PROMPT_COMMAND=__stoolPromptUpdate
        # else
        #   Already initialized, do nothing
        #   CAUTION:
        #   Initializing again 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