zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Andrew Janke <janke@pobox.com>
Cc: zsh-workers@zsh.org
Subject: Re: FAQ title bar answer using chpwd()
Date: Sat, 7 Mar 2015 04:19:24 +0000	[thread overview]
Message-ID: <20150307041924.GD2206@tarsus.local2> (raw)
In-Reply-To: <54FA731B.8050800@pobox.com>

Andrew Janke wrote on Fri, Mar 06, 2015 at 22:40:11 -0500:
> Hi, ZSH workers,
> 
> I have a question about an answer in the ZSH FAQ. Is this the right
> list to ask about it?
> 
> http://zsh.sourceforge.net/FAQ/zshfaq03.html#l23
> 

Personally I'd have addressed zsh-users.

> Answer 3.6 suggests using chpwd() to emit terminal control sequences
> to update the title bar for Apple's Terminal.app. This probably
> isn't the right place to do it, because cd's can happen inside
> functions, pipelines, and so on whose output is going to be captured
> for use elsewhere. The terminal control sequences will contaminate
> the captured output instead of going to the terminal.
> 
> There's at least one place in the wild where this causes an issue,
> with Android development scripts:
> https://github.com/robbyrussell/oh-my-zsh/issues/3524
> 

We had a similar issue at Subversion: http://svn.apache.org/r1643793

> The prompt or other known user-interaction output points are
> probably the only safe place to emit terminal control sequences like
> this. So precmd() is probably a better choice than chpwd() for this.
> It seems like chpwd() should probably not be used to do anything
> that emits to stdout, in case it's being captured.
> 
> Should the FAQ answer be updated to reflect this?

Why is a chpwd() hook set within the context of the Android scripts in
the first place?  Is it because they get sourced instead of executed?
If so, they really should switch to the ssh-agent/gpg-agent model, of
[eval `script`] instead of [source 'script'].

In the meantime, they can do something like:
[ -n "$ZSH_VERSION" ] && cd() { builtin cd -s "$@" }

>

Incidentally, another possible fix would be to have the FAQ recommend to
have the control sequences be printed to the controlling terminal,
rather than to stdout.  That would cause a different problem: instead of
contaminating the output, the terminal title might be wrong if a script
did 'cd' and then exited without changing back to the interactive user's
directory, as in '(cd ..)'.

Cheers,

Daniel


  reply	other threads:[~2015-03-07  4:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-07  3:40 Andrew Janke
2015-03-07  4:19 ` Daniel Shahaf [this message]
2015-03-07  7:33   ` Bart Schaefer
2015-03-07  7:20 ` Bart Schaefer
2015-03-13  0:39   ` Lawrence Velázquez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150307041924.GD2206@tarsus.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=janke@pobox.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).