-
Notifications
You must be signed in to change notification settings - Fork 521
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
Conversation
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.
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.*?(?<=\.)' \ |
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.
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.
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.
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*\.)
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.
→ 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
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 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.
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.
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:]]*//'
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.
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 |
This PR improves the completion for
bash
.Currently the improvements are:
rebar3 as <tab>
gives a list of therebar,config
profiles, same forrebar3 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 forfish
andzsh
.