From bda85c36794dafbe0a6c063bfde29565dee30b09 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Sat, 20 Jun 2020 14:37:21 +0300 Subject: [PATCH] lib: Add on-disable-callback for plugins to use --- DEVELOPMENT.md | 5 +++++ lib/helpers.bash | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index ba9efe60..33276b71 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -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. 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. diff --git a/lib/helpers.bash b/lib/helpers.bash index e7ef15ba..9c4b3c43 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -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" } +_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 () { _about 'disables bash_it plugin' @@ -326,6 +337,7 @@ _disable-plugin () _group 'lib' _disable-thing "plugins" "plugin" $1 + _on-disable-callback $1 } _disable-alias ()