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

preexec: work around upstream mangling of $HISTCONTROL #1979

Merged
merged 2 commits into from
Nov 1, 2021

Conversation

gaelicWizard
Copy link
Contributor

@gaelicWizard gaelicWizard commented Oct 20, 2021

Description

This is a work around for the refusal of bash-preexec upstream to fix their mangling of user's $HISTCONTROL. See upstream PR 119 for a complete, working patch which maintains their desired behavior, while alsö allowing the user to choose their own settings including fall-back code to emulate user intent, and fall-back code for close-enough when the user forces $HISTCONTROL, and compatibility with Bash 3.2–5.x.

Motivation and Context

This workaround is intended to avoid the need to patch upstream (see #1966). We could of course just patch upstream and carry the patch ourselves, but that would introduce additional friction for updates in the future.

Basically, this asks the bash-preexec lib to not run it's initializer when we load it, then we overwrite the problematic function, then we call the initializer ourselves. Result: no patch, no mangling.

How Has This Been Tested?

Tested? Where we're going, we don't need testing. (@cornfeedhobo tested this on his system, and a version of this has been live in my main branch for months.)

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 preexec-histcontrol branch 2 times, most recently from 8db5333 to 5fb69dd Compare October 20, 2021 19:12
@gaelicWizard gaelicWizard marked this pull request as ready for review October 20, 2021 19:12
@gaelicWizard
Copy link
Contributor Author

@cornfeedhobo, I believe this is ready to go. Could you give it a spin to make sure?

By setting `__bp_delay_install`, we avoid any immediate initialization at all. We then override two troublesome functions before calling `__bp_install_after_session_init()`.

The `__bp_install_after_session_init()` function doesn't enable the DEBUG trap, just sets `$PROMPT_COMMAND` to include `__bp_install()`, so the actual final `$PROMPT_COMMAND` is not finished, and DEBUG trap set, until after the first prompt is displayed.
@gaelicWizard gaelicWizard changed the title Preexec histcontrol preexec: work around upstream mangling of $HISTCONTROL Oct 20, 2021
_bash-preexec_ passes the "current" command line as `$1`, but this is unreliable and we explicitly discourage it's use.

Use `$BASH_COMMAND` instead.
@cornfeedhobo
Copy link
Member

@gaelicWizard looks good, but how did this xterm stuff sneak in?

@gaelicWizard
Copy link
Contributor Author

gaelicWizard commented Oct 27, 2021

looks good, but how did this xterm stuff sneak in?

plugin/xterm uses $1 from bash-preexec so I modified it to use $BASH_COMMAND rather than breaking it, as we're modifying specifically that. I'd rather not commit a change that breaks something else. I put notes in the commit message.

@cornfeedhobo
Copy link
Member

Oh good point. In my haste I didn't think to check commit messages. Btw, thank for for being disciplined and thinking about the quality of your commit messages. That's something I'm trying to improve on as well.

Copy link
Member

@cornfeedhobo cornfeedhobo left a comment

Choose a reason for hiding this comment

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

@NoahGorny For posterity, could I get your sign off before merging? I've tested on two hosts and I think this is a good compromise.

@NoahGorny NoahGorny merged commit ab3b8b8 into Bash-it:master Nov 1, 2021
@gaelicWizard gaelicWizard deleted the preexec-histcontrol branch December 27, 2021 21:33
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