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: set options before load #1

Conversation

gaelicWizard
Copy link

Description

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.

Motivation and Context

Along with upstream PR 119, this should make things safe and reliable to use.

How Has This Been Tested?

A variation of this is live on my main branch.

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.

seefood and others added 23 commits May 19, 2021 10:54
- Remove limitation on OS.
- Add search for Mac OS X developer tools locations by using `xcrun` instead of trying to guess paths.
- �Add search for locations based on path of `$GIT_EXE` (set by `lib/theme`).
skip go tests when go is not available
completion/git: improvements and linting
…autosave-history-plml

* 'master' of https://github.com/bash-it/bash-it: (114 commits)
  ci: Bump go to 1.17 from 1.14
  skip go tests when go is not available
  plugins: Add ble.sh plugin
  clean up pyenv plugin
  Lint: prepare `lib/utilities` for `shellcheck` (Bash-it#1933)
  plugin/base: improvements (Bash-it#1930)
  plugins/percol: `bind`
  completion/git: `shfmt` && `shellcheck`
  completion/git: expand search range
  plugin/percol: `shellcheck` & `shfmt`
  plugins/percol: use `_command_exists`
  completion/pip: simplify code flow
  plugin/less-pretty-cat: remove `|| cat`
  completion/wpscan: simplify code flow (whitespace)
  plugins/less-pretty-cat: simplify code flow
  plugins/less-pretty-cat: use `_command_exists`
  lib/helpers: cite `_bash-it-find-in-ancestor()`
  gradle: adopt `_bash_it_find_in_ancestor()`
  lib/helpers: new function `_bash-it-find-in-ancestor()`
  completion/laravel: simplify code flow
  ...
The tilde should not have been escaped, and in fact I did not have it escaped in my main branch, but the PR I submitted did have it escaped and...now it shows up in the prompt line for all the PowerLine themes... oops.
theme/powerline: fix an oops in the last patch
alsö fix usage example of `_bash-it-array-contains-element()`
No need to `rm` when we overwrite the file the line after next. Alsö, use `>|` in case the user sets `noclobber`; we do expressly intend to overwrite the file in this case.
See the discussions in Bash-it@953e422#commitcomment-58148656 . Tested with bash 5.1 and  bash 3.2
Add history flushes on each command to the powerline themes
Use $XDG_CACHE_HOME environment constant instead of placing a tmp/cache folder inside the bash-it data repo. If not defined, fall back to current behavior.

This resolves Bash-it#1904.
Doesn't show up on my shellcheck 0.7.2, but does for NoahGorny!
The existing function `_bash-it-grep()` is weird. New function `_bash-it-egrep()` just does the thing without requiring two subshells and manual invocation.
@cornfeedhobo
Copy link
Owner

cornfeedhobo commented Oct 20, 2021

@gaelicWizard I tested this, but didn't include your changes to the preexec lib. With your init.d modifications in place, it seems like everything works as expected. At this point, I think you should close this PR and open one directly on the core bash-it repo to modify bash_it.sh and vendor/init.d/preexec.bash.

Edit: to be clear, I don't think we should wait on rcaloras/bash-preexec#119. from my testing, what you've figured out works with preexec as-is.

@gaelicWizard
Copy link
Author

The problem is that without some changes to upstream, the "current" command passed in to the preexec function(s) may be inaccurate.

@cornfeedhobo
Copy link
Owner

Well, the preexec owner has been very polite and pretty clear that they aren't going to merge any of our PRs. The fact that iTerm ships with a patched version of preexec puts a lot of weight on the pattern of end-users working around any preexec issues. I think we have to accept this reality and find a way forward on our own.

Within that context, let me know if you have any other clever ideas. I'll try to think about this at my next free iteration cycle.

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
Copy link
Author

I'm just butt-hurt that (after being grumpy) I put in the work to fix their code to do everything they wanted, add emulation of user-configured preference while still doing their mangling (from another patch), and fall back to $BASH_COMMAND when $HISTCONTROL is read-only preventing their mangling, and added your compatibility for Bash 3.2+, and they just DGAF.

Like, I get it they dude just wants to do his thing but...like my combined patch does do his thing and alsö our thing. 😢 #sadpanda

(I drink the open source cool-aid; I always imagine that everyone is altruistic and out to help each other (within reason), &c, &c.)

And on top of that, once I realized same dude alsö runs BashHub, I realized that actually that's kinda cool and makes total sense why he wants to make sure history entries don't silently disappear, but alsö it's extremely creepy that a no-security cloud sync service goes out of it's way to silently and without documentation alter a user-configured setting which many users rely* on to hide passwords from their shell history file. Like, literally I would specifically want to hide some history from the automatic cloud sync service.

  • It's is not a good feature to rely on security-wise, but that doesn't change reality that people do.

Anyway, enough whining. 😃

@cornfeedhobo
Copy link
Owner

@gaelicWizard Yeah, I think that's where we see projects get forked. You could always start bash-preexec-ng or something

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.

6 participants