I try to make the title of my windows in GNU screen automatically equal to the path of the working directory PLUS the process running if there is one (e.g: npm start or vim file.js)

for that purpose I added these lines in my .zshrc :

precmd () {
  local action = action_to_define
  if [[ $TERM == screen* ]]; then
    printf -Pn '\ek%~ $action\e\\'

this send (somehow) the path as a title to screen (see this post)

and the variable action would print the running program if it exist

I tried local action= $(history | tail -1 | sed 's#[0-9 ]*##') because this select the prompt of the last command in the history (just like history !! would do if the option !! was recognized, which is not for some reason...)

and local action= $(ps -lr | tail -1 | sed 's#^.*:...##') because this select the command of the running process

but it doesn't works, as if the process was not captured neither by history or ps... maybe precmd run before the action is launched, so I tried other functions like preexec or zshaddhistory without any luck...

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.