Convenience functions to add hooks to the prompt hook lists.
Install the elvish-modules
package using epm:
use epm
epm:install github.com/zzamboni/elvish-modules
In your rc.elv
, load this module:
use github.com/zzamboni/elvish-modules/prompt-hooks
$edit:before-readline
hooks are executed before right after the prompt is shown. $edit:after-readline
hooks are executed after the user presses Enter, before the command is executed. The typed command is passed as argument to after-readline
hooks.
Use like this:
prompt-hooks:add-before-readline { code to execute } ...
prompt-hooks:add-after-readline { code to execute } ...
Multiple hooks can be added, they execute in sequence.
Each function adds the given hooks to the corresponding variable, if it’s not there already.
fn add-before-readline {|@hooks|
each {|hook|
if (not (has-value $edit:before-readline $hook)) {
set edit:before-readline = [ $@edit:before-readline $hook ]
}
} $hooks
}
fn add-after-readline {|@hooks|
each {|hook|
if (not (has-value $edit:after-readline $hook)) {
set edit:after-readline = [ $@edit:after-readline $hook ]
}
} $hooks
}