Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oh-my-Zsh functions leaking #56

Closed
asymmetric opened this issue Dec 16, 2015 · 20 comments
Closed

Oh-my-Zsh functions leaking #56

asymmetric opened this issue Dec 16, 2015 · 20 comments

Comments

@asymmetric
Copy link
Contributor

Hi,

I have zplug "plugins/mix", from:oh-my-zsh in my ~/.zshrc, which to me basically means that I only want the mix plugin from OMZ, not everything that comes with it.

But I noticed that in my shell the function upgrade_oh_my_zsh, taken from lib/functions is defined. I definitely don't want to let OMZ update itself, since I'm using the much lovelier zplug :)

Is there a way not to let OMZ define this particular function, or any function at all?

@babarot
Copy link
Member

babarot commented Dec 16, 2015

Thank you for your report and suggestion!

I have an idea! I'll give it a try.

@asymmetric
Copy link
Contributor Author

Thanks a lot b4b4r07!

I just want to add that naturally, sometimes OMZ's functions need to be defined, as is the case for themes which rely on git_prompt_info, defined in lib/git.zsh.

I'm sure you know this but just wanted to make it extra clear ;)

@NigoroJr
Copy link
Member

I was just about to create an issue for a similar problem I had :)

My problem is that oh-my-zsh sets WORDCHARS, for no apparent reason(?), which overrides the value I have set in my .zshenv. Sure, I can set the variable after oh-my-zsh is loaded, but I'd like to keep all the environment variable definitions in .zshenv. I know you have a thought on this issue, but my humble suggestion: maybe an as:completion tag that sources a file and adds the directory to the fpath might help?

@babarot
Copy link
Member

babarot commented Dec 16, 2015

Hi,

Thank you @NigoroJr your suggestion.

maybe an as:completion tag that sources a file and adds the directory to the fpath might help?

Actually, I was just thinking about it.

