cfenollosa / bashblog

A single Bash script to create blogs. Download, run, write, done!
1.65k stars 226 forks source link

Plugins #161

Open stormdragon2976 opened 3 years ago

stormdragon2976 commented 3 years ago

This is a way for people to write and use plugins. Plugins are sourced into the program itself, so everything is available to them. the call to call_plugins could probably be added in a few more places, but this is a good starting point.

Plugins can be added in a subdirectory called plugins, or system wide in /usr/share/bashblog/plugins. I can write more information for the readme, but basically each of them can be in a file, and they are each written as a series of functions. For example, this plugin will show what you were listening to as you wrote the current post:

    [[ -z "$1" ]] && return
    sed -i '/Tags: keep-this-tag-format, tags-are-optional, beware-with-underscores-in-markdown, example/d' "$1"
    echo -n "### Composed to the sound of " >> "$1"
    playerctl metadata -f '{{artist}} - {{album}} - {{title}}' >> "$1"
    echo -e "\nTags: keep-this-tag-format, tags-are-optional, beware-with-underscores-in-markdown, example" >> "$1"
}

So, each plugin must start with the keyword plugin_ followed by where it's called, in this case pre_edit, and then should have a unique identifier, _composed. I think this will add a whole lot more flexibility to an already powerful system, and the lines of code it took to do it were minimal.