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

POSIX friendly printing #1671

Closed
wants to merge 3 commits into from
Closed

POSIX friendly printing #1671

wants to merge 3 commits into from

Conversation

3uryd1ce
Copy link

@3uryd1ce 3uryd1ce commented May 5, 2023

Hey, I noticed that there have been a number of discussions and pull requests about moving updater.sh away from bash toward POSIX compliance (#1641 being one example). I'm opening a simple pull request to test the waters and gauge interest before I attempt to write something more thorough.

As a side note, if the maintainers are open to a pull request replacing {updater,prefsCleaner}.{sh,bat} with a Perl implementation, I could see myself doing this. I see a lot of ways that programs like these could benefit from being written in a more structured language.

One benefit is actually related to portability: all of what I've seen so far could be handled by Perl's included modules and built-ins. This does require a Perl installation, but the current script requires bash + curl/wget which may not be a given either (for instance, this is less likely to be the case on the BSDs).

Please let me know if there are any changes you would like me to make or if you need more details on something. I had considered adding an exit 1 to err(), but I noticed the exit codes aren't consistent throughout updater.sh so I omitted that.

echo flags aren't defined by POSIX. In general, anything more advanced
than a simple string followed by a newline should be handled by
printf(1) if portability/consistency are concerns.

Added new functions to handle this so that colors are kept separate from
the strings themselves (should make the script more maintainable in the
long run).

An additional benefit of using functions here is that errors and
warnings are more likely to be sent to STDERR.
printf_color() functions by assigning the first positional parameter and
shifting it out of the list of parameters. If the interface is misused
and the first positional parameter is also the only parameter, what
would happen? It is probably better to change both to handle that
situation the same way since the code savings is minimal.

While here, add back in a newline that was accidentally nuked in the
first commit.
Accidentally deleted a comma and added a newline. I would like to keep
the formatting the same until someone indicates that I should do
otherwise.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

4 participants