Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Update dev_setup.sh to use and benefit from bash double square bracket syntax #2166

Merged
merged 4 commits into from
Jun 25, 2019
Merged

Conversation

MichaIng
Copy link
Contributor

@MichaIng MichaIng commented Jun 18, 2019

Description

  • Consequently use double square brackets (over single square backets), to be consistent and benefit from this syntax
  • Skip obsolete quoting of left sided variables and strings in double square brackets
  • Use "-z" instead of comparing with empty string explicitly in double square brackets
  • Merge multiple double square bracket expressions, connected by "&&" or "||", into a single expression
  • "! -z" => "-n"
  • Remove obsolete free spaces from command substitutions, to be consistent

How to test

Run (especially the interactive part of) the installer with multiple command options and YN selections.
However, this is just a trivial minor syntax enhancement.

Contributor license agreement signed?

…t syntax

+ Consequently use double square brackets (over single square backets), to be consistent and benefit from this syntax
+ Skip obsolete quoting of left sided variables and strings in double square brackets
+ Use "-z" instead of comparing with empty string explicitly in double square brackets
+ Merge multiple double square bracket expressions, connected by "&&" or "||", into a single expression
+ "! -z" => "-n"
+ Remove obsolete free spaces from command substitutions, to be consistent
@devs-mycroft devs-mycroft added the CLA: Needed Need signed CLA from https://mycroft.ai/cla label Jun 18, 2019
@devs-mycroft
Copy link
Collaborator

Hello, @MichaIng, thank you for helping with the Mycroft project! We welcome everyone
into the community and greatly appreciate your help as we work to build an AI
for Everyone.

To protect yourself, the project, and users of Mycroft technologies we require
a Contributor Licensing Agreement (CLA) before accepting any code
contribution. This agreement makes it crystal clear that along with your
code you are offering a license to use it within the confines of this project.
You retain ownership of the code, this is just a license.

Please visit https://mycroft.ai/cla to initiate this one-time signing. Thank
you!

Copy link
Collaborator

@forslund forslund left a comment

Choose a reason for hiding this comment

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

Thanks for providing this cleanup. I will test it further when the CLA arrives, from what I can see most look good. The only thing that caught my attention was the removal of quotes around some paths, there has been issues before with paths containing spaces.

But you probably know more of bash than me so if you can defend the change I'll accept it :)

dev_setup.sh Show resolved Hide resolved
@MichaIng
Copy link
Contributor Author

@forslund
CLA request btw arrived an signed.

@devs-mycroft devs-mycroft added CLA: Yes Contributor License Agreement exists (see https://github.com/MycroftAI/contributors) and removed CLA: Needed Need signed CLA from https://mycroft.ai/cla labels Jun 24, 2019
Copy link
Collaborator

@forslund forslund left a comment

Choose a reason for hiding this comment

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

Looks good as far as I can tell. I had two comments that you can look at and say if they're things that needs to be handled. If you don't have time to look at it I'll just merge this PR tomorrow, it's a pretty nice improvement over the previous code.

Many thanks for contributing this!

dev_setup.sh Outdated Show resolved Hide resolved
dev_setup.sh Outdated
if [ ! -z ${INSTALL_PRECOMMIT_HOOK+x} ] || grep -q "MYCROFT DEV SETUP" ${HOOK_FILE}; then
if [ ! -f ${HOOK_FILE} ] || grep -q "MYCROFT DEV SETUP" ${HOOK_FILE} ; then
if [[ -n ${INSTALL_PRECOMMIT_HOOK} ]] || grep -q "MYCROFT DEV SETUP" ${HOOK_FILE}; then
if [[ ! -f ${HOOK_FILE} ]] || grep -q "MYCROFT DEV SETUP" ${HOOK_FILE} ; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nothing you have to fix but I wonder if it's an old bug here in the grep statement if there are spaces in the path?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@forslund
The +x replaces the contained string with an x IF it exists, so it does not have spaces anymore. If the check is just about empty string or not, then the contained +x is actually an alternative to double quoting, since it works around possible space issues. But the curly braces can be removed safely if no manipulation (like +x) is done and no literal meant characters are added to the string.

Will add a commit to make optimal bash code 🙂.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I might have been unclear, I was reffering to the grep command part of it: grep -q "MYCROFT DEV SETUP" ${HOOK_FILE} will ${HOOK_FILE} be expanded to a single argument if it the HOOK_FILE path has spaces is my question.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@forslund
Ah yep, theoretically doubles quotes make sense here. However the variable is just assigned the lines above, clearly without spaces.

+ Always use single quotes around strings that are fully meant literal and do not contain single quotes themselves.
+ Remove curly braces around variable names, if no next character or a space is following.
+ Remove curly braces double quotes around single variables (and command substitutions) that are assigned to variables. The contained strings are always added correctly with spaces.
+ Merge multiple printed lines into one echo call.
@MichaIng
Copy link
Contributor Author

MichaIng commented Jun 24, 2019

Did some further tuning, I hope not too much for now. Basically:

  • Use single quotes around literal meant strings that do not contain single quotes themselves. This assures that no magic character expansion is done accidentally and only single quotes themselves would require an ugly escaping.
  • Remove curly braces where not required. However this is also a question of personal taste, e.g. if one wants to make variable calls more prominent. So I can revert this, if wanted, it was simply mixed, sometimes braces, sometimes not.

@forslund
Copy link
Collaborator

I'm ok with these changes. Merging.

@forslund forslund merged commit a66dd08 into MycroftAI:dev Jun 25, 2019
@MichaIng MichaIng deleted the patch-1 branch June 25, 2019 13:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CLA: Yes Contributor License Agreement exists (see https://github.com/MycroftAI/contributors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants