User contributed modules

Ben edited this page Nov 29, 2018 · 128 revisions

We have started to maintain a repository for scripts contributed by the community: polybar-scripts.

This means that everything written in Shell, Python or Perl is collected there. Look over there!

Other languages

workspaces-xmonad (Haskell)

This plugin contains two modules, one for displaying workspaces and one for displaying title of current window. The communication between XMonad and polybar is done by named pipes to achieve speed and memory efficiency. You may adjust eventLogHook according to your preferences.

[module/workspaces-xmonad]
type = custom/script
exec = tail -F /tmp/.xmonad-workspace-log
exec-if = [ -p /tmp/.xmonad-workspace-log ]
tail = true
[module/title-xmonad]
type = custom/script
exec = tail -F /tmp/.xmonad-title-log
exec-if = [ -p /tmp/.xmonad-title-log ]
tail = true
import Data.List (sortBy)
import Data.Function (on)
import Control.Monad (forM_, join)
import XMonad.Util.Run (safeSpawn)
import XMonad.Util.NamedWindows (getName)
import qualified XMonad.StackSet as W

main = do
  forM_ [".xmonad-workspace-log", ".xmonad-title-log"] $ \file -> do
    safeSpawn "mkfifo" ["/tmp/" ++ file]

  let myConf = def
        { ...
        , logHook         = eventLogHook
        , ...
        }

eventLogHook = do
  winset <- gets windowset
  title <- maybe (return "") (fmap show . getName) . W.peek $ winset
  let currWs = W.currentTag winset
  let wss = map W.tag $ W.workspaces winset
  let wsStr = join $ map (fmt currWs) $ sort' wss

  io $ appendFile "/tmp/.xmonad-title-log" (title ++ "\n")
  io $ appendFile "/tmp/.xmonad-workspace-log" (wsStr ++ "\n")

  where fmt currWs ws
          | currWs == ws = "[" ++ ws ++ "]"
          | otherwise    = " " ++ ws ++ " "
        sort' = sortBy (compare `on` (!! 0))
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.