Repository navigation
Conversation
zsh's _describe treats the first unescaped ':' in each entry as the name/description separator, so 'migration:create' was offered as 'migration' with the description 'create', and the remaining targets of the namespace were dropped. Escape the colons before handing the list to _describe. bash splits words at ':' (it is in COMP_WORDBREAKS by default), so 'mage migration:d<TAB>' completed against 'd' and found nothing. Take the current word from COMP_LINE instead and strip the part up to the last ':' from each match, since bash only replaces the text after it. Fixes magefile#558
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #558
With a namespace such as
type Migration mg.Namespace,mage -autocompleteprintsmigration:create,migration:down, ... but neither the zsh nor the bash script completes them.zsh:
_describereads each entry asname:description, somigration:createwas offered asmigrationwith the descriptioncreate, and the other targets in the namespace were dropped. The script now escapes the colons (${(@)targets//:/\\:}) before calling_describe.bash:
:is inCOMP_WORDBREAKSby default, so the colon splits the word. On bash 3.2 (macOS),mage migration:<TAB>turned intomage migration:migration:. On bash 4+,COMP_WORDS[COMP_CWORD]is just the text after the colon, so nothing matched. The script now takes the current word fromCOMP_LINEup toCOMP_POINT. When:is a word break, it also removes the part up to the last:from each match, because bash only replaces the text after that point. This is the same approach bash-completion's__ltrim_colon_completionsuses, without depending on bash-completion. fish and PowerShell are not affected and are unchanged.Tests:
TestBashCompletionNamespacedTargetssources the generated bash script with a stand-inmagethat prints namespaced targets, setsCOMP_LINE/COMP_POINT/COMP_WORDSthe way bash does, and checksCOMPREPLY.TestZshCompletionNamespacedTargetsstubs_describeand checks that the target names reach it with their colons escaped. Both skip when the shell isn't installed, and both skip on Windows. Before the fix, 3 of the 6 bash cases and the zsh test fail.What was run (macOS arm64, Go 1.27.1, zsh 5.9, /bin/bash 3.2.57):
go test -v -vet=all -tags CI -race ./...: everything passes exceptTestBootstrap. That test fails the same way on master here, becauseGOPATHisn't set in the environment (stat bin/mage).go vet -tags CI ./...andgofmt -l .: clean.golangci-lint run ./...: no findings in the changed files. CI pins v2.11.2, but that version can't load Go 1.27 export data, so v2.15.0 was used. Its only findings are 156exhaustruct_v5hits that are identical on master; that linter is newer than the repo's config.zpty) now offersmigration:create migration:down migration:upformage <TAB>andmage migration:<TAB>, andmigration:downformage migration:d<TAB>. bash 3.2 completesmage migration:d<TAB>tomage migration:downandmage fmt migration:u<TAB>tomage fmt migration:up.Not run: bash 4/5 interactively (the unit test simulates its word splitting), Windows, Linux.