-----------------------------------------------------------------------------
-- |
-- Module      : XMonad.Hooks.Script
-- Description : Simple interface for running a ~\/.xmonad\/hooks script with the name of a hook.
-- Copyright   : (c) Trevor Elliott <trevor@galois.com>
-- License     : BSD3-style (see LICENSE)
--
-- Maintainer  : Trevor Elliott <trevor@galois.com>
-- Stability   : unstable
-- Portability : unportable
--
-- Provides a simple interface for running a ~\/.xmonad\/hooks script with the
-- name of a hook.
--
-----------------------------------------------------------------------------

module XMonad.Hooks.Script (
    -- * Usage
    -- $usage

    -- * Script Hook Interface
    execScriptHook
  ) where

--
-- Useful Imports
--
import XMonad

-- $usage
--
-- This module allows you to run a centrally located script with the text
-- name of a hook.  The script is assumed to be located at @~\/.xmonad\/hooks@.
--
-- For example, if you wanted to run the hook "startup" in your script every
-- time your startup hook ran, you could modify your xmonad config as such:
--
-- > main = xmonad $ def {
-- >   ...
-- >   startupHook = execScriptHook "startup"
-- >   ...
-- >   }
--
-- Now, every time the startup hook runs, the command
-- @~\/.xmonad\/hooks startup@ will also.

-- | Execute a named script hook
execScriptHook :: String -> X ()
execScriptHook :: String -> X ()
execScriptHook String
hook = do
  String
xmonadDir <- (XConf -> String) -> X String
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Directories' String -> String
forall a. Directories' a -> a
cfgDir (Directories' String -> String)
-> (XConf -> Directories' String) -> XConf -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XConf -> Directories' String
directories)
  let script :: String
script = String
xmonadDir String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"/hooks "
  String -> X ()
forall (m :: * -> *). MonadIO m => String -> m ()
spawn (String
script String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
hook)