Nifty bash trick?

T.C. Hollingsworth tchollingsworth at gmail.com
Mon Oct 3 03:02:35 UTC 2011


On Sun, Oct 2, 2011 at 6:21 PM, Christopher Svanefalk
<christopher.svanefalk at gmail.com> wrote:
> Quick question, what do I add to what config file to make bash run
> 'clear' prior to executing whatever commands I run in the terminal?
> Thanks in advance?

Add this to your ~/.bashrc:


preexec () { clear; }
preexec_invoke_exec () {
    [ -n "$COMP_LINE" ] && return  # do nothing if completing
    local this_command=`history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//g"`;
    preexec "$this_command"
}
trap 'preexec_invoke_exec' DEBUG


Tip of the hat to:
http://superuser.com/questions/175799/does-bash-have-a-hook-that-is-run-before-executing-a-command/175802#175802

-T.C.


More information about the users mailing list