blob: f803d0fbd3845c930fdea9217b2c56c1e78f3008 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
{-# LANGUAGE CPP #-}
-----------------------------------------------------------------------------
-- |
-- Module : Plugins.Monitors.ArchUpdates
-- Copyright : (c) 2024 Enrico Maria De Angelis
-- License : BSD-style (see LICENSE)
--
-- Maintainer : Enrico Maria De Angelis <enricomaria.dean6elis@gmail.com>
-- Stability : unstable
-- Portability : unportable
--
-- An ArchLinux updates availablility plugin for Xmobar
--
-----------------------------------------------------------------------------
module Xmobar.Plugins.ArchUpdates (ArchUpdates(..)) where
import System.Exit (ExitCode(..))
import System.Process (readProcessWithExitCode)
import Xmobar.Run.Exec
import Xmobar.Plugins.Command (Rate)
data ArchUpdates = ArchUpdates (String, String, String) Rate
deriving (Read, Show)
instance Exec ArchUpdates where
alias (ArchUpdates _ _) = "arch"
rate (ArchUpdates _ r) = r
run (ArchUpdates (z, o, m) _) = do
(exit, stdout, _) <- readProcessWithExitCode "checkupdates" [] ""
return $ case exit of
ExitFailure 2 -> z--ero updates
ExitFailure 1 -> "pacman: Unknown cause of failure."
ExitSuccess -> case length $ lines stdout of
0 -> impossible
1 -> o
n -> m >>= \c -> if c == '?' then show n else pure c
_ -> impossible
where
impossible = error "This is impossible based on pacman manpage"
|