From 80be37611711871c6971588873687755103097c0 Mon Sep 17 00:00:00 2001 From: Enrico Maria De Angelis Date: Wed, 17 Apr 2024 18:25:45 +0100 Subject: ArchUpdates --- src/Xmobar/Plugins/ArchUpdates.hs | 47 +++++++++++++++++++++++++++++++++++++++ src/Xmobar/Run/Types.hs | 2 ++ 2 files changed, 49 insertions(+) create mode 100644 src/Xmobar/Plugins/ArchUpdates.hs (limited to 'src/Xmobar') 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 +-- 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 -- cgit v1.2.3