lib: Add on-disable-callback for plugins to use

pull/1622/head
Noah Gorny 2020-06-20 14:37:21 +03:00
parent 4f4bae95e4
commit bda85c3679
2 changed files with 17 additions and 0 deletions

View File

@ -43,3 +43,8 @@ For `aliases`, `plugins` and `completions`, the following rules are applied that
Having the order based on a numeric priority in a common directory allows for more flexibility. While in general, aliases are loaded first (since their default priority is 150), it's possible to load some aliases after the plugins, or some plugins after completions by setting the items' load priority. This is more flexible than a fixed type-based order or a strict alphabetical order based on name. Having the order based on a numeric priority in a common directory allows for more flexibility. While in general, aliases are loaded first (since their default priority is 150), it's possible to load some aliases after the plugins, or some plugins after completions by setting the items' load priority. This is more flexible than a fixed type-based order or a strict alphabetical order based on name.
These items are subject to change. When making changes to the internal functionality, this page needs to be updated as well. These items are subject to change. When making changes to the internal functionality, this page needs to be updated as well.
## Plugin Disable Callbacks
Plugins can define a function that will be called when the plugin is being disabled.
The callback name should be `{PLUGIN_NAME}_on_disable`, you can see `gitstatus` for usage example.

View File

@ -318,6 +318,17 @@ _bash-it-describe ()
printf '%s\n' "$ bash-it disable $file_type <$file_type name> [$file_type name]... -or- $ bash-it disable $file_type all" printf '%s\n' "$ bash-it disable $file_type <$file_type name> [$file_type name]... -or- $ bash-it disable $file_type all"
} }
_on-disable-callback()
{
_about 'Calls the disabled plugin destructor, if present'
_param '1: plugin name'
_example '$ _on-disable-callback gitstatusd'
_group 'lib'
callback=$1_on_disable
_command_exists $callback && $callback
}
_disable-plugin () _disable-plugin ()
{ {
_about 'disables bash_it plugin' _about 'disables bash_it plugin'
@ -326,6 +337,7 @@ _disable-plugin ()
_group 'lib' _group 'lib'
_disable-thing "plugins" "plugin" $1 _disable-thing "plugins" "plugin" $1
_on-disable-callback $1
} }
_disable-alias () _disable-alias ()