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

Fix more issues identified through shellcheck #355

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

a1346054
Copy link
Contributor

More issues were identified through shellcheck and reading through the code.

Continues work on #345 but more help would be appreciated because I'm not too familiar with the codebase - more shellcheck issues remain to be fixed.

All tests pass.

bash completions files are not supposed to have executable filemode set
shellcheck already relies on functionality added in bash v4.1, hence
better to move the version check to the top of the script rather than
checking in just one place

also fixes proper invocation of 'read'
also fixes a rare bug when directory name contains a space
@a1346054
Copy link
Contributor Author

a1346054 commented Aug 10, 2021

macOS users will have to update their bash versions, because the bash provided by apple is terribly out-of-date and will not be updated by apple anymore due to GPL licence concerns.

Bash 4.1, which provides the necessary functionality, was released in 2010, which was 11 years ago.

Updating is easy and most people who use the commandline (and hence todo.sh) will already have done so.

This was also one of the main reasons why the hashbang line was changed to '#!/usr/bin/env bash' earlier, so that the correct bash is started on macOS instead of the apple-provided one.

Breaks on macOS

This reverts commit 17e3e88.
@inkarkat
Copy link
Member

Thanks. That's again a whole lot of changes; most of it pretty straightforward. I wonder whether the consistent joining of for ...; do and if ...; then is worth it; this is purely cosmetic, but affects a lot of places.

Getting rid of the old Bash support on Mac OS would indeed be very useful; it's been a huge pain in the rear. I hope that your assessment that this is straightforward and most users would / can do it is correct. From the work on the mailing list, I know that at least for some people todo.sh is the only command-line application they use; some have installed Cygwin on Windows just for it.

I think the CI build on Mac OS would have to be upgraded first, so that we don't lose the test coverage on that platform.

needed due to old version of bash on macOS
@a1346054
Copy link
Contributor Author

a1346054 commented Aug 10, 2021

I'm using this guide https://google.github.io/styleguide/shellguide.html#loops which recommends those exact changes for the for ... do.

I'll revert the macOS changes and do a proper bash version check instead for that one read parameter.

@karbassi karbassi requested a review from inkarkat August 10, 2021 20:44
@karbassi
Copy link
Member

We could discuss dropping support for any version of Bash before 4.1 (2009-12-31). If we do, we'll release a major version upgrade to 3.0.0 for todo.txt-cli.

References:

@a1346054
Copy link
Contributor Author

If full compatibility with a locally installed updated bash version on a macOS were desired, then the hashbang

#!/bin/bash

would have to be changed to

#!/usr/bin/env bash

in every test file.

@a1346054
Copy link
Contributor Author

I created two new branches that are ready for a pull request once this pull request is accepted.

The first one https://github.com/a1346054/todo.txt-cli/tree/macos_tests fixes issues with tests not running with the correct bash on macOS (and possibly elsewhere), as well as improves the general code consistency.

The second one https://github.com/a1346054/todo.txt-cli/tree/bash_syntax_tests further builds upon the first one by using more modern bash syntax, while still keeping backwards compatibility with older versions of bash.

All tests pass, as well as my own testing.

@karbassi
Copy link
Member

@a1346054 can you convert all files to use tabs and add an editorconfig file to the project as well?

@a1346054
Copy link
Contributor Author

Sure, I'll set it up. Any other preferences besides tabs over spaces?

@karbassi
Copy link
Member

Sure, I'll set it up. Any other preferences besides tabs over spaces?

Great question. I think it would be great to use shfmt as the formatter. That way we have a "standard" to follow.

Could you set up shfmt in a new PR? Maybe set up sh-checker GitHub Action?

@a1346054 a1346054 marked this pull request as draft September 30, 2021 01:36
@a1346054
Copy link
Contributor Author

I'd like to rework this PR and implement all the suggestions. Feel free to cherrypick the various commits though, or do whatever else is desired.

@karbassi
Copy link
Member

I'd like to rework this PR and implement all the suggestions. Feel free to cherrypick the various commits though, or do whatever else is desired.

We'll wait for your rework. Thanks again!

@chrysle
Copy link
Contributor

chrysle commented Mar 5, 2023

@a1346054 Is this still in progress or can it be closed?

@a1346054
Copy link
Contributor Author

a1346054 commented Mar 6, 2023

It can be closed for now, there are many pending PRs and shfmt/shellcheck can be setup at any point once the PRs are merged.

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.

4 participants