summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/Plugins/PacmanUpdates.hs
diff options
context:
space:
mode:
authorAlexander 'ccntrq' Pankoff <ccntrq@screenri.de>2025-04-10 08:20:15 +0200
committerAlexander 'ccntrq' Pankoff <ccntrq@screenri.de>2025-04-14 16:21:30 +0200
commit82398b1603d139898be70af97ef9d59ba441bae0 (patch)
tree67e49854466cf540d54168f554bcc5c5c01c4cf2 /src/Xmobar/Plugins/PacmanUpdates.hs
parent3ac316ab1b468b97ef3230bd334a8b9b15fb80e1 (diff)
downloadxmobar-82398b1603d139898be70af97ef9d59ba441bae0.tar.gz
xmobar-82398b1603d139898be70af97ef9d59ba441bae0.tar.bz2
feat: add new PacmanUpdates plugin
the new PacmanUpdates plugin behaves similar to the ArchUpdates plugin while additionally allowing to pass in a custom error message for unknown pacman failures. The default error message of `pacman: Unknown cause of failure.` of the ArchUpdates plugin is too long for my taste. The ArchUpdates plugin was modified to delegate to the new PacmanUpdates plugin while providing the default error message and to show a deprecation notice in the zero updates case. The new name better represents the Plugin's compatibility with all pacman-based distributions, not just Arch. The docs have been updated to reflect the existence of the new plugin and to highlight the similarities between the ArchUpdates and PacmanUpdates plugins. The ArchUpdates plugin has been marked has deprecated there to.
Diffstat (limited to 'src/Xmobar/Plugins/PacmanUpdates.hs')
-rw-r--r--src/Xmobar/Plugins/PacmanUpdates.hs43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/Xmobar/Plugins/PacmanUpdates.hs b/src/Xmobar/Plugins/PacmanUpdates.hs
new file mode 100644
index 0000000..1e8a8fc
--- /dev/null
+++ b/src/Xmobar/Plugins/PacmanUpdates.hs
@@ -0,0 +1,43 @@
+{-# LANGUAGE CPP #-}
+
+-----------------------------------------------------------------------------
+
+-----------------------------------------------------------------------------
+
+{- |
+Module : Plugins.Monitors.PacmanUpdates
+Copyright : (c) 2024 Enrico Maria De Angelis
+ , (c) 2025 Alexander Pankoff
+License : BSD-style (see LICENSE)
+
+Maintainer : Enrico Maria De Angelis <enricomaria.dean6elis@gmail.com>
+Stability : unstable
+Portability : unportable
+
+A Pacman updates availablility plugin for Xmobar
+-}
+module Xmobar.Plugins.PacmanUpdates (PacmanUpdates (..)) where
+
+import System.Exit (ExitCode (..))
+import System.Process (readProcessWithExitCode)
+import Xmobar.Plugins.Command (Rate)
+import Xmobar.Run.Exec
+
+data PacmanUpdates = PacmanUpdates (String, String, String, String) Rate
+ deriving (Read, Show)
+
+instance Exec PacmanUpdates where
+ alias = const "pacman"
+ rate (PacmanUpdates _ r) = r
+ run (PacmanUpdates (z, o, m, e) _) = do
+ (exit, stdout, _) <- readProcessWithExitCode "checkupdates" [] ""
+ return $ case exit of
+ ExitFailure 2 -> z -- ero updates
+ ExitFailure 1 -> e
+ 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"