1

SOLUTION: There was a bug in the program. Instructions below with sleep helped me find it.

Does anyone know how to do this?

I tried the following, but the backslash escape before a space did not work as expected with xterm or Apple Terminal:

  SEARCH=' '
  REPLACE='_' # XXX fix display of spaces
  PWD_SPACE="${PWD//$SEARCH/$REPLACE}"

Full context:

  # replace spaces with percent sign for pathnames
  # with spaces
  SEARCH=' '
  REPLACE='%20'
  PWD_URL="${PWD//$SEARCH/$REPLACE}"

  SEARCH=' '
  REPLACE='_' # XXX fix display of spaces
  PWD_SPACE="${PWD//$SEARCH/$REPLACE}"

  if [ -n "$KSH_VERSION" ]; then
    TMP_PWD=$(shortpath $PWD_SPACE)
  else
    TMP_PWD=$(shortpath_bash_trunc $PWD_SPACE)
  fi

  if [ -t 0 ]; then 
    if [ "$TERM_PROGRAM" == "Apple_Terminal" ]; then
       #titlebar "${SYS} : ${PWD##*/}"
       $ECHOE "\033]0;\007"
       $ECHOE "\033]6;\007"
       $ECHOE "\033]7;file:$PWD_URL\007"
    elif [[ "$TERM" == *"xterm"* ]]; then
       $ECHOE "\033]0;$TMP_PWD\007"
       $ECHOE "\033]6;\007"
       $ECHOE "\033]7;\007"
    fi
  fi
4
  • 1
    xterm has no problems with spaces in titles, and has no need to change spaces into %20. Do you see the correct results with printf '\033]0;%s\007' "$PWD"' ; sleep 30 - at least for 30 seconds? – icarus Oct 28 '19 at 6:10
  • why the sleep? would that not delay the entire shell read, eval, print loop? – Nick Oct 28 '19 at 14:14
  • icarus: this advice did you work? have you personally tested? – Nick Oct 28 '19 at 14:20
  • 1
    The point of the sleep is to stop either PS1 or PROMPT_COMMAND or something like them changing the title again immediately after the printf has set it, leading you to think it hadn't worked. Yes I tested it for an xterm. – icarus Oct 28 '19 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.