# bug #380229
${str:<beginfold id='1'>$((</beginfold id='1'>${#a[1]}+1<endfold id='1'>))</endfold id='1'>}

# from http://zshwiki.org/home/examples/hardstatus
function title <beginfold id='2'>{</beginfold id='2'>
  <beginfold id='3'>if</beginfold id='3'><beginfold id='1'> [[</beginfold id='1'> $TERM == "screen"<endfold id='1'> ]]</endfold id='1'>; then
    # Use these two for GNU Screen:
    print -nR $'\033k'$1$'\033'\\

    print -nR $'\033]0;'$2$'\a'
  elif<beginfold id='1'> [[</beginfold id='1'> $TERM == "xterm" || $TERM == "rxvt"<endfold id='1'> ]]</endfold id='1'>; then
    # Use this one instead for XTerms:
    print -nR $'\033]0;'$*$'\a'
  <endfold id='3'>fi</endfold id='3'>
<endfold id='2'>}</endfold id='2'>

function precmd <beginfold id='2'>{</beginfold id='2'>
  title zsh "$PWD"
<endfold id='2'>}</endfold id='2'>

function preexec <beginfold id='2'>{</beginfold id='2'>
  emulate -L zsh
  local -a cmd; cmd=(${(z)1})
  title $cmd[1]:t "$cmd[2,-1]"
<endfold id='2'>}</endfold id='2'>

caption always "%3n %t%? (%u)%?%?: %h%?"

preexec() <beginfold id='2'>{</beginfold id='2'>
  emulate -L zsh
  local -a cmd; cmd=(${(z)1})             # Re-parse the command line

  # Construct a command that will output the desired job number.
  <beginfold id='4'>case</beginfold id='4'> $cmd[1] in
      fg<beginfold id='5'>)</beginfold id='5'>
        <beginfold id='3'>if</beginfold id='3'> <beginfold id='1'>((</beginfold id='1'> $#cmd == 1 <endfold id='1'>))</endfold id='1'>; then
          # No arguments, must find the current job
          cmd=(builtin jobs -l %+)
        else
          # Replace the command name, ignore extra args.
          cmd=(builtin jobs -l ${(Q)cmd[2]})
        <endfold id='3'>fi</endfold id='3'><endfold id='5'>;;</endfold id='5'>
       %*<beginfold id='5'>)</beginfold id='5'> cmd=(builtin jobs -l ${(Q)cmd[1]})<endfold id='5'>;;</endfold id='5'> # Same as "else" above
       exec<beginfold id='5'>)</beginfold id='5'> shift cmd;& # If the command is 'exec', drop that, because
          # we'd rather just see the command that is being
          # exec'd. Note the ;& to fall through.
       *)  title $cmd[1]:t "$cmd[2,-1]"    # Not resuming a job,
          return<endfold id='5'>;;</endfold id='5'>                        # so we're all done
      <endfold id='4'>esac</endfold id='4'>

  local -A jt; jt=(${(kv)jobtexts})       # Copy jobtexts for subshell

  # Run the command, read its output, and look up the jobtext.
  # Could parse $rest here, but $jobtexts (via $jt) is easier.
  $cmd >><beginfold id='6'>(</beginfold id='6'>read num rest
          cmd=(${(z)${(e):-\$jt$num}})
          title $cmd[1]:t "$cmd[2,-1]"<endfold id='6'>)</endfold id='6'> 2>/dev/null
<endfold id='2'>}</endfold id='2'>

function precmd() <beginfold id='2'>{</beginfold id='2'>
  title zsh "$IDENTITY:$(print -P %~)"
<endfold id='2'>}</endfold id='2'>

"%{^[]0;screen ^En (^Et) ^G%}"

print -nRP $'\033k%(!.#\[.)'$1$'%'$\(\(20\-${#1}\)\)$'< ..<'${${2:+${${${@[${#${@}}]##/*/}/#/ }:-}}//\"/}$'%(!.\].)\033'\\
