Package hook

import "github.com/BurntSushi/wingo/hook"
Overview
Index

Overview ▾

package hook defines, reads and executes hooks in Wingo. This package must be initialized with a Gribble execution environment, and a file path to a configuration file specifying user defined hooks.

The hook package defines only a set number of hook groups that the user can use to execute arbitrary commands.

Whenever Wingo enters a state described by a hook group, Fire is called with the appropriate hook group (and arguments if relevant). Adding a new hook group only requires a new constant and a new entry in the unexported 'groups' variable.

Please see config/hooks.wini in the Wingo project directory for an explanation of how user defined hooks can be specified: https://github.com/BurntSushi/wingo/blob/master/config/hooks.wini

func Fire

func Fire(hk Type, args Args)

Fire will attempt to run every hook in the group specified, while replacing special strings in every command executed with those provided by args.

Running a hook is a two step process. First, the match conditions are executed. If all match conditions return true, we proceed to execute all of the consequences. If any of the match conditions are false, we stop and condinue on to the next hook.

Note that Fire immediately return a channel, as it executes in its own goroutine. The channel can be used to block until Fire has finished.

func Initialize

func Initialize(env *gribble.Environment, fpath string)

Initializes the hooks package with a Gribble execution environment and a file path to a wini formatted hooks configuration file. If the initialization fails, only a warning is logged since hooks are not essential for Wingo to run.

type Args

type Args struct {
    Client string
}

Args represents a value that specifies what special strings get replaced with in user defined hooks. So for instance, the "focused" hook is specifically defined on a particular client, so its hook is fired like so:

args := Args{
	Client: "identifier of window being focused",
}
hook.Fire(hook.Focused, args)

type Type

type Type string
const (
    Startup   Type = "startup"
    Restarted Type = "restart"
    Managed   Type = "managed"
    Focused   Type = "focused"
    Unfocused Type = "unfocused"
)

All available hook groups. Each hook group corresponds to some action in Wingo. When that action happens, every hook in the corresponding group is fired.