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

lib/helpers: lint, cleanup, & improvements #1934

Merged
merged 16 commits into from
Jan 24, 2022

Conversation

gaelicWizard
Copy link
Contributor

@gaelicWizard gaelicWizard commented Sep 9, 2021

Please see individual commit notes for detailed information if relevant.

Description

This is a partial PR covering only the lib/helpers portion of #1917 in support of #1696 and fixes #1978.

This PR touches many files due to some scope overlap with lib/utilities and due to touching BATS: I needed to add several .keep files to protect empty folders from git.

Closes #1978.

Motivation and Context

My shellcheck branch (#1917) got a bit large, so I'm splitting it up. This PR includes only changes to lib/helpers (and a little lib/utilities):

  • Make _is_function behave similarly to _command_exists, _completion_exists, _binary_exists, &c.
  • Make pathmunge not add not-existing directories to $PATH
  • Use _bash-it-get-component-type-from-path() and ...name-from-path()
  • Fix all_groups() from 10 seconds to run to less than one tenth of a second.
  • Refactor tests for plugin/ruby as they weren't working on Mac OS X, turns out due to the fact that we set $HOME to $TMPDIR in our test suite on Mac, which I only figured out after messing around with BATS quite a bit.
  • make _bash-it-component-item-is-enabled() not rely on reading every single file from disk, parsing metadata, then grep and awk.

How Has This Been Tested?

The full test suite and shellcheck have run on #1917 and this is part of my main branch since september.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the code style of this project.
  • If my change requires a change to the documentation, I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • If I have added a new file, I also added it to clean_files.txt and formatted it using lint_clean_files.sh.
  • I have added tests to cover my changes, and all the new and existing tests pass.

gaelicWizard and others added 16 commits January 18, 2022 11:02
- Don't write to disk, just pipe.
- Don't loop, just do all functions.

Performance of old implementation on my system:
```
real    0m9.996s
user    0m5.318s
sys     0m9.126s
```

Performance of new implementation on my system:
```
real    0m0.052s
user    0m0.069s
sys     0m0.025s
```
The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`!
Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c.

Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible.

Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here?

Alsö, don't add not-existing directories to `$PATH` in `pathmunge()`.

Finally, merge PR Bash-it#1865 from NoahGorny...and clean it a bit...
lib/helpers: lint `_bash-it-migrate()`

lib/helpers: lint `_disable-thing()`

lib/helpers: lint `_enable-thing()`

lib/helpers: lint `_help-list-aliases()`

lib/helpers: lint `_help-plugins()`

lib/helpers: some SC2034 fixes

And SC2154 in `_make_reload_alias()`

lib/helpers: lint `all_groups()`
My apologies to future `git blame` hunters ♥
- Improve `pushd`/`popd` somewhat
- local some parameters
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)
Use `_bash-it-component-item-is-enabled()`

Fix SC2295
Use curly braces when `$1` is unseparated from words in a string.
Co-authored-by: Kostas Giapis <45879751+tsiflimagas@users.noreply.github.com>
Replace weird non-globs with array and loop, as suggested by `shellcheck`. Alsö, simplify several constructs to eliminate external binaries.

Alsö, see mvdan/sh issue 558

lib/helpers: unbound positional parameters
- add some `local` variables,
- don't subshell `_typeset_functions`,
Duplicate function of existing `_bash-it-component-item-is-enabled()`.
Quote some parameter uses that don't strictly require it, but since Bash needs so many quotes everywhere else my brain worms feel better when these are quoted too.

lib/helpers: simplify some quote escapes
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.

possible search bug
3 participants