#!/bin/bash

if [[ $RUNNING_ON_GK ]]; then

  if [[ $BASH_VERSION ]]; then
    declare GKC_PROMPT_END="$(echo '\001\e[1314~\002')"
    if [[ -z $BASH_OLD_PS1 ]]; then
      export BASH_OLD_PS1=$PS1
    fi

    function __gkc_prompt() {
      pwd="$(echo "$PWD" | sed 's/ /\\ /g; s/(/\\(/g; s/)/\\)/g')"
      gkc setCwd "$pwd"
      export PS1="${BASH_OLD_PS1}${GKC_PROMPT_END}"
    }
    PROMPT_COMMAND=__gkc_prompt
  fi

  function bash() {
    unset PS1
    command bash --rcfile "$BASHRC" "$@"
  }

  unalias gkc 2>/dev/null
fi
