Commit graph

200 commits

Author SHA1 Message Date
Ryan Caloras
5ae4758c36
Update README to include WezTerm and Atuin
Added WezTerm and Atuin to the list of projects using this.
2026-08-23 21:33:23 -04:00
Ryan Caloras
d866eeefdb Preparing to tag v0.7.0 2026-08-23 21:17:41 -04:00
Ryan Caloras
3281b825cb Add release automation script
Add script/release to update the version, run tests, create and push
the release commit and tag, and draft GitHub release notes.

Usage:
  script/release --dry-run 0.7.0
  script/release 0.7.0
  script/release 0.7.0 "Teal Otter"
2026-08-22 22:46:31 -04:00
Koichi Murase
66e913cd9d
Remove the local declaration of "{preexec,precmd}_functions" (#182) 2026-07-06 06:50:11 +09:00
Koichi Murase
04f63834b5
Merge pull request #187 from gnachman/fix/preserve-exit-status-on-early-returns 2026-06-19 19:04:30 +09:00
Koichi Murase
c1c32832eb Test that __bp_precmd_invoke_cmd in PROMPT_COMMAND preserves $_ 2026-06-19 19:02:59 +09:00
George Nachman
d0498b0bca Preserve $? and $_ on __bp_precmd_invoke_cmd early returns
__bp_precmd_invoke_cmd saves the previous command's exit status into
__bp_last_ret_value at the top and restores it via __bp_set_ret_value
on the normal exit path. Two early-return paths bypass that restore:

1. The `(( __bp_inside_precmd > 0 )); then return` reentrancy guard
   leaves $? equal to the exit status of the `(( ... ))` test, which
   is always 0 when the condition is true.

2. The `return 0` inside the nested-call-frame branch (the "another
   framework saved our PROMPT_COMMAND" case) explicitly clobbers $?
   to 0.

Both paths run before reaching the trailing __bp_set_ret_value, so
the next command in PROMPT_COMMAND (and any direct caller of
__bp_precmd_invoke_cmd) sees $? = 0 instead of the user's actual
last exit status. Add an explicit __bp_set_ret_value call (and
replace `return 0` with a bare `return`) on both early-return paths
so $? and $_ flow through cleanly.

Includes bats coverage for both paths. The path-2 test clears
BATS_VERSION inside the nested call because the path's own guard
short-circuits when BATS_VERSION is set (so bats's own scaffolding
doesn't trip it).
2026-06-19 19:02:59 +09:00
Ryan Caloras
8df9f66c29
Fix Bashhub logo link in README
Updated the Bashhub logo link in README.md.
2026-04-15 06:50:39 -04:00
Koichi Murase
a220343bf2
Merge pull request #180 from Rogach/fix/login-shell-first-preexec 2026-04-08 15:56:54 +09:00
Jeffrey Faer
48b5494771
Properly check to see if we're already installed in PROMPT_COMMAND (#185)
If there's no PROMPT_COMMAND, we will set it to be $prolog\n$epilog.
The glob $prolog\n*\n$epilog does not match that PROMPT_COMMAND since
there's only a single newline.

Co-authored-by: Koichi Murase <myoga.murase@gmail.com>
2026-04-08 15:42:21 +09:00
Jeffrey Faer
35fead9f34
Allow __bp_precmd_invoke_cmd to be called from __bp_install. (#184)
Fix #183
2026-04-08 15:09:41 +09:00
Platon Pronko
5d8ba5dd9c Fix initialization hook in the PROMPT_COMMAND array on Bash 5.1+
If PROMPT_COMMAND contains unrelated commands before installing
bash-preexec, then these unrelated commands may trigger
`__bp_preexec_invoke_exec`, which causes interactive mode marker to be
unset.  This causes preexec to be missed for the first interactive
command, since bash-preexec assumes that we are still not interactive.

Example of what can trigger such behavior: on Arch Linux in a login
shell /etc/profile.d/80-systemd-osc-context.sh causes
`__systemd_osc_context_precmdline` to be added to PROMPT_COMMAND, and
`__systemd_osc_context_precmdline` trips
`__bp_preexec_interactive_mode`.

This patch avoids the issue by appending our initialization hook as
the last element of PROMPT_COMMAND in Bash >= 5.1, instead of
appending the hook to the first element of PROMPT_COMMAND.
2026-04-08 11:39:54 +09:00
Koichi Murase
fdd5ba732f Remove whitespaces around removed semicolons in __bp_sanitize_string
The remaining whitespaces are harmless and do not cause behavioral
differences in actual application.  However, this causes differences
in the expected results of test cases in test/bash-preexec.bats.  We
want to remove the whitespaces to normalize the expected results.  In
particular, we treat PROMPT_COMMAND as an array based on the Bash
version, which causes the version depedenence of the expected results
with the current implementation.

* To make the expected results of test cases consistent, this patch
  changes __bp_sanitize_string to remove the whitespaces.
* We also use [:blank:] instead of the variable sp=$' \t'.
2026-04-08 11:32:48 +09:00
Koichi Murase
23011bb11b
Merge pull request #143 from akinomyoga/adjust-PROMPT_COMMAND
Re-adjust `PROMPT_COMMAND` when `PROMPT_COMMAND` is modified elsewhere
2026-04-07 12:23:45 +09:00
Koichi Murase
0b02569057 Suppress PROMPT_COMMAND hooks from inside saved strings
We try to remove the existing hooks before the re-adjustment of
PROMPT_COMMAND, but it might not work when another framework saves the
original value of `PROMPT_COMMAND` in another variable and tries to
call it from inside their `PROMPT_COMMAND` hook.  For example,
Starship does that [1].  In such a case, our hooks would be called
several times unexpectedly.  To avoid this situation, we process our
hooks only when the hooks are called at the top level.

[1] 3d47468414/src/init/starship.bash (L97)
2026-04-07 12:22:47 +09:00
Koichi Murase
66cf0b3464 Check PROMPT_COMMAND in precmd and adjust it if necessary 2026-04-07 12:22:47 +09:00
Koichi Murase
ae593dbdbb Include the no-op colon reduction in __bp_sanitize_string 2026-04-07 12:22:47 +09:00
Koichi Murase
0a2f67be57 Work around shopt -u extquote 2026-04-07 12:22:47 +09:00
Koichi Murase
3440806a53 Suppress shellcheck false positives
These are oversights of commit 21a26bf.

* Suppress SC2128 for array PROMPT_COMMAND
* Suppress SC2016 for the command string containing expansions like
  '__bp_install "$_"'
2026-04-07 12:22:17 +09:00
Koichi Murase
aab0589add
Merge pull request #166 from akinomyoga/PS0-funsub
Use a function substitution in `$PS0` for preexec in Bash >= 5.3
2026-03-30 22:51:26 +09:00
Koichi Murase
21a26bfff8 Fix handling of "$_" 2026-03-07 12:18:48 +09:00
Koichi Murase
0a44524054 Introduce "__bp_hook_preexec_proc" for consistent preexec handling
The Copilot agent suggested to check readonly variables in a finer way
so that PS0 is not checked when PS0 is not used according to the
current version of Bash.  However, this duplicates the complicated
test for the version requirement (( BASH_VERSINFO[0] > 5 ||
(BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >= 3) )) for selecting the
preexec strategy.  However, it is more manageable to store the
currently selected preexec strategy in a variable, and switch the
behavior based on the saved strategy value.

For this purpose, this patch adds a new global variable
"$__bp_hook_preexec_proc" that contains the function name to install
the hook.  Then, we switch the check for readonly variables based on
the value of "$__bp_hook_preexec_proc".  Now, the conditional checks
in Bats tests also use this variable to switch the tests.
2026-03-07 12:18:48 +09:00
Koichi Murase
fe9d64bf75 Use PS0 and function substitution in Bash 5.3 2026-03-07 12:18:26 +09:00
Koichi Murase
097b421556 Obtain existing DEBUG trap inside "__bp_install" 2026-03-07 12:17:32 +09:00
Koichi Murase
ad77a36865 Separate the code to determine the current command 2026-03-07 12:17:32 +09:00
Koichi Murase
794639bdc3 Separate "__bp_invoke_pre{cmd,exec}_functions"
* Do not prefix local varnames with underscores
* Make "__bp_invoke_pre{cmd,exec}_functions" return the last non-zero exit status
* Test "__bp_invoke_pre{cmd,exec}_functions"
2026-03-07 12:17:30 +09:00
Ryan Caloras
4ad5a6347e
Test against Bash 3.2, 4.4, 5.0, 5.3 in CI (#177)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 14:45:53 -05:00
Ryan Caloras
50ec4ef83e Fix typo 2026-03-06 14:20:16 -05:00
Jon Parise
aad114d22a
Mention Ghostty (#172)
Also, remove Fig, which was shut down in September 2024.
2025-12-07 13:39:35 -05:00
Jon Parise
c6b5d3da3f
Use bats-core/bats-action to set up Bats (#176)
This is the "official" (under the bats-core organization) GitHub Action
for setting up Bats in a workflow. This removes the need to manually
install the `bats` package.

Also, update to the latest actions/checkout version and use the latest
Ubuntu image.
2025-12-07 13:33:10 -05:00
Ryan Caloras
b73ed5f7f9 Preparing to tag v0.6.0 2025-08-02 23:45:27 -04:00
Jon Parise
31ce2f3fdf
Remove dependency on sed(1) for history processing (#167)
* Remove dependency on sed(1) for history processing

We post-process `history 1`'s output to extract the current command.
This processing needs to strip the leading history number, an optional
`*` character indicating whether the entry was modified (or a space),
and then a space separating character.

We were previously using sed(1) for this, but we can implement an
equivalent transformation using bash's native parameter expansion
syntax.

* Improved the substitution pattern

The history number is printed as "%5d" so we need to handle all possible
columns.

    declare -a lines=(
        "10000  history 1"
        " 1000  history 1"
        "    1  history 1"
        " 1000* history 1"
        " 1000   history 1"
    )

    for line in "${lines[@]}"; do
        echo "${line#*[[:digit:]][* ] }"
    done
2025-08-02 23:38:30 -04:00
Jon Parise
cf2c1db8f6
Improve prior_trap processing (#170)
We use `trap` to bootstrap our installation function (__bp_install). We
remove our code upon first execution but need to restore any preexisting
trap calls. We previously used `sed` to process the trap string, but
that had two downsides:

1. `sed` is an external command dependency. It needs to exist on the
   system, and we need to invoke it in a subshell (which has some
   runtime cost).
2. The regular expression pattern was imperfect and didn't handle
   trickier cases like `'` characters in the trap string:

        $ (trap "echo 'hello'" DEBUG; trap -p DEBUG)
        hello
        trap -- 'echo '\''hello'\''' DEBUG

This change removes the dependency on `sed` by locally evaluating the
trap string and extracting any prior trap. This works reliably because
we control the format our trap string, which looks like this (with
newlines expanded):

    __bp_trap_string="$(trap -p DEBUG)"
    trap - DEBUG
    __bp_install
2025-08-02 23:37:28 -04:00
Jon Parise
5cb38ca73a
Retire .travis.yml (#168)
The CI workflows now use GitHub Actions.
2025-08-02 23:35:09 -04:00
Illia Bobyr
4919c44b54
GitHub workflow: Update runner 20.04 -> 24.04 (#171)
20.04 runner has been deprecated.  For details see:

https://github.com/actions/runner-images/issues/11101
2025-08-02 23:24:51 -04:00
Koichi Murase
e8e9024d4d
Fix indentation and remove trailing semicolons (#165) 2025-01-12 21:59:03 -05:00
Koichi Murase
8926de0a1f
Exclude the bind -x commands from interactive commands (#152)
* Exclude the `bind -x` commands from interactive commands

* Check COMP_POINT instead of possibly empty COMP_LINE

The check for COMP_LINE can fail because it can be empty in the
completion function for the empty command line "complete -F _func -E".
2024-02-25 14:24:06 -05:00
Michael Diamond
1f77dc0935
Merge pull request #151 from akinomyoga/fix-test-__bp_install
Fix false-negative test case for __bp_install
2024-02-04 11:15:18 -08:00
Koichi Murase
99d05b9ca9 Clarify the intent of the test case
Co-authored-by: Michael Diamond <dimo414@gmail.com>
2024-02-04 11:58:35 +09:00
Koichi Murase
8913ea5faf Use $__bp_install_string for a robust test case 2024-02-04 11:19:29 +09:00
Koichi Murase
2a4ac8f683 Fix false-negative test case for __bp_install
This is an oversight of changing `trap DEBUG` to `trap - DEBUG` in

https://github.com/rcaloras/bash-preexec/pull/106

The oversight did not cause a test error because the test always
succeeds.  The problem is that even if __bp_install is broken and
fails to remove `trap - DEBUG`, the current test case failed to detect
the failure and produce a false negative.  This patch fixes it.
2024-02-03 15:55:43 +09:00
Jim Winstead
f872f3fff2
Don't load if old version already present (Fixes rcaloras/bash-preexec#146) (#150) 2024-01-23 23:56:16 -05:00
Koichi Murase
fb23d474b3
Fix the test for the Bash version for shellcheck (#142)
* Fix the test for the Bash version for shellcheck

* Add parenthesis and whitespace for clarity

---------

Co-authored-by: Michael Diamond <dimo414@gmail.com>
2023-03-12 20:57:03 -04:00
Koichi Murase
7ad48e14d3
Support the array PROMPT_COMMAND in Bash 5.1+ (#141) 2023-03-12 20:27:10 -04:00
John D Pell
0c8fe466da
Better handle edge-cases in $PROMPT_COMMAND (#128)
Some libraries do things like `PROMPT_COMMAND="$PROMPT_COMMAND ; _new_addition"`, that's a space-semicolon-space. It would be counter-productive to try to account for all possibilities, so just swap the install string for a no-op.

Clean up no-op, it it's all that's left

Co-authored-by: Ryan Caloras <rcaloras@gmail.com>
2023-03-06 20:39:08 -05:00
Ryan Caloras
a44754f5c3 Fix failing test due to bats not preserving ret value
- Related to #121. Didn't notice this was failing until upgrading to
  bats 1.8.2 and the related IFS issue was fixed.
2022-11-16 12:02:55 -05:00
Koichi Murase
9c1e17b698
Addtional fixes for shellcheck (#137)
* Disable remaining shellcheck false warning

* Avoid passing empty argument to `return`

* Avoid word splitting of the exit status

* Follow the shellcheck suggestion
2022-09-11 21:39:15 -04:00
Koichi Murase
a131ff9cad
Check Bash version 3.1+ (#136) 2022-09-11 16:56:16 -04:00
adamprice2
e5790586c6
Update to remove shellcheck warnings (#135)
* add shellcheck # shellcheck shell=bash directive to allow linting

* BP_PIPESTATUS may be unused in function __bp_precmd_invoke_cmd, ignore

* line 174 - SC2086 (info): Double quote to prevent globbing and word splitting.

* line 249 false alarm 'SC1007 (warning): Remove space after = ', added ignore.

* line 294 SC2155 (warning): Declare and assign separately to avoid masking return values.

* line 295 SC2001 (style): See if you can use ${variable//search/replace}. Added ignore

* line 323 SC1087 (error): Use braces when expanding arrays. Disable warning

* fix indentation

* line 249 false alarm 'SC1007 (warning): empty space to '' removed shellcheck directive

Co-authored-by: Adam Price <git@blinvisible.com>
2022-09-11 12:23:37 -04:00
Michael Diamond
8bfcb39fc9
Merge pull request #133 from ayeseeem/patch-1
Fix typo in README: our -> your
2022-07-14 11:03:36 -07:00