Closed timdp closed 6 years ago
I haven't used zplug
but I will check it later. Also you can submit a PR.
I am going to change the installation steps which may solve this problem.
It may be:
$ ./install.sh /path/to/you/like
So is the following example is OK? (This is a plan. Don't run it now.)
$ ./install.sh ~/.zplug/repos/g-plane
You can try it in v1.0.0-0 (https://github.com/g-plane/zsh-yarn-autocompletions/releases/tag/v1.0.0-0)
I had a look at the code before running it. It might work, but I don't think you're using the API as intended.
The way I understand it, when I add zplug "g-plane/zsh-yarn-autocompletions"
to .zshrc
, that makes it clone the repo to ~/.zplug/repos/g-plane/zsh-yarn-autocompletions
. For plugins written in pure zsh, that should be sufficient.
In this case, I assume you want to run rustc
afterwards to get the binaries ready. zplug
lets you specify a build hook in .zshrc
, like I did in my original message. You could leverage that to compile the binaries.
I see you're still using $ZSH_CUSTOM
in the code so it would most likely still fail. Couldn't you just get the plugin source directory as dirname $0
and put the binaries in a subdir there?
You don't need to compile source code to binary file now. Just check the release page and download it.
According to your description, I guess plugins of zplug
are located in ~/.zplug
. If it is correct, you can run ./install.sh ~/.zplug/repos/g-plane
.
And I am trying removing the $ZSH_CUSTOM
.
Using dirname $0
seems that it works well.
I appreciate the effort but I think I need to explain how zplug works, or at least as I understand it. The idea is that you can install plugins by simply adding a line of the format
zplug "user/repo"
to .zshrc
. Then, when zplug initializes, it will notice that it doesn't have a local copy of that plugin and clone the repo. Additionally, it can automatically pull in new commits.
Thus, an install script that performs these steps for you isn't going to cut it as far as zplug is concerned. That is, it could sort of work but it doesn't seem like the right thing to do.
If a plugin install needs to run additional steps after git clone, it can do so with a post-build hook, like in my original message. There's probably also a way for plugins to specify those steps themselves so that users still only need to add a simple zplug
statement; I didn't check.
Regardless, as a workaround, I considered adding the current install script as a build hook. Unfortunately, that's not going to work either because the install script insists on creating folders and copying files around, while the whole purpose of zplug is to do that for you. Additionally, as you mentioned, the build script doesn't produce binaries at all because you're expecting people to download the tarball from GitHub, which isn't how zplug works.
Now, I was able to make it work with:
zplug "g-plane/zsh-yarn-autocompletions", hook-build:"cargo build --release && cp target/release/yarn-autocompletions ./"
so that could already be part of the readme for zplug users. To make it slightly easier for them, you could add a build.sh
that runs those commands. Or as mentioned above, there's probably zplug syntax for automating it. Or you could even do it just-in-time, right before the binary gets run for the first time; that way, you'd also avoid the hook.
If you don't want to introduce a dependency on the Rust toolchain (which makes sense), I think you can also still do that. If you also publish the binaries as part of a GitHub release, you can just curl
those instead of compiling them locally.
Anyway, hope that helps!
According to your description, is the following solution a good idea?
zplug "g-plane/zsh-yarn-autocompletions", hook-build:"sh zplug.sh"
And the zplug.sh
would be:
wget # URL here
What do you think?
Yeah, that should work. I guess you'll have to determine the platform to decide which binary to download?
How about just executing uname
command?
I have a question: If I use zplug to install a plugin, which shell script will be loaded when I open terminal?
I'm not sure what you mean. Did you check the zplug docs and check the code of existing plugins as a reference?
For example, after we used zplug to install this plugin, will the yarn-autocompletions.plugin.zsh
be loaded automatically?
It did do that for me, yeah. Not sure if it's a wildcard or an exact match.
I have released https://github.com/g-plane/zsh-yarn-autocompletions/releases/tag/v1.1.0-beta.0 . You can try:
zplug "g-plane/zsh-yarn-autocompletions", hook-build:"sh zplug.sh"
Welcome sending any reponses.
zplug "g-plane/zsh-yarn-autocompletions", hook-build:"sh zplug.sh"
does not work for me. I do not receive autocompletion.
It doesn't work because you're using sh
instead of zsh
. You can verify this by adding >/tmp/zplug.log 2>&1
to the command. Then you get this as the log:
zplug.sh: 3: [: Linux: unexpected operator
curl: (22) The requested URL returned error: 404 Not Found
gzip: stdin: unexpected end of file
tar: Child returned status 1
tar: Error is not recoverable: exiting now
If you add #!/usr/bin/zsh
as the first line and make the script executable (chmod u+x zplug.sh
), the build hook can just become ./zplug.sh
. Additionally, if you add set -e
before running any commands, the script will exit on errors, which is safer.
Also, what does the ./
in the tar
command do?
Also, the comparison in the []
should use a single =
. The ==
is invalid.
Just extract the binary file only. However it seems that it will throw an error but the binary still can be extracted normally. It's confusing.
@timdp In fact you can submit a PR, as I am not familiar with zplug.
My remarks were more about *NIX in general and zsh than zplug. :slightly_smiling_face:
@timdp Thanks a ton, man! I was just wondering if I could get this to work with zplug. The command
zplug "g-plane/zsh-yarn-autocompletions", hook-build:"cargo build --release && cp target/release/yarn-autocompletions ./"
worked like a charm :)
@timdp So can you help me check the zplug.zsh
file of the latest commit?
@g-plane I had to fix two things:
version=$(grep '^version =' Cargo.toml | cut -d'"' -f2)
./
in ./yarn-autocompletions
confused tar
.With those two changes, it worked.
@timdp Is that OK now? I have updated it.
The script seems to work (the binary is there) but it's no longer completing when I hit tab. It's also broken with my cargo
build hook, so I guess something else is broken?
The CI result of last commit is passed. Can you show me the output of running cargo build
manually?
Yeah, I'm not sure what could be wrong. It feels unrelated to the recent patches. In both cases (cargo and curl), I tested by removing the cloned repo, updating my .zshrc
, and started a new shell, which completed the install process. Both installs worked and I verified that the binary was present. It's just that entering yarn
and hitting tab just completes with file names rather than commands, as if the plugin isn't there at all. Since it worked before, I think there might be some other issue with my zsh installation.
Have you installed other autocompletion plugins?
If I enter yarn run
and press Tab
, then I get the following error:
yarn run _fetch_yarn_autocompletions_result:1: no such file or directory: /usr/local/opt/zplug/repos/g-plane/zsh-yarn-autocompletions/yarn-autocompletions
_fetch_yarn_autocompletions_result:1: no such file or directory: /usr/local/opt/zplug/repos/g-plane/zsh-yarn-autocompletions/yarn-autocompletions
_fetch_yarn_autocompletions_result:1: no such file or directory: /usr/local/opt/zplug/repos/g-plane/zsh-yarn-autocompletions/yarn-autocompletions
yarn
$ ls /usr/local/opt/zplug/repos/g-plane/zsh-yarn-autocompletions
Cargo.lock install.sh yarn-autocompletions.example.yml
Cargo.toml package.json yarn-autocompletions.plugin.zsh
LICENSE screenshot.gif zplug.zsh
README.md src
@danielbayerlein Have you tried the latest installation? The command may be zplug "g-plane/zsh-yarn-autocompletions", hook-build:"zplug.zsh"
.
@g-plane Yes. YARN_AUTO_COMP_PATH
show the following path:
echo $YARN_AUTO_COMP_PATH
/usr/local/opt/zplug/repos/g-plane/zsh-yarn-autocompletions/yarn-autocompletions
But /usr/local/opt/zplug/repos/g-plane/zsh-yarn-autocompletions/yarn-autocompletions
does not exist. I think the install.sh
is not executed.
@danielbayerlein install.sh
is not for zplug user.
@g-plane But then the YARN_AUTO_COMP_PATH
is wrong, right?
@danielbayerlein Is the binary file in the plugin directory?
@g-plane See the directory output in my comment above.
@danielbayerlein According to your comment, there is no binary files. So it's impossible to execute autocompletion.
@g-plane You're right. Apparently the hook-build does not work. If I execute ./zplug.zsh
manually, then the yarn autocompletion works.
{"pid":58671,"shlvl":1,"level":"ERROR","dir":"/usr/local/opt/zplug/repos/g-plane/zsh-yarn-autocompletions","message":"(eval):1: command not found: zplug.zsh","trace":["__zplug::log::capture::error:8","__zplug::job::hook::service:25","__zplug::job::hook::build:4","__zplug::job::handle::hook:32","__zplug::job::handle::wait:41","__install__:73","__zplug::core::core::run_interfaces:14","zplug:12","zsh:4"],"date":"2018-03-30T11:01:18+0200"}
@timdp What is your installation command?
š The solution for zsh-yarn-autocompletions
and zplug
š
zplug "g-plane/zsh-yarn-autocompletions", hook-build:"./zplug.zsh", defer:2
@g-plane Are you interested on a pull request for the documentation?
@danielbayerlein Please do.
I'm by no means a zsh expert but I've been using zplug lately. I wanted to install your plugin using zplug and I ran into some issues:
I was able to run the build manually by adding this to my
.zshrc
:In order to move the compiled
yarn-deps
andyarn-scripts
to the plugin's root folder, the folders of the same name can't exist, so I'm moving those tosrc
. It's kind of hacky so a better way would be nice.If I type
yarn
and hit tab, I get:Looking at the code, it's interpolating
$ZSH_CUSTOM
to the empty string, so I guess that's not supported by default. The plugin gets installed to~/.zplug/repos/g-plane/zsh-yarn-autocompletions
so$ZSH_CUSTOM/plugins/yarn-autocompletions
, like the plugin code currently uses, doesn't seem like the generic approach.Happy to have a stab at a PR but I wanted to check first. :slightly_smiling_face: