Skip to content

Bash prompt hooks for before and after a command

License

Notifications You must be signed in to change notification settings

spl/bash-prompt-hooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

travis-ci codecov

bash-prompt-hooks

preexec and precmd hooks for the Bash prompt. This is a fork of bash-preexec that has been simplified. (See the ChangeLog for details.)

Usage

First, get the script. For example:

$ curl https://raw.githubusercontent.com/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.bash

Finally, 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 $

Testing

Run the tests using Bats:

$ bats test

About

Bash prompt hooks for before and after a command

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages