From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7535 invoked by alias); 8 Apr 2014 17:53:20 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 18714 Received: (qmail 29052 invoked from network); 8 Apr 2014 17:53:13 -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=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Message-ID: <53441D5E.2010008@goots.org> Date: Tue, 08 Apr 2014 17:01:34 +0100 From: Nick Cross User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: Bart Schaefer , zsh-users@zsh.org Subject: Re: Look for git info in background References: <140216182021.ZM19970@torch.brasslantern.com> <5343D114.8040509@goots.org> <140408082531.ZM13585@torch.brasslantern.com> In-Reply-To: <140408082531.ZM13585@torch.brasslantern.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator3039.hostgator.com X-AntiAbuse: Original Domain - zsh.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - goots.org X-BWhitelist: no X-Source-IP: 128.240.4.255 X-Exim-ID: 1WXYTT-0007T1-3S X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([172.17.130.193]) [128.240.4.255]:58668 X-Source-Auth: goots@goots.org X-Email-Count: 1 X-Source-Cap: cm5jO3JuYztnYXRvcjMwMzkuaG9zdGdhdG9yLmNvbQ== Hi, Thanks for the reply. Bizarrely I am getting precmd_update_git_vars:6: bad option: -w from zle -F -w Using rpm -q zsh zsh-5.0.2-5.fc19.x86_64 Regards Nick On 08/04/14 16:25, Bart Schaefer wrote: > On Apr 8, 11:36am, Nick Cross wrote: > } > } Apologies for resurrecting such an old thread ;-) However, on the same > } topic rather than using vcs_info is it also possible to run a python > } script in the background to update the prompt e.g. > } > } PROMPT='%m$(git_super_status) $ ' > > The basic pattern is: > > (1) precmd (or entry in precmd_functions) that creates a background > job writing to a file descriptor > > (2) widget that reads from that descriptor and updates the prompt > > (3) chpwd (or chpwd_functions) that clears the old info so the prompt > won't be misleading before the widget updates it > > If the state can change rapidly at times other than change of directory, > drop the third step and clear the old info in the precmd. > > Something I didn't deal with in the vcs_info example was the possibility > of a race, e.g., if new prompts appear faster than the background jobs > finish then you may have multiple of them waiting to update the prompt > and they may do so in the wrong order. The precmd ought to remove the > old handler before creating the new one. > > The vcs_info example is also a little special because it communicates > through the vcs_info_msg_0_ parameter instead of text output, so to > background it required generating a typeset command to pass the value > up to the parent, which then eval'd the typeset. That's not needed > in a case like $(git_super_status) where the output is directly used. > > I don't recall now why I decided to use a coproc for the background job > instead of <<(...) substitution, which is easier. > > typeset -g update_prompt_fd > PROMPT='%m[waiting] $ ' > > update_super_status () { > PROMPT="%m$(read -rE -u$1) $ " # double quotes, not promptsubst > update_prompt_fd=0 > zle -F $1 > exec {1}>&- > zle reset-prompt > } > zle -N update_super_status > > chpwd () { > if zle -l update_super_status > then > PROMPT='%m[waiting] $ ' > fi > } > > precmd () { > if zle -l update_super_status > then > (( update_prompt_fd )) && zle -F $update_prompt_fd >/dev/null > exec {update_prompt_fd}<<( git_super_status ) > zle -F -w $update_prompt_fd update_super_status > fi > } >