The problem with this issue is that zplug cannot know whether the OMZ plugins are dependent on the library (lib/*) or not. In case of @asymmetric (plugins/mix), if there are no zsh files (*.zsh / *.plugin.zsh) in the plugin directory, it is possible not to load the library files. However, your case is not applicable because there are zsh files.

Although it seems to solve by introducing as:completion tag, this change will have a wide influence on an entire of zplug. Therefore I'm worried a little.

@babarot
Copy link
Member

babarot commented Dec 16, 2015

In addition, I identified the repository which consists of only completion files with a plugin.

I'm sure that your @NigoroJr suggestion is a constructive and effective opinion, but I think as:completion should not source zsh files because completion files (beginning with an underscore _*) may be added to the fpath.

NigoroJr added a commit to NigoroJr/zplug that referenced this issue Dec 17, 2015
This is useful when the user intentionally wants to delay loading the plugin
to after compinit is called. For example,

    zplug 'robbyrussell/oh-my-zsh', \
        of:plugins/golang/*.zsh', \
        nice:10

can be used to load (source) `plugins/golang/*.zsh' after compinit is called.
See zplug#56.
@NigoroJr
Copy link
Member

@b4b4r07 Hmmm that's a good point.

I found a workaround by setting it up like:

zplug 'robbyrussell/oh-my-zsh', \
    of:'plugins/golang/*.zsh', \
    nice:10

The only issue is that even though I try to have plugins/golang loaded after compinit, it gets loaded beforehand. I think this is because the name ends up being the same as when using from:oh-my-zsh, thus, I made a small change at NigoroJr/zplug@0a267b8 to not force the nice value when explicitly specified to be more than 9. Do you think this will solve the issue or is it pointless? I also wasn't sure whether I should check if [[ $nice -lt 10 ]] or [[ $nice -eq 0 ]].

@NigoroJr
Copy link
Member

Hmm... #57 solves the issue when the file can be sourced, but for @asymmetric's case, you can't source the file because it's _mix...

@babarot
Copy link
Member

babarot commented Dec 17, 2015

I think your PR #57 doesn't become a solution to the root of the problem on @NigoroJr's case because I feel this writing style is forcibly and is not beautiful:

zplug 'robbyrussell/oh-my-zsh', \
        of:plugins/golang/*.zsh', \
        nice:10

(I'll merge your PR #57 soon because it's an essential change)

How about this?:

zplug "plugins/golang", as:plugin, of:"*.zsh", ignore:oh-my-zsh.sh

I'll introduce ignore tag to zplug in order to prevent oh-my-zsh.sh and its library files from being loaded forcibly (ref: https://github.com/b4b4r07/zplug/blob/master/zplug#L900-L906).

Then, @asymmetric's case is...

If there are no zsh files (*.zsh|*.plugin.zsh), try not to load oh-my-zsh.sh file. By doing so, if the repository consists of only completion file (beginning with an underscore _*) like plugin/mix, to become not to load oh-my-zsh.sh.

Any thoughts? @asymmetric, @NigoroJr

@NigoroJr
Copy link
Member

@b4b4r07 Sounds like a good idea that will allow more flexible customization 👍 I'm guessing if you want to ignore, for example, some_file.sh in some directory other than the root of the repository you would do ignore:path/to/some_file.sh? (so just like the of tag)

@babarot
Copy link
Member

babarot commented Dec 17, 2015

@NigoroJr

I'm guessing if you want to ignore, for example, some_file.sh in some directory other than the root of the repository you would do ignore:path/to/some_file.sh? (so just like the of tag)

Yes. That's exactly right.

ignore tag will accept as follows:

# of:"*.zsh" is default
zplug "fooA/bar", of:"*.zsh",  ignore:some_file.zsh

zplug "fooB/bar", ignore:"some_*.zsh"    # file-glob ok

I plan to accept ignore:path/to/some_file.sh but there is really no meaning for that because the files which will be loaded are the ending with zsh *.zsh (this defaults to of:"*.zsh").

In addition, the relative path in ignore tag will be resolved with respect to the $ZPLUG_HOME/repos/USER/REPO directory.

of tag and ignore tag are contradictory tags.

@NigoroJr
Copy link
Member

@b4b4r07 Awesome! Looking forward to that change 😃 Also, thank you for the awesome plugin manager: I immediately fell in love with it!

@babarot
Copy link
Member

babarot commented Dec 17, 2015

@NigoroJr You're welcome, I'm glad.

babarot added a commit that referenced this issue Dec 17, 2015
… files

- Case of #56
- For example, robbyrussell/oh-my-zsh/tree/master/plugins/mix
- This repo consists of only completion file
@babarot
Copy link
Member

babarot commented Dec 17, 2015

This change 331535a is for @asymmetric's case. What do you think?

In case that consists of only completion files (beginning with an underscore) such as plugins/mix, zplug doesn't load oh-my-zsh.sh file.

babarot added a commit that referenced this issue Dec 17, 2015
@babarot
Copy link
Member

babarot commented Dec 17, 2015

This change 93cd1f0 is for @NigoroJr's case. What do you think? Please check it out and try it.

zplug "plugins/golang", from:oh-my-zsh, ignore:oh-my-zsh.sh

In the case of from:oh-my-zsh, the base directory for ignore tag is $ZPLUG_HOME/repos/robbyrussell/oh-my-zsh. This is:

# INVALID
zplug "plugins/history-substring-search", \
    from:oh-my-zsh, \
    ignore:update-from-upstream.zsh

# VALID
zplug "plugins/history-substring-search", \
    from:oh-my-zsh, \
    ignore:plugins/history-substring-search/update-from-upstream.zsh

ignore tag's behavior is subject to the following description:

In addition, the relative path in ignore tag will be resolved with respect to the $ZPLUG_HOME/repos/USER/REPO directory.

So how do you like it?

@asymmetric
Copy link
Contributor Author

@b4b4r07 what should I do in this case:

  • I have a theme which depends on OMZ (for the git_prompt_info function, let's say)
  • Therefore I want lib/git.zsh to be loaded
  • I don't want anything else from OMZ

Should I do

zplug "lib/git.zsh", from:oh-my-zsh, ignore:oh-my-zsh.sh | \
  zplug "asymmetric/56ccdf015e1a3b4c4fbd", from:gist # theme which depends on OMZ

Also, what happens if below this I want another plugin from OMZ? Do I always have to remember to ignore:? i.e. let's say that below what I posted above, I have

zplug "plugins/mix", from:oh-my-zsh

Will this again load all OMZ, or will it remember my ignore? What if this is above?

@NigoroJr
Copy link
Member

@b4b4r07 Looks like it's working fine for me, thanks!

@babarot
Copy link
Member

babarot commented Dec 17, 2015

@asymmetric
It's similar to of tag, that is to say, it's valid on the line only.

zplug "lib/git.zsh", from:oh-my-zsh, ignore:oh-my-zsh.sh | \
  zplug "asymmetric/56ccdf015e1a3b4c4fbd", from:gist # theme which depends on OMZ

However, this case

zplug "plugins/mix", from:oh-my-zsh

will NOT be loaded because there are no *.zsh files in plugins/mix. Please Try it out.

If there are *.zsh files in the plugins directory, for example plugins/golang, oh-my-zsh.sh is loaded. It can not be avoided. Because...

zplug cannot know whether the OMZ plugins are dependent on the library

One solution:

zplug "plugins/golang", from:oh-my-zsh, ignore:oh-my-zsh.sh
# or
zplug "plugins/golang", from:oh-my-zsh, do:"unfunction upgrade_oh_my_zsh"

@asymmetric
Copy link
Contributor Author

Makes sense. Thank you very much! 👍

@babarot
Copy link
Member

babarot commented Dec 17, 2015

Thanks!

If there aren't any problems, I'll merge two branches to master.

@babarot
Copy link
Member

babarot commented Dec 18, 2015

Merged. Please run zplug update --self and try it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants