* FAQ title bar answer using chpwd()
@ 2015-03-07 3:40 Andrew Janke
2015-03-07 4:19 ` Daniel Shahaf
2015-03-07 7:20 ` Bart Schaefer
0 siblings, 2 replies; 5+ messages in thread
From: Andrew Janke @ 2015-03-07 3:40 UTC (permalink / raw)
To: zsh-workers
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
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
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?
Cheers,
Andrew
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: FAQ title bar answer using chpwd()
2015-03-07 3:40 FAQ title bar answer using chpwd() Andrew Janke
@ 2015-03-07 4:19 ` Daniel Shahaf
2015-03-07 7:33 ` Bart Schaefer
2015-03-07 7:20 ` Bart Schaefer
1 sibling, 1 reply; 5+ messages in thread
From: Daniel Shahaf @ 2015-03-07 4:19 UTC (permalink / raw)
To: Andrew Janke; +Cc: zsh-workers
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: FAQ title bar answer using chpwd()
2015-03-07 3:40 FAQ title bar answer using chpwd() Andrew Janke
2015-03-07 4:19 ` Daniel Shahaf
@ 2015-03-07 7:20 ` Bart Schaefer
2015-03-13 0:39 ` Lawrence Velázquez
1 sibling, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2015-03-07 7:20 UTC (permalink / raw)
To: Andrew Janke, zsh-workers
On Mar 6, 10:40pm, Andrew Janke wrote:
}
} http://zsh.sourceforge.net/FAQ/zshfaq03.html#l23
}
} 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.
If you've actually examined the FAQ example, you'll see
[[ -t 1 ]] || return
which means to do nothing if the standard output is not a terminal.
That's a perfectly reasonable solution to the issue described here:
} https://github.com/robbyrussell/oh-my-zsh/issues/3524
In short, the FAQ answer is correct and whoever created the chpwd to
which that issue refers, has coded it wrong.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: FAQ title bar answer using chpwd()
2015-03-07 4:19 ` Daniel Shahaf
@ 2015-03-07 7:33 ` Bart Schaefer
0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2015-03-07 7:33 UTC (permalink / raw)
To: zsh-workers; +Cc: Andrew Janke
On Mar 7, 4:19am, Daniel Shahaf wrote:
}
} We had a similar issue at Subversion: http://svn.apache.org/r1643793
OK, so the real problem is that
- there exists some software written for the user's shell to execute
- that software needs to change working directory
- the user is an idiot who has installed a chpwd function that always
prints to stdout
- this breaks the software and is reported as a bug to the developer.
Frankly I don't think any update to the zsh FAQ is going to eliminate
idiocy. The developer needs to either use "cd -q ..." if the shell is
known to be zsh, or to use "{ cd ... } >/dev/null" if zsh-ness for some
reason is not testable.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: FAQ title bar answer using chpwd()
2015-03-07 7:20 ` Bart Schaefer
@ 2015-03-13 0:39 ` Lawrence Velázquez
0 siblings, 0 replies; 5+ messages in thread
From: Lawrence Velázquez @ 2015-03-13 0:39 UTC (permalink / raw)
To: Bart Schaefer; +Cc: Andrew Janke, zsh-workers
On Mar 7, 2015, at 2:20 AM, Bart Schaefer <schaefer@brasslantern.com> wrote:
> If you've actually examined the FAQ example, you'll see
>
> [[ -t 1 ]] || return
>
> which means to do nothing if the standard output is not a terminal.
Would the FAQ code clean up properly after executing a subshell that
switched directories? It doesn't seem to, in my experiments.
% (cd /)
vq
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-03-13 0:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-07 3:40 FAQ title bar answer using chpwd() Andrew Janke
2015-03-07 4:19 ` Daniel Shahaf
2015-03-07 7:33 ` Bart Schaefer
2015-03-07 7:20 ` Bart Schaefer
2015-03-13 0:39 ` Lawrence Velázquez
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).