From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22376 invoked by alias); 7 Mar 2015 04:19:39 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 34672 Received: (qmail 28544 invoked from network); 7 Mar 2015 04:19:28 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=x-sasl-enc:date:from:to:cc:subject :message-id:references:mime-version:content-type:in-reply-to; s= mesmtp; bh=IBxxAZ3i5ITYSZzF+XhM25Ars9U=; b=ewMtzXp8ixGG4VvSAII8H TO4sGyexyMcdu1DU5NwYRalhyxwEDtJTkQydeTmcxMeo7xX+yY0ICcqwgDrwwuQi NWMH/PrsF+bklSt4Iw7kh7fbaLvvyaRT+EKuy4RdnY9xS4ZHgqA5Mzyr3ZFJ53K8 eSk79YurfAp3RNOzatQ3Mc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=x-sasl-enc:date:from:to:cc:subject :message-id:references:mime-version:content-type:in-reply-to; s= smtpout; bh=IBxxAZ3i5ITYSZzF+XhM25Ars9U=; b=JvKR8Xpq8vleFr54Q+dR 5n6qE4AFFU4sq0FDZEc9atLQfOJ7xAjQxpILp+Y4cbC/a9XeECcpWrhbgM+X9FNO i3Y3Coi6BjXITUdwcrxeDKVVLBOU2tLm0fF8pV0tR2BK5nX1nK2QsMY/qTLjWeVG p3zg+SQbExjXuw3Hl4VnM2k= X-Sasl-enc: VaoHSWzbwscyIjzOOViAh0+HuDK4gdFbFs38H7RJYpHl 1425701966 Date: Sat, 7 Mar 2015 04:19:24 +0000 From: Daniel Shahaf To: Andrew Janke Cc: zsh-workers@zsh.org Subject: Re: FAQ title bar answer using chpwd() Message-ID: <20150307041924.GD2206@tarsus.local2> References: <54FA731B.8050800@pobox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <54FA731B.8050800@pobox.com> User-Agent: Mutt/1.5.21 (2010-09-15) 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