zdharma-continuum / zinit

🌻 Flexible and fast ZSH plugin manager
MIT License
2.95k stars 126 forks source link

feat: add completions ice #417

Closed jankatins closed 1 year ago

jankatins commented 1 year ago

Description

Adds a new ice called completions which, if set, always triggers completion detection and installation.

This can be used to overwrite as'null' which would otherwise not trigger completion detection and installation. It would also overwrite a nocompletions ice, if both are set, e.g. via using the default ice annex.

Motivation and Context

I use default ice to set zinit default-ice --quiet as'null' from"gh-r" lbin'!' lucid nocompile for my list of gh-r downloads. Unfortunately, this disables the import of completions:

To reproduce:

zinit default-ice --quiet as'null' from"gh-r" lbin'!' lucid nocompile
# simple jira command line client
zinit lbin'!gj' pick'gj*.tar.gz' atclone'./gj completion zsh > _gj'  atpull'%atclone' for @rsteube/go-jira-cli
zinit clist | grep _gj # -> no _gj completion

Related Issue(s)

Usage examples

Set default ice

zinit default-ice --quiet as'null' from"gh-r" lbin'!' lucid nocompile completions
zinit lbin'!gj' pick'gj*.tar.gz' atclone'./gj completion zsh > _gj'  atpull'%atclone' for @rsteube/go-jira-cli
zinit clist | grep _gj # -> a line with _gj completion is shown

set empty ice per zinit call

zinit default-ice --quiet as'null' from"gh-r" lbin'!' lucid nocompile
zinit lbin'!gj' pick'gj*.tar.gz' atclone'./gj completion zsh > _gj'  completions atpull'%atclone' for @rsteube/go-jira-cli
zinit clist | grep _gj # -> a line with _gj completion is shown

I didn't implement setting a pattern for compilations'whatever' as this would have complicated the change: it would need to add (or replace) the default pattern which is searched for.

How Has This Been Tested?

I ran the above two versions locally via

λ  rm -rf ~/.local/share/zinit/completions/_gj ; zi delete -y rsteube/go-jira-cli ; exec zsh
linkbin annex: Removed gj soft link

Done (action executed, exit code: 0)

Downloading rsteube/go-jira-cli…
(Requesting `gj_0.2.5_Darwin_x86_64.tar.gz'…)
[...]
ziextract: Unpacking the files from: `gj_0.2.5_Darwin_x86_64.tar.gz'…
ziextract: Successfully extracted and assigned +x chmod to the file: `gj'.
linkbin annex: Created the gj soft link and set +x on the gj binary
gj*.tar.gz null rsteube/go-jira-cli %atclone ./gj completion zsh > _gj gh-r !gj
Installed 1 completions. They are stored in the $INSTALLED_COMPS array.

See the last line which shows that the completions were installed.

There are also two new tests which hopefully pass :-)

Types of changes

Checklist:

jankatins commented 1 year ago
Run find . -name '*.md' -type f -print0 | xargs -0 -n1 -P4 python3 -m mdformat --check --wrap 120
Error: File "/home/runner/work/zinit/zinit/CHANGELOG.md" is not formatted.
Error: Process completed with exit code 123.

Given that the last change is from 2021, I guess I can ignore this one?

psprint commented 1 year ago

LGTM, the two extended if checks appear to be OK.

pon., 7 lis 2022, 20:23 użytkownik Jan Katins @.***> napisał:

Run find . -name '*.md' -type f -print0 | xargs -0 -n1 -P4 python3 -m mdformat --check --wrap 120 Error: File "/home/runner/work/zinit/zinit/CHANGELOG.md" is not formatted. Error: Process completed with exit code 123.

Given that the last change is from 2021, I guess I can ignore this one?

— Reply to this email directly, view it on GitHub https://github.com/zdharma-continuum/zinit/pull/417#issuecomment-1306081075, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABOE4CDOXGNSDXZDXMIYC4LWHFJKHANCNFSM6AAAAAARZNXBDE . You are receiving this because you are subscribed to this thread.Message ID: @.***>

jankatins commented 1 year ago

Rebased...

the zshelldoc test fails with some places I never touched. Is actually someone looking at this test or is that not relevant for merging (I assume some previous PR changed these places, but not the test...)

vladdoster commented 1 year ago

Questions:

  1. Why does the current behavior disables checking for completions?
  2. Are you sure the lbin ice doesn't cause it?
jankatins commented 1 year ago

Are you sure the lbin ice doesn't cause it?

I've not explicitly tested this, but from my reading of the code, there is nothing which could be influenced by the lbin ice. It's my usage of the default ice with as"null" ... nocompile which causes this (twice, actually, as both disable compilations).

Why does the current behavior disables checking for completions?

Main part from the PR diff:

-    [[ 0 = ${+ICE[nocompletions]} && ${ICE[as]} != null && ${+ICE[null]} -eq 0 ]] && \
+    [[ (0 = ${+ICE[nocompletions]} && ${ICE[as]} != null && ${+ICE[null]} -eq 0) || 0 != ${+ICE[completions]} ]] && \

Basically if you either use as"null" or nocompile(e.g. in a default ice), you won't get completion right now. This PR simply lets you overwrite that.

My interpretation of the current code is that this was simply overlooked: nocompile has compile, so you can put it back. But nocompletions(or as"null") has up to now no completions to overwrite it, so this PR adds it. I guess it wasn't an issue until the default ice annex came up...

vladdoster commented 1 year ago

@jankatins Can you update the documentation?

vladdoster commented 1 year ago
Run find . -name '*.md' -type f -print0 | xargs -0 -n1 -P4 python3 -m mdformat --check --wrap 120
Error: File "/home/runner/work/zinit/zinit/CHANGELOG.md" is not formatted.
Error: Process completed with exit code 123.

Given that the last change is from 2021, I guess I can ignore this one?

@jankatins This was fixed, btw.

jankatins commented 1 year ago

Can you update the documentation?

I added it in the readme, where else does it need to go?

jankatins commented 1 year ago

I added a commit which should fix the doctest, but this was a different PR which broke this, I didn't add 20+ lines somewhere...

github-actions[bot] commented 1 year ago

:tada: This PR is included in version 3.9.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: