Skip to content

feat: Add %SYMBOL% substituting to non-clone time ices like atinit'', atload'', etc.#450

Open
psprint wants to merge 1 commit into
zdharma-continuum:mainfrom
psprint:substitute-atload
Open

feat: Add %SYMBOL% substituting to non-clone time ices like atinit'', atload'', etc.#450
psprint wants to merge 1 commit into
zdharma-continuum:mainfrom
psprint:substitute-atload

Conversation

@psprint

@psprint psprint commented Dec 29, 2022

Copy link
Copy Markdown
Contributor

Description

There are many such symbol var-like symbols:

  • %ID% – id-as ice
  • %USER% – username (in user/plugin ID)
  • %PLUGIN% – plugin name (in user/plugin ID)
  • %URL% – snippet url
  • %DIR% – plugin directory path
  • %ZPFX% – value of $ZPFX
  • %OS% – $OSTYPE
  • %MACH% – $MACHTYPE
  • %CPU% – $CPUTYPE
  • %VENDOR% – $VENDOR
  • %HOST% – $HOST
  • %UID% – $UID (numerical user id)
  • %GID% – $GID (group #)

With this patch many has been fixed (like %ID%, %USER%, %PLUGIN% were returning empty strings, possibly breaking packages, where this undocumented feature is used) and support for load-time ices (like atload'', etc.) have been added.

Motivation and Context

I wanted to make %SYM% more widely used, it might yield interesting use cases. Maybe some new vars can be added? README is updated to mntion the feature.

Related Issue(s)

Usage examples

For example:

zinit id-as'plugin-%UID%' atload'print Loaded from dir: %DIR%, plugin id: %ID%' for zd

output is:

Loaded from dir: /home/q/.local/share/zinit/plugins/plugin-500, plugin id: plugin-500

How Has This Been Tested?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
@psprint

psprint commented Feb 15, 2023

Copy link
Copy Markdown
Contributor Author

It should now pass the linter.

@vladdoster

Copy link
Copy Markdown
Member

The commit message should be all lowercase.

@psprint

psprint commented Feb 16, 2023

Copy link
Copy Markdown
Contributor Author

The commit message should be all lowercase.

@vladdoster: fixed

@psprint

psprint commented Feb 16, 2023

Copy link
Copy Markdown
Contributor Author

@vladdoster I don't know why README.md isn't formatted, could you help?

@vladdoster

Copy link
Copy Markdown
Member

@psprint,

What is an actual use case for this?

@psprint

psprint commented Apr 29, 2023 via email

Copy link
Copy Markdown
Contributor Author
@psprint

psprint commented Apr 29, 2023

Copy link
Copy Markdown
Contributor Author

@vladdoster Oh, I see that I've already described the feature in PR message. As for the use case, it's: e.g.: ability to just write my-%PLUGIN% in id-as'' ice to obtain e.g.: my-dstask, i.e.:

zinit id-as'my-%PLUGIN%' from"gh-r" sbin'*->dstask' bpick'^*import*' \
        for @naggie/dstask

I think that such special vars are useful and needed from the point of view of versatility, to provide a complete support of the intentions of users (one could want such automatic plugin-name reference, for example).

@psprint psprint force-pushed the substitute-atload branch 2 times, most recently from 20cc9a5 to d65c35a Compare April 29, 2023 19:37
@psprint

psprint commented Apr 29, 2023

Copy link
Copy Markdown
Contributor Author

@vladdoster: I've fixed the markdown in README.md (was exceeding 120 chars line lenght)

There are many such symbol var-like symbols:

- %ID%          – id-as ice
- %USER%        – username (in user/plugin ID)
- %PLUGIN%      – plugin name (in user/plugin ID)
- %URL%         – snippet url
- %DIR%         – plugin directory path
- %ZPFX%        – value of $ZPFX
- %OS%          – `$OSTYPE`
- %MACH%        – `$MACHTYPE`
- %CPU%         – `$CPUTYPE`
- %VENDOR%      – `$VENDOR`
- %HOST%        – `$HOST`
- %UID%         – `$UID` (numerical user id)
- %GID%         – `$GID` (group #)

With this patch many has been fixed (like %ID%, %USER%, %PLUGIN% were
returning empty strings, possibly breaking packages, where this undocumented
feature is used) and support for load-time ices (like `atload''`, etc.) have
been added.

For example:

```zsh
zinit id-as'plugin-%UID%' atload'print Loaded from dir: %DIR%, plugin id: %ID%' for zdharma-continuum/null
```

output is:

```
Loaded from dir: /home/q/.local/share/zinit/plugins/plugin-500, plugin id: plugin-500
```
@psprint psprint force-pushed the substitute-atload branch from d65c35a to 6de002d Compare April 29, 2023 19:41
@psprint

psprint commented Apr 29, 2023

Copy link
Copy Markdown
Contributor Author

@vladdoste: Eh, mdformat is stil failing, I think that I'll give up, as I've run it without --check and then committed the result… Could you look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants