From 8f9c5f1ecec8ee13bb0e803a1f26140bb8d8357e Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Thu, 29 May 2014 02:16:07 -0400 Subject: A simple CatInt monitor --- readme.md | 10 ++++++++++ src/Plugins/Monitors.hs | 4 ++++ src/Plugins/Monitors/CatInt.hs | 25 +++++++++++++++++++++++++ xmobar.cabal | 2 +- 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/Plugins/Monitors/CatInt.hs diff --git a/readme.md b/readme.md index ac3f4c5..ca3a15f 100644 --- a/readme.md +++ b/readme.md @@ -1100,6 +1100,16 @@ more than one battery. Run Locks +### `CatInt n fn` + +- Reads and displays an integer from the file whose path is `fn` + (especially useful with files in `/sys`). +- Aliases as `catn` (e.g. `Cat 0` as `cat0`, etc.) so you can + have several. +- Example: + + Run CatInt 0 "/sys/devices/platform/thinkpad_hwmon/fan1_input" [] 50 + ## Executing External Commands In order to execute an external command you can either write the diff --git a/src/Plugins/Monitors.hs b/src/Plugins/Monitors.hs index 27db417..860da71 100644 --- a/src/Plugins/Monitors.hs +++ b/src/Plugins/Monitors.hs @@ -35,6 +35,7 @@ import Plugins.Monitors.CoreTemp import Plugins.Monitors.Disk import Plugins.Monitors.Top import Plugins.Monitors.Uptime +import Plugins.Monitors.CatInt #ifdef IWLIB import Plugins.Monitors.Wireless #endif @@ -69,6 +70,7 @@ data Monitors = Weather Station Args Rate | TopProc Args Rate | TopMem Args Rate | Uptime Args Rate + | CatInt Int FilePath Args Rate #ifdef IWLIB | Wireless Interface Args Rate #endif @@ -116,6 +118,7 @@ instance Exec Monitors where alias (DiskU _ _ _) = "disku" alias (DiskIO _ _ _) = "diskio" alias (Uptime _ _) = "uptime" + alias (CatInt n _ _ _) = "cat" ++ (show n) #ifdef IWLIB alias (Wireless i _ _) = i ++ "wi" #endif @@ -151,6 +154,7 @@ instance Exec Monitors where start (DiskU s a r) = runM a diskUConfig (runDiskU s) r start (DiskIO s a r) = startDiskIO s a r start (Uptime a r) = runM a uptimeConfig runUptime r + start (CatInt _ s a r) = runM a catIntConfig (runCatInt s) r #ifdef IWLIB start (Wireless i a r) = runM (a ++ [i]) wirelessConfig runWireless r #endif diff --git a/src/Plugins/Monitors/CatInt.hs b/src/Plugins/Monitors/CatInt.hs new file mode 100644 index 0000000..3d19270 --- /dev/null +++ b/src/Plugins/Monitors/CatInt.hs @@ -0,0 +1,25 @@ +----------------------------------------------------------------------------- +-- | +-- Module : Plugins.Monitors.CatInt +-- Copyright : (c) Nathaniel Wesley Filardo +-- License : BSD-style (see LICENSE) +-- +-- Maintainer : Nathaniel Wesley Filardo +-- Stability : unstable +-- Portability : unportable +-- +----------------------------------------------------------------------------- + +module Plugins.Monitors.CatInt where + +import Plugins.Monitors.Common +import Plugins.Monitors.CoreCommon + +catIntConfig :: IO MConfig +catIntConfig = mkMConfig "" ["v"] + +runCatInt :: FilePath -> [String] -> Monitor String +runCatInt p _ = + let failureMessage = "Cannot read: " ++ (show p) + fmt x = show (truncate x :: Int) + in checkedDataRetrieval failureMessage [[p]] Nothing id fmt diff --git a/xmobar.cabal b/xmobar.cabal index 54acaa3..584b833 100644 --- a/xmobar.cabal +++ b/xmobar.cabal @@ -88,7 +88,7 @@ executable xmobar Plugins.Monitors.Swap, Plugins.Monitors.Thermal, Plugins.Monitors.ThermalZone, Plugins.Monitors.Top, Plugins.Monitors.Uptime, Plugins.Monitors.Weather, - Plugins.Monitors.Bright + Plugins.Monitors.Bright, Plugins.Monitors.CatInt ghc-prof-options: -prof -auto-all ghc-options: -funbox-strict-fields -Wall -fno-warn-unused-do-bind -- cgit v1.2.3