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

plugin/percol shellcheck #1956

Merged
merged 3 commits into from
Sep 28, 2021
Merged

Conversation

gaelicWizard
Copy link
Contributor

@gaelicWizard gaelicWizard commented Sep 19, 2021

Description

Adopt _command_exists, use _log_warning, some cleanup, shellcheck, and finally shfmt.

Motivation and Context

This was part of my _command_exists branch (#1938) but was out of scope.

How Has This Been Tested?

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 gaelicWizard force-pushed the plugin-percol branch 2 times, most recently from d6cdb58 to 5e87c53 Compare September 20, 2021 05:14
@gaelicWizard gaelicWizard changed the title DRAFT: plugin/percol shellcheck plugin/percol shellcheck Sep 20, 2021
@gaelicWizard gaelicWizard marked this pull request as ready for review September 20, 2021 05:16
@davidpfarrell
Copy link
Contributor

Update Unrelated Files In The PR Is The Devil!

@gaelicWizard
Copy link
Contributor Author

Rebased on master, no other changes to PR

Addresses Bash-it#1632

And use `_log_warning`.

Alsö, code style cleanup: quote things, handle unbound parameters, &c.

Alsö alsö, short-circuit if not installed or inadequate _Bash_ version.
According to `shellcheck`, the `_tac` alias simply doesn't work. At all. Ever. See SC2262 and SC2263.
Move `bind` below function definition
Copy link
Contributor

@davidpfarrell davidpfarrell left a comment

Choose a reason for hiding this comment

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

I'm pretty happy with this so I'm approving it BUT ...

There could have been some acknowledgement that this PR deprecates using tac when present in favor of always using tail -r ...

@gaelicWizard
Copy link
Contributor Author

I'm pretty happy with this so I'm approving it BUT ...

There could have been some acknowledgement that this PR deprecates using tac when present in favor of always using tail -r ...

I did. It's in the commit notes: according to shellcheck, the _tac alias simply never worked. Please don't claim that I did not specifically call that out.

@davidpfarrell
Copy link
Contributor

I did. It's in the commit notes

Hey @gaelicWizard, apologies for not noticing your related commit message.

TIL that clicking the ... on the commit note in the PR comments will expand them (I will be doing this going forward)

The alias approach was definitely borked !

BUT

There are other ways to accomplish the tac || tail -r invocation.

I still feel that choosing to deprecate tac was worth calling out in the PR description.

SIDE NOTE:

I also wish the original PR for this had a comment in the code explaining the use.

I was not able to confirm either of :

  • tac is noticeably more performant than tail -r
  • tail -r is not fully portable

Without one of those being true, I'm not sure why one would add that logic present in the first place ...

@NoahGorny
Copy link
Member

I think this is mergable right now, the tac thing can be opened as a separate issue

@NoahGorny NoahGorny merged commit 05aac8e into Bash-it:master Sep 28, 2021
@gaelicWizard gaelicWizard deleted the plugin-percol branch September 29, 2021 23:00
@gaelicWizard
Copy link
Contributor Author

gaelicWizard commented Oct 18, 2021

@davidpfarrell, I had actually never heard of tac before and had to Google it. (cat, backwards...😑) Doesn't exist on Mac anyway.

Since literally zero people use this plugin, as it's been broken since original commit (except for someone who has _tac previously defined in their environment, or has some kind of double-invocation bug where the plugin gets loaded, the function gets run (thereby defining the alias, but failing to run successfully), then the plugin gets loaded again (this time with the alias already defined)), I didn't think any further about the impact of using cat or tail -r.

That said, I'm trying out percol now so maybe I'll have some more thoughts in the future or at least be able to offer some intuition about how this runs.

EDIT: found a very-related discussion about tac vs tail -r for history sorting in Fish.

@gaelicWizard
Copy link
Contributor Author

Final thought for now:

tac and tail -r seem indistinguishable performance wise on my 16k history:

$ TAC='tail -r'
$ time { history | ${TAC} | sed -e 's/^\ *[0-9]*\ *//' ; } | wc -l
   16179

real    0m4.382s
user    0m1.839s
sys     0m2.616s
$ TAC='tac'
$ time { history | ${TAC} | sed -e 's/^\ *[0-9]*\ *//' ; } | wc -l
   16181

real    0m4.306s
user    0m1.756s
sys     0m2.621s

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.

3 participants