diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Xmobar.hs | 2 | ||||
-rw-r--r-- | src/Xmobar/Plugins/ArchUpdates.hs | 47 | ||||
-rw-r--r-- | src/Xmobar/Run/Types.hs | 2 |
3 files changed, 51 insertions, 0 deletions
diff --git a/src/Xmobar.hs b/src/Xmobar.hs index ced40a5..374825b 100644 --- a/src/Xmobar.hs +++ b/src/Xmobar.hs @@ -26,6 +26,7 @@ module Xmobar (xmobar , SignalType (..) , module Xmobar.Config.Types , module Xmobar.Config.Parse + , module Xmobar.Plugins.ArchUpdates , module Xmobar.Plugins.BufferedPipeReader , module Xmobar.Plugins.CommandReader , module Xmobar.Plugins.Date @@ -53,6 +54,7 @@ import Xmobar.Run.Runnable import Xmobar.Run.Exec import Xmobar.Config.Types import Xmobar.Config.Parse +import Xmobar.Plugins.ArchUpdates import Xmobar.Plugins.Command import Xmobar.Plugins.BufferedPipeReader import Xmobar.Plugins.CommandReader diff --git a/src/Xmobar/Plugins/ArchUpdates.hs b/src/Xmobar/Plugins/ArchUpdates.hs new file mode 100644 index 0000000..a8cf3a9 --- /dev/null +++ b/src/Xmobar/Plugins/ArchUpdates.hs @@ -0,0 +1,47 @@ +{-# 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 Rate + | ArchUpdates' (String, String, String) Rate + deriving (Read, Show) + +instance Exec ArchUpdates where + alias (ArchUpdates _) = "arch" + alias (ArchUpdates' _ _) = "arch" + rate (ArchUpdates r) = r + rate (ArchUpdates' _ r) = r + run (ArchUpdates r) = run (ArchUpdates' ("up to date", + "1 update available", + "? updates available") 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" diff --git a/src/Xmobar/Run/Types.hs b/src/Xmobar/Run/Types.hs index 69406bb..bb573c8 100644 --- a/src/Xmobar/Run/Types.hs +++ b/src/Xmobar/Run/Types.hs @@ -19,6 +19,7 @@ module Xmobar.Run.Types(runnableTypes) where import {-# SOURCE #-} Xmobar.Run.Runnable() +import Xmobar.Plugins.ArchUpdates import Xmobar.Plugins.Command import Xmobar.Plugins.Monitors import Xmobar.Plugins.Date @@ -59,6 +60,7 @@ infixr :*: runnableTypes :: Command :*: Monitors :*: Date :*: PipeReader :*: BufferedPipeReader :*: CommandReader :*: StdinReader :*: XMonadLog :*: EWMH :*: Kbd :*: Locks :*: NotmuchMail :*: + ArchUpdates :*: #ifdef INOTIFY Mail :*: MBox :*: #endif |