6

Is it possible to automatically add some characters at the end of each command typed in the terminal.

For example, if I write

sudo apt-get update

the shell will execute

sudo apt-get update && notify-send Done

without me writing the && notify-send Done part.

Thanks in advance!

ioanD
  • 163

2 Answers2

6

If you're using bash as your default shell, you can set PROMPT_COMMAND.

From the bash man page:

PROMPT_COMMAND
If set, the value is executed as a command prior to issuing each primary prompt.

So just paste the following line in your .bashrc to get a notification for each command:

PROMPT_COMMAND="notify-send Done"

So each time your bash prompt is called (normal behavior when a command is finished, with success or not), you'll get a notification.

Note: you'll be also notified if you press just Enter as the prompt will be displayed again.

0

You can bind some characters to to an enter key:

$ bind '"\C-M":" && echo test\n"'

This has some drawbacks, for example if you just press Enter:

-bash: syntax error near unexpected token `&&'

You can block this effect by terminating your lines with # character - it will turn appended text into a harmless comment.

Still I'd say that this sounds like a really bad idea.

Nykakin
  • 3,814