0

The following bash script was posted in this thread as a means of setting an ST (terminal window's) title in DWM (X window manager). While adding this segment to by .bashrc has the desired result, I would like to be able to use this in zsh.

set_title(){
   local cmd=$BASH_COMMAND
   case $cmd in
   fg) cmd=$(jobs %); cmd=${cmd##"${cmd%  *}  "};;
   fg\ *|%*) cmd=$(jobs "${cmd#fg }"); cmd=${cmd##"${cmd%  *}  "};;
   esac
   printf '\e]2;%s\e\\' "${TERM%%-*} ${cmd//[$'\e\a']/#}"
}
trap set_title DEBUG

I have already tried calling it as a bash script in my .zshrc, however this does not change the window title as expected. Any help converting this for use in zsh would be appreciated.

1 Answer 1

1

Could be something like:

TRAPDEBUG() {
  [[ $zsh_eval_context[1] = toplevel ]] || return
  local cmd=$ZSH_DEBUG_CMD
  case $cmd in
    (fg)
      cmd=$jobtexts[${(k)jobstates[(r)*:+:*]}];;
    (('fg '|%)<->)
      cmd=$jobtexts[${(M)cmd%%<->}];;
  esac
  printf '\e]2;%s\e\\' "${TERM%%-*} ${cmd//[$'\e\a']/#}"
}

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.