onCommandCompletion
Trigger an event upon a command’s completion
onCommandCompletion
events are triggered after a command has finished executing in the interactive terminal.
Background processes or commands ran from inside aliases, functions, nested blocks or from shell scripts cannot trigger this event. This is to protect against accidental race conditions, infinite loops and breaking expected behaviour / the portability of Murex scripts. On those processes directly ran from the prompt can trigger this event.
event onCommandCompletion name=command { code block }
!event onCommandCompletion name
<command>
Name of command that triggers this eventThe following payload is passed to the function via stdin:
{
"Name": "",
"Interrupt": {
"Command": "",
"Parameters": [],
"Stdout": "",
"Stderr": "",
"ExitNum": 0
}
}
This is the name you specified when defining the event.
Name of command executed prior to this event being triggered.
The command line parameters of the aforementioned command.
This will be an array of strings, like @ARGV
.
This is the name of the Murex named pipe which contains a copy of the stdout from the command which executed prior to this event.
You can read this with read-named-pipe
. eg
» <stdin> -> set: event
» read-named-pipe: $event.Interrupt.Stdout -> ...
This is the name of the Murex named pipe which contains a copy of the stderr from the command which executed prior to this event.
You can read this with read-named-pipe
. eg
» <stdin> -> set: event
» read-named-pipe: $event.Interrupt.Stderr -> ...
This is the exit number returned from the executed command.
This event doesn’t have any $EVENT_RETURN
parameters.
In this example we check the output from pacman
, which is ArchLinux’s package management tool, to see if you have accidentally ran it as a non-root user. If the stderr contains a message saying you are no root, then this event function will re-run pacman
with sudo
.
event onCommandCompletion sudo-pacman=pacman {
<stdin> -> set event
read-named-pipe $event.Interrupt.Stderr \
-> regexp 'm/error: you cannot perform this operation unless you are root/' \
-> if {
sudo pacman @event.Interrupt.Parameters
}
}
Stdout and stderr are both written to the terminal’s stderr.
alias
): Create an alias for a commandif
): Conditional statement to execute different blocks of code depending on the result of the conditionevent
): Event driven programming for shell scriptsfunction
): Define a function block<stdin>
): Read the stdin belonging to the parent code blockregexp
): Regexp tools for arrays / lists of stringsconfig
): Query or define Murex runtime settingsARGV
(json): Array of the command name and parameters within a given scopeonPrompt
: Events triggered by changes in state of the interactive shellThis document was generated from builtins/events/onCommandCompletion/oncommandcompletion_doc.yaml.
This site's content is rebuilt automatically from murex's source code after each merge to the master
branch. Downloadable murex binaries are also built with the website.
Last built on Tue Dec 10 22:56:57 UTC 2024 against commit 60f05a260f05a227caf73dd5b3478e3cb3f4bb24e46745b.
Current version is 6.4.1005 (develop) which has been verified against tests cases.