onPrompt
Events triggered by changes in state of the interactive shell
onPrompt
events are triggered by changes in state of the interactive shell (often referred to as readline). Those states are defined in the interrupts section below.
event onPrompt name=(before|after|abort|eof) { code block }
!event onPrompt name[.before|.after|.abort|.eof]
abort
Triggered if ctrl
+c
pressed while in the interactive promptafter
Triggered after user has written a command into the interactive prompt and then hit enter
before
Triggered before readline displays the interactive prompteof
Triggered if ctrl
+d
pressed while in the interactive promptThe following payload is passed to the function via stdin:
{
"Name": "",
"Interrupt": {
"Name": "",
"Operation": "",
"CmdLine": ""
}
}
This is the namespaced name – ie the name and operation.
This is the name you specified when defining the event.
This is the interrupt you specified when defining the event.
Valid interrupt operation values are specified below.
This is the command line executed, ie what you typed into the readline prompt.
Please note this is only populated if the interrupt is after.
This event doesn’t have any $EVENT_RETURN
parameters.
event onPrompt example=before {
out "This will appear before your command prompt"
}
event onPrompt example=after {
out "This will appear after you've hit [enter] on your command prompt"
out "...but before the command executes"
}
» event onPrompt echo=after { -> set event; out $event.Interrupt.CmdLine }
» echo hello world
echo hello world
hello world
Stdout and stderr are both written to the terminal. So this event can be used to provide multiple additional lines to the prompt since readline only supports one line for the prompt itself and three extra lines for the hint text.
Interrupts are run in alphabetical order. So an event named “alfa” would run before an event named “zulu”. If you are writing multiple events and the order of execution matters, then you can prefix the names with a number, eg 10_jump
This event is namespaced as $(NAME).$(OPERATION)
.
For example, if an event in onPrompt
was defined as example=eof
then its namespace would be example.eof
and thus a subsequent event with the same name but different operation, eg example=abort
, would not overwrite the former event defined against the interrupt eof
.
The reason for this namespacing is because you might legitimately want the same name for different operations (eg a smart prompt that has elements triggered from different interrupts).
event
): Event driven programming for shell scriptsconfig
): Query or define Murex runtime settingsonCommandCompletion
: Trigger an event upon a command’s completiononKeyPress
: Custom definable key bindings and macrosonPreview
: Full screen previews for files and command documentationThis document was generated from builtins/events/onPrompt/onprompt_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 Wed Sep 18 21:18:57 UTC 2024 against commit c037883c03788357164e9846c84d9f777251495d9452a8e.
Current version is 6.3.4225 (develop) which has been verified against tests cases.