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

Improve completion for bash #2754

Closed
wants to merge 13 commits into from

Conversation

williamthome
Copy link
Contributor

@williamthome williamthome commented Nov 10, 2022

This PR improves the completion for bash.

Currently the improvements are:

  • Profiles completion: typing rebar3 as <tab> gives a list of the rebar,config profiles, same for rebar3 clean --project/-p <tab>

Any tips or comments about this are welcome.

Note: For now I will do this for bash. Maybe in the future for fish and zsh.

Copy link
Collaborator

@ferd ferd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good stuff. I think there a few small things to be worried about, but they're probably not gonna be a problem aside from the profiles functionality.


if [ -f "$rebarconf" ]; then
profconfig=$( cat "$rebarconf" \
| grep -oPz '(?s){profiles.*?(?<=\.)' \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can break whenever using periods in content. For example:

{profiles, [{
   {test, [{relx, [{sys_config, "./config/test.sys.config"},
   ...
}]}.

This will break on the first profile because of the period.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try this updated regex?
(?s){profiles,\s*(\r\n)*\n*\r*\[\s*(\r\n)*\n*\r*.*?(?<=\s*(\r\n)*\n*\r*\}\s*(\r\n)*\n*\r*\.)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

→ cat rebar.config| grep -oPz '(?s){profiles,\s*(\r\n)*\n*\r*\[\s*(\r\n)*\n*\r*.*?(?<=\s*(\r\n)*\n*\r*\}\s*(\r\n)*\n*\r*\.)'
grep: lookbehind assertion is not fixed length

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fixed now. Can you try again, @ferd?

$ cat rebar.config | grep -oPz '(?s)(?:{\s*profiles\s*,\s*(\r\n)*\n*\r*\[).*?(?:\s*(\r\n)*\n*\r*}\s*(\r\n)*\n*\r*\.)'

I also refactored to a more generic/reusable code.
There is an issue with comments. This regex does not ignore them. I will take a look at this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments issue is fixed. Here is the complete command:

cat rebar.config \
| grep -v '\s*%.*' \
| grep -oPz "(?s)(?:{\s*profiles\s*,\s*(\r\n)*\n*\r*\[).*?(?:\s*(\r\n)*\n*\r*}\s*(\r\n)*\n*\r*\.)" \
| tr -d '\0' \
| tr -d '\n' \
| grep -oPz '(?s)(?<=\[).*(?=\])' \
| tr -d '\0' \
| sed -e 's/^[[:space:]]*//'

Copy link
Collaborator

@ferd ferd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep I think that works! Thanks for updating this, much appreciated!

@williamthome
Copy link
Contributor Author

williamthome commented Nov 15, 2022

Yep I think that works! Thanks for updating this, much appreciated!

Thanks, @ferd! I will do some changes to add more completions, for example to rebar3 unlock <packagename> command, where the <packagename> will be suggested. I will come back when having some news.

@williamthome
Copy link
Contributor Author

I am closing this PR in favor of #2858.
Excellent job, @MarkoMin!

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

Successfully merging this pull request may close these issues.

2 participants