#!/bin/bash

if [[ $RUNNING_ON_GK ]]; then

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

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

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

  unalias gk 2>/dev/null
fi
