System: Lubuntu 14.04 LTS
I want to know if it's possible to modify the alert
alias provided in ~/.bashrc
in a particular way. This is the original alert
:
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
Use of default alias “alert” explains what it does.
And here is an example of the default notification on my system (using xfce4-notify
) when I run ls; alert
which, of course, completes successfully:
If I run a nonsensical command, asdfgh; alert
, I see this:
The terminal
icon has been replaced with the error
icon because of
-i "$([ $? = 0 ] && echo terminal || echo error)"
As of now, the notification has just two items:
- the icon which is terminal
or error
depending on the success of the "previous" command
- the command itself (ls
in the first case and asdfgh
in the second)
I can modify the existing alias to include a line of text above the command like this:
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "Task finished" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
Then, if I run ls; alert
and asdfgh; alert
I get the notifications shown below.
My question is this: Both notifications show "Task finished" but can the same logic that is used to decide whether the terminal
icon or the error
icon is shown be applied again to determine which text string is shown above the command? So, if the terminal
icon displays, the text would be "Task finished" but if the error
icon displays, the text could something like "Something went wrong!"
sed
command (I should have fixed it). – kos Mar 23 '16 at 06:27sed
by default interprets patterns as EREs, which require escaping+
. In fact escaping+
on your original command works for me. Just curious, whichsed
are you using? – kos Mar 23 '16 at 06:35\+
in your modified version was interpreted as an escaped markdown special character and the \ just didn't show up. However I simplified that command a little bit more in case you're interested. – kos Mar 23 '16 at 07:42