How do i run an arbitrary command like echo Done
after any command has finished?
I want to be able to put any command in the terminal and it to return the same command when its done i.e.
> pwd
/home/user
Done
> ls
...
Done
> whoami
user
Done
I know if it is something specific like cd
the code would be:
function cd () {
builtin cd $@
echo Done
}
but how do i do this for all commands?
CodePudding user response:
Ok i found 2 ways:
Bash (by Andrej Podzimek and markp-fuso):
PROMPT_COMMAND='echo Done'
ZSH:
precmd() { "echo Done" }
CodePudding user response:
With bash
. This works in a script, too. Add it to your ~/bashrc
.
function after_every_command() {
echo "last command: $BASH_COMMAND"
}
trap 'after_every_command' DEBUG