zplug / installer

:inbox_tray: zplug installer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The installer exits without waiting for the completion of `git clone`

crhg opened this issue Β· comments

The installer exits without waiting for the completion of git clone. This is not a problem when running the installer manually. However, if you write .zshrc to automatically run the installer if zplug is not installed, subsequent processing using zplug will cause an error depending on the timing.

It seems that spin() is responsible for waiting for the job to finish, but it does not seem to work well.

If you add the following code to the end of the installer, the output will be as follows. It is expected to wait for 10 seconds sleeping, but in fact it finished almost immediately.

date
execute \
    --title \
    "sleep 10" \
    "sleep 10"
date
% cat installer.zsh | zsh
 βœ”  Checking if your zsh version is newer than 4.1.9 [SUCCEEDED]
 βœ”  Installing zplug to /Users/matsui/.zplug [SUCCEEDED]
 All processes are successfully completed πŸŽ‰
 For more information, see http://zplug.sh 🌺
 Enjoy zplug!
Mon Nov 12 17:16:24 JST 2018
 βœ”  sleep 10 [SUCCEEDED]
Mon Nov 12 17:16:25 JST 2018

My environment is as follows.

zsh 5.6.2 (x86_64-apple-darwin18.0.0)
GNU Awk 4.2.1, API: 2.0 (GNU MPFR 4.0.1, GNU MP 6.1.2)

I tried it on another machine in the same way and it worked as expected here.

% cat installer.zsh| zsh
 βœ”  Checking if your zsh version is newer than 4.1.9 [SUCCEEDED]
 βœ”  Installing zplug to /home/matsui/.zplug [SUCCEEDED]
 All processes are successfully completed πŸŽ‰
 For more information, see http://zplug.sh 🌺
 Enjoy zplug!
2018εΉ΄ 11月 13ζ—₯ η«ζ›œζ—₯ 09:29:20 JST
 βœ”  sleep 10 [SUCCEEDED]
2018εΉ΄ 11月 13ζ—₯ η«ζ›œζ—₯ 09:29:30 JST

The environment is as follows.

zsh 5.4.2 (x86_64-ubuntu-linux-gnu)
GNU Awk 4.1.4, API: 1.1 (GNU MPFR 4.0.1, GNU MP 6.1.2)

In zsh-5.6.2 I found that connecting echo $jobstates to pipe will make the output empty even if there are some jobs. This does not occur for zsh 5.4.2.

% sleep 30
^Z
zsh: suspended  sleep 30
% echo $jobstates
suspended:+:16815=suspended
% echo $jobstates | cat

% echo $jobstates
suspended:+:16815=suspended

I asked about this on the zsh-users mailing list and got the answer that this is the effect of bug fixes made in 5.6. In order to prevent the left side of the pipe operator executed by subshell from influencing the parent, parameter expansion is performed after forking, and it seems that $jobstates becomes empty because subshell does not have a job. For details, see the thread from zsh-users 23756.

As a result, it seems that the logic for judging completion of job in the spin() function is not working properly.

        echo "$jobstates" \
            | awk '
            /[0-9]+=/ {
                jobs[++job_count] = $0
            }
            END {
                for (i = 1; i <= job_count; i++) {
                    print(jobs[i])
                }
                exit job_count == 0
            }' \
                | xargs test -z && break

I think that the part here can be written as follows without using pipes.

        [ $#jobstates = 0 ] && break