### Prompts:

# PROMPT='%m%# '    # default prompt
# RPROMPT=' %~'     # prompt for right side of screen


## history number ??
# typeset PROMPT_BANG=1
# setopt PROMPT_BANG
# setopt PROMPT_PERCENT
# PS1=$'%{\e[1;31m%}<the rest of your prompt here>%{\e[0m%}'

# yellow='%{\e[1;33;40m%}'
# red='\e[01;31;40m'

# NO_BGJOBS=0

# precmd ()  {
#   NO_BGJOBS=`ps -g  $$ | wc -l`
#   let "NO_BGJOBS=NO_BGJOBS - 4"
# }
# #  echo "precmd $NO_BGJOBS"


# echo "setting prompt $under_xterm"
# xtitle    read prompt
if under_xterm;
    then
#    echo "setting prompt under_xterm"
#
# (red (hostname)
#      (username)
    setopt PROMPT_SUBST
    # this contains the xterm title setting ?


    # calculate `zsh_title_chroot' variable:
    if [[ -z ${SUDO_USER} ]]     # this is set by sudo
    then
        sudo=""
    else
        sudo="${SUDO_USER}->"
        if [[ $SUDO_COMMAND =~ "^/usr/sbin/chroot" ]]
        then
            zsh_title_chroot="${SUDO_COMMAND##/usr/sbin/chroot }@@"
        else
            zsh_title_chroot=""
        fi
    fi


    # `container':
    code=$(lsb_release --short --codename)
    if [ $code != "buster" ]
    then
        zsh_title_chroot="($code)"
    fi


    # "" ... parameter and command substitution occur,
    # %n username,                          %m hostname        %f stop colour
    #    %B bold %F fg color
    # $'....'  is processed the same way as the string arguments of the print builtin, and the resulting string
    # is considered to be entirely quoted.

    # this is dynamically substituted

    PROMPT=$'%B%F{green}${sudo}%n@'
    PROMPT+=$'%F{blue}${zsh_title_chroot}'
    PROMPT+=$'%F{yellow}%m:%F{red}%5c\ \$NO_BGJOBS%f'
    PROMPT+=$'%U%?%u$ %_'
    # title:
    PROMPT+=$'%{\e]2;zsh ${sudo}%n@${zsh_title_chroot}%m:$NO_BGJOBS%d%}%b'


#    $'%{\e[1;33;40m%}%n@%{\e[1;32;40m%}%m:%{\e[01;31;40m%}%5c\ \$NO_BGJOBS%{\e[0m%}%U%?%u$ %_%{\e]2;zsh %n@%m:$NO_BGJOBS%d%}'

    RPS1="%B<%h %* %l%b\$NO_BGJOBS"


#    PROMPT="%n@%m: %{${fg[red]}%}%~%{${fg[white]}%}\$ "
#    PROMPT="%n@%m: %{${fg[red]}%}%~%{${fg[white]}}%$ "
#    PROMPT="%n@%m: %{${fg[red]}%~${fg[white]}%} "
else
##
    PROMPT=$'%{\e[1;33;40m%}%n@%m:%{\e[01;31;40m%}%5c\ '
fi


# tramp/ M-x shell
if [ "$TERM" = "dumb" ] ;
then
  echo $TERM
  PROMPT="%n@%m:%5c "
  # PROMPT="%h>"
fi



if false;
then
    if [[ ! -z $INSIDE_EMACS ]]; then
        #PROMPT="$'%n@%m:%5c\ %U%?%u$ %_%{]2;zsh %n@%m:'"
        PROMPT="%h>"
    else
        setopt  PROMPT_SUBST
        RPS1="%B<%h %* %l%b\$NO_BGJOBS"
    fi
fi # false


#  %N
# PROMPT=$"%{\e[1;33;40m%}%n@%m:\e[01;31;40m%5c\ %{\e[0m%}%U%?%u$ %_"
# PROMPT='(!)$%{\e[1;33;40m%}%n@%m:\e[01;31;40m%5c\ %{\e[0m%}%U%?%u\$ %_'
# screen ??
# xterm: "]2;$1"
# %0(w,domenica,)
