Pass plugin names as arguments (#788)

event-args
Jorge Bucaran 3 months ago
parent 2efd33ccd0
commit ebaf0851fd
No known key found for this signature in database
GPG Key ID: E54BA3C0E646DB30

@ -130,22 +130,22 @@ Non `.fish` files and directories inside these locations will be copied to `$fis
### Event system ### Event system
Fish [events](https://fishshell.com/docs/current/cmds/emit.html) notify plugins when they're being installed, updated, or removed. Fisher notifies plugins when they're being installed, updated, or removed via [events](https://fishshell.com/docs/current/cmds/emit.html). Each relevant event handler is invoked with the plugin's name supplied as the first argument.
> Keep in mind, `--on-event` functions must be loaded when their event is emitted. So, place your event handlers in the `conf.d` directory. > Place your event handler functions in the `conf.d` directory to ensure they're loaded and ready when needed.
```fish ```fish
# Defined in flipper/conf.d/flipper.fish # Defined in flipper/conf.d/flipper.fish
function _flipper_install --on-event flipper_install function _flipper_install --on-event flipper_install --argument-names plugin
# Set universal variables, create bindings, and other initialization logic. # Set universal variables, create bindings, and other initialization logic.
end end
function _flipper_update --on-event flipper_update function _flipper_update --on-event flipper_update --argument-names plugin
# Migrate resources, print warnings, and other update logic. # Migrate resources, print warnings, and other update logic.
end end
function _flipper_uninstall --on-event flipper_uninstall function _flipper_uninstall --on-event flipper_uninstall --argument-names plugin
# Erase "private" functions, variables, bindings, and other uninstall logic. # Erase "private" functions, variables, bindings, and other uninstall logic.
end end
``` ```

@ -132,7 +132,7 @@ function fisher --argument-names cmd --description "A plugin manager for Fish"
if contains -- "$plugin" $remove_plugins if contains -- "$plugin" $remove_plugins
for name in (string replace --filter --regex -- '.+/conf\.d/([^/]+)\.fish$' '$1' $$plugin_files_var) for name in (string replace --filter --regex -- '.+/conf\.d/([^/]+)\.fish$' '$1' $$plugin_files_var)
emit {$name}_uninstall emit {$name}_uninstall $plugin
end end
printf "%s\n" Removing\ (set_color red --bold)$plugin(set_color normal) " "$$plugin_files_var | string replace -- \~ ~ printf "%s\n" Removing\ (set_color red --bold)$plugin(set_color normal) " "$$plugin_files_var | string replace -- \~ ~
set --erase _fisher_plugins[$index] set --erase _fisher_plugins[$index]
@ -188,7 +188,7 @@ function fisher --argument-names cmd --description "A plugin manager for Fish"
for file in (string match --regex -- '.+/[^/]+\.fish$' $$plugin_files_var | string replace -- \~ ~) for file in (string match --regex -- '.+/[^/]+\.fish$' $$plugin_files_var | string replace -- \~ ~)
source $file source $file
if set --local name (string replace --regex -- '.+conf\.d/([^/]+)\.fish$' '$1' $file) if set --local name (string replace --regex -- '.+conf\.d/([^/]+)\.fish$' '$1' $file)
emit {$name}_$event emit {$name}_$event $plugin
end end
end end
end end

Loading…
Cancel
Save