# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoredups

# append to the history file, don't overwrite it
shopt -s histappend

shopt -s checkwinsize

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# multi-line commands in history
shopt -q -s cmdhist

# correct dir spellings
shopt -q -s cdspell

# verify history command before execution
shopt -s  histverify

# prevent first exit if running jobs exists
shopt -s checkjobs

# try to make host completion on @
shopt -s hostcomplete

#save time in history
export HISTTIMEFORMAT='%d.%m.%Y %H:%M:%S  '

# enable color support of ls and also add handy aliases
if [ "$TERM" != "dumb" ]; then
    eval "`dircolors -b`"
    alias ls='ls --color=auto'
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi

if [ "$QLOUD_APPLICATION" ]; then
    case "$TERM" in
        xterm*)
            export PS1='\[\e[1;31m\]$(echo "["${?}"]" | sed "s/\\[0\\]//")\[\033[33;1m\][tank]'" \[\033[38;5;177m\]$QLOUD_APPLICATION.\[\033[38;5;150m\]$QLOUD_ENVIRONMENT.\[\033[38;5;172m\]$QLOUD_COMPONENT.\[\033[38;5;248m\]\h\[$(tput sgr0)\]: \w# " ;;
        dumb*)
            export PS1="[tank] $QLOUD_APPLICATION.$QLOUD_ENVIRONMENT.$QLOUD_COMPONENT\h: \w#" ;;
        *)
            PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' ;;
    esac

    PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND ; }"'echo -ne "\033]0;[tank] $QLOUD_APPLICATION.$QLOUD_ENVIRONMENT.$QLOUD_COMPONENT\007"'
fi

if [ "$DEPLOY_PROJECT_ID" ]; then
    case "$TERM" in
        xterm*)
            export PS1='\[\e[1;31m\]$(echo "["${?}"]" | sed "s/\\[0\\]//")\[\033[33;1m\][tank]'" \[\033[38;5;177m\]$DEPLOY_PROJECT_ID.\[\033[38;5;150m\]$DEPLOY_STAGE_ID.\[\033[38;5;172m\]$DEPLOY_POD_TRANSIENT_FQDN.\[\033[38;5;248m\]\h\[$(tput sgr0)\]: \w# " ;;
        dumb*)
            export PS1="[tank] $DEPLOY_PROJECT_ID.$DEPLOY_STAGE_ID.$DEPLOY_POD_TRANSIENT_FQDN\h: \w#" ;;
        *)
            PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' ;;
    esac

    PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND ; }"'echo -ne "\033]0;[tank] $DEPLOY_PROJECT_ID.$DEPLOY_STAGE_ID.$DEPLOY_POD_TRANSIENT_FQDN\007"'
fi

msg="\n\033[31;1mY\033[37mandex.\033[32mTank\033[0m docker image
    Tank version:   $(yandex-tank --version 2> /dev/null)
    General docs:   https://yandextank.readthedocs.io/en/latest/
    Internal docs:  https://wiki.yandex-team.ru/NagruzochnoeTestirovanie/#nashinstrumentarijjidokumentacija
    Telegram support: https://t.me/joinchat/AAAAAD-zGT5mLOoGc_N-kw

To enable TUI console output add to the config:\n\nconsole:\n  enabled: true\n\n"

printf "$msg" > /dev/stderr
