Jumping from I3 to xmonad - Day 2 -> Setup xmobar
Tags: xmonad, wm, xmobar
Published: 2020-11-29 18:12:33

---
title: Jumping from I3 to xmonad - Day 2 -> Setup xmobar
published: true
series: xmonad
tags: xmonad, wm, xmobar
---

Setting up xmonad is already a story, but xmobar is a completely different. 

I had in I3 a bar iBlocks bar with the following content.

![i3-iblocks-status-bar.png](https://www.dropbox.com/s/vaomeoxp1v93801/i3-iblocks-status-bar.png?raw=1)

This is of cause something what I want back, at lease in a similar fashion.
Xmobar don't show your workspaces per default. The reason is, that xmobar and xmonad are two different programs, but xmobar get the information from xmonad as hook. Some how I had difficulties without the workspace display in my bar.
So I want my workspaces back and the overview of my time tracking.

As time tracker I'm using [watson](https://tailordev.github.io/Watson/), it's an easy to use CLI time tracker.

To get the right output for xmobar I created a script:

```bash

#!/bin/bash

while :; do
    case "$1" in
        -s) 
            echo $(watson status) | sed -e "s/Project //g" -e "s/(.*)//g"
            ;;
        -l) 
            echo " $(watson log | head -n1)"
            ;;
        *)
            break
    esac
    shift
done

```

```haskell

    , Run Com "watson.sh" ["-l"] "watson" 60                                
    , Run Com "watson.sh" ["-s"] "watson2" 60 

```

This delivered something like this:

` No project started. / Friday 27 November 2020 (12h 04m 17s) `


The workspace overview tells a different story. 

This is from my xmonad settings:

```haskell

-- needed imports
import XMonad.Hooks.DynamicLog (dynamicLogWithPP, wrap, xmobarPP, xmobarColor, PP(..))

main = do 
        -- i want to have two bars. with slightly different settings
        xmproc0 <- spawnPipe "xmobar -x 0 /home/maren/.config/xmobar/xmobarrc0 -A 200"
        xmproc1 <- spawnPipe "xmobar -x 1 /home/maren/.config/xmobar/xmobarrc1 -A 200"
        xmonad $ ewmh $ docks $ def {

      -- 
      -- [block of ohter definitions]
      --

      -- defining the hook for xmobar

        logHook = myLogHook <+> dynamicLogWithPP xmobarPP
                        { ppOutput = \x -> hPutStrLn xmproc0 x  >> hPutStrLn xmproc1 x
                        , ppCurrent = xmobarColor "FGCOLOR" "" . wrap "[" "]" -- Current workspace in xmobar
                        , ppVisible = xmobarColor "COLOR2" ""                -- Visible but not current workspace
                        , ppHidden = xmobarColor "COLOR3" "" . wrap "*" ""   -- Hidden workspaces in xmobar
                        , ppSep =  "<fc=FGCOLOR> <fn=2>|</fn> </fc>"          -- Separators in xmobar
                        , ppUrgent = xmobarColor "COLOR8" "" . wrap "!" "!"  -- Urgent workspace
                        , ppExtras  = [windowCount]                           -- # of windows current workspace
                        , ppOrder  = \(ws:l:t) -> [ws]
                        }
    } 
```

And here is the template:

```haskell
       , template = " <action=`xdotool key control+alt+g`><icon=haskell_20.xpm/> </action><fc=#cfddeb>  |</fc> %StdinReader% }{ <fc=#cfddeb><fn=2>|</fn> </fc><fc=#6F94CF> %cpu% </fc><fc=#cfddeb> <fn=2>|</fn></fc> <fc=#6F94CF> %memory% </fc><fc=#cfddeb> <fn=2>|</fn></fc> <fc=#6F94CF> %disku% </fc><fc=#cfddeb> <fn=2>|</fn></fc>  <fc=#B993B2> %enp0s31f6% </fc><fc=#cfddeb> <fn=2>|</fn></fc> <fc=#cfddeb> <fn=2>|</fn></fc> <fc=#B993B2> %wlp3s0wi% </fc><fc=#cfddeb> <fn=2>|</fn></fc> <fc=#5C54AA> %date% </fc><fc=#cfddeb><fn=2>|</fn></fc> <fc=#5C54AA>%watson2% / %watson% | %battery% %trayerpad%</fc> "

```

You can ignore the <fc> tags the are used to get colors in the bar. Everything which is between % are the variables for replacing the content.

The `StdinReader` variable provides the workspace display. And here is the result:

![xmonad-bar.png](https://www.dropbox.com/s/euv2vbvet4zrks1/xmonad-bar.png?raw=1)

You can see the full configuration [here - xmonad](https://github.com/mafflerbach/dotfiles/blob/master/xmonad/xmonad.hs) and [here - picom](https://github.com/mafflerbach/dotfiles/blob/master/i3/compton.conf)