diff options
-rw-r--r-- | doc/plugins.org | 28 | ||||
-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 | ||||
-rw-r--r-- | xmobar.cabal | 1 |
5 files changed, 80 insertions, 0 deletions
diff --git a/doc/plugins.org b/doc/plugins.org index f27d7ff..bb33466 100644 --- a/doc/plugins.org +++ b/doc/plugins.org @@ -1575,6 +1575,34 @@ xmonad configuration (=xmonad.hs=), e.g. by using a custom =~/.xmonad/build= script. +* Other plugins + + =ArchUpdates Rate= + + Same as + + #+begin_src haskell + ArchUpdates' ("up to date", + "1 update available", + "? updates available") Rate + #+end_src + + =ArchUpdates' (Zero, One, Many) Rate= + - Aliases to =arch= + + - =Zero=: a =String= for when the system is up to date. + - =One=: a =String= for when only one update is available. + - =Many=: a =String= for when several updates are available; it must contain a =?= character as a placeholder for the number of updates. + - Example: + + #+begin_src haskell + ArchUpdates' (green "up to date", + yellow "1 update", + yellow "? updates") 600 + where + yellow = wrap "<fc=yellow>" "</fc>" + green = wrap "<fc=green>" "</fc>" + #+end_src * Executing external commands 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 diff --git a/xmobar.cabal b/xmobar.cabal index 559131c..e00044a 100644 --- a/xmobar.cabal +++ b/xmobar.cabal @@ -149,6 +149,7 @@ library Xmobar.X11.Text, Xmobar.X11.Types, Xmobar.X11.Window, + Xmobar.Plugins.ArchUpdates, Xmobar.Plugins.Command, Xmobar.Plugins.BufferedPipeReader, Xmobar.Plugins.CommandReader, |