-
Notifications
You must be signed in to change notification settings - Fork 70
Add check for autoloading compinit in zsh.go #124
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
Open
ratticon
wants to merge
2
commits into
posener:master
Choose a base branch
from
ratticon:patch-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not this is 100% correct.
Does the order of the commands important?
If the file already have the
completeCmd
line, but doesn't have thecompInit
in it?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking Eyal.
Let me rubber-duck for a moment:
This line defines compInit as the string to search for / add, that same way the
bashCompInit
line is handled.Before the suggested changes, the conditional at line 28 looks for the line in the zsh config file matching the
bashCompInit
string, then builds thecompleteCmd
string to append to the file.In my suggested changes, I added the conditional at line 31 to check for the compInit line in the zsh config and add both the
bashCompInit
andcompInit
commands plus thecompleteCmd
string that may / may not have already been added to by the previous conditional.You are correct! This could result in
completeCmd
string being mutated and appended like so:(newline chars expanded for easier reading)
I'm sorry, I will re-think this.
As for the order of the commands. I haven't tested that.
I will edit my
~/.zshrc
file and see if autocomplete works properly with theautoload bashcompinit...
andautoload compinit...
commands in a different order.Kind Regards,
Ben
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested two versions of my
~/.zshrc
file and found that both enable autocompletion without throwing any errors.Test A:
Test B:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed line 32 from:
completeCmd = bashCompInit + "\n" + compInit + "\n" + completeCmd
to
completeCmd = compInit + "\n" + completeCmd
to avoid the issue the bug I identified above.
Test 1 - both bashcompinit and compinit lines missing from z.rc
(newline chars expanded for easier reading)
Test 2 - only bashcompinit line missing from z.rc
(newline chars expanded for easier reading)
Test 3 - only compinit line missing from z.rc
(newline chars expanded for easier reading)
Test 4 - both bashcompinit and compinit lines exist in z.rc
(newline chars expanded for easier reading)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@posener, regarding:
This is also an issue with the existing check for the bashCompInit line, right?
Maybe we should add a dedicated function to check if zsh has been configured and fix it before adding commands, for example:
Sorry if above example is declared incorrectly. I'm coming from a Python background, but picking up Go while working through this change request with you. I'm not sure if I can declare
missingConfigLines
as an empty string or if returningappendFile(z.rc, "")
would throw an exception.