Improve status-script
This commit is contained in:
parent
4f97f3ee98
commit
47d3d96d67
|
@ -42,6 +42,7 @@ data Var a = MkVar
|
||||||
{ value :: TVar a
|
{ value :: TVar a
|
||||||
, update :: TMVar ()
|
, update :: TMVar ()
|
||||||
}
|
}
|
||||||
|
|
||||||
newVar :: a -> IO (Var a)
|
newVar :: a -> IO (Var a)
|
||||||
newVar initial_value = atomically $ MkVar <$> newTVar initial_value <*> newEmptyTMVar
|
newVar initial_value = atomically $ MkVar <$> newTVar initial_value <*> newEmptyTMVar
|
||||||
|
|
||||||
|
@ -92,6 +93,12 @@ simpleModule delay action var = repeatM do
|
||||||
atomically . updateVarIfChanged var =<< action
|
atomically . updateVarIfChanged var =<< action
|
||||||
Concurrent.threadDelay delay
|
Concurrent.threadDelay delay
|
||||||
|
|
||||||
|
withColor :: Monad m => Text -> Text -> m (Maybe Text)
|
||||||
|
withColor color content = pure $ Just [i|<span foreground='\##{color}'>#{content}</span>|]
|
||||||
|
|
||||||
|
when' :: Monad m => Bool -> m (Maybe a) -> m (Maybe a)
|
||||||
|
when' cond result = if cond then result else pure Nothing
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
mode_var <- newVar Unrestricted
|
mode_var <- newVar Unrestricted
|
||||||
|
@ -99,52 +106,63 @@ main = do
|
||||||
modules =
|
modules =
|
||||||
[ simpleModule (5 * oneSecond) $ do
|
[ simpleModule (5 * oneSecond) $ do
|
||||||
appointments <- lines . decodeUtf8 <$> tryCmd (khal ["list", "-a", "Standard", "-a", "Planung", "-a", "Uni", "-a", "Maltaire", "now", "2h", "-df", ""])
|
appointments <- lines . decodeUtf8 <$> tryCmd (khal ["list", "-a", "Standard", "-a", "Planung", "-a", "Uni", "-a", "Maltaire", "now", "2h", "-df", ""])
|
||||||
pure $
|
when' (not $ null appointments) $
|
||||||
if null appointments
|
withColor "8839ef" (Text.intercalate "; " appointments)
|
||||||
then Nothing
|
|
||||||
else Just [i|<span foreground='\#8839ef'>#{Text.intercalate "; " appointments}</span>|]
|
|
||||||
, simpleModule oneSecond $
|
, simpleModule oneSecond $
|
||||||
Just . Text.replace "Stopped -" "⏹" . Text.replace "Playing -" "▶" . Text.replace "Paused -" "⏸" . Text.intercalate " - " . fmap decodeUtf8 . filter (/= "") <$> mapM tryCmd [playerctl "status", playerctl "metadata" "title", playerctl "metadata" "album", playerctl "metadata" "artist"]
|
Just
|
||||||
|
. Text.replace "Stopped -" "⏹"
|
||||||
|
. Text.replace "Playing -" "▶"
|
||||||
|
. Text.replace "Paused -" "⏸"
|
||||||
|
. Text.intercalate " - "
|
||||||
|
. fmap decodeUtf8
|
||||||
|
. filter (/= "")
|
||||||
|
<$> mapM
|
||||||
|
tryCmd
|
||||||
|
[ playerctl "status"
|
||||||
|
, playerctl "metadata" "title"
|
||||||
|
, playerctl "metadata" "album"
|
||||||
|
, playerctl "metadata" "artist"
|
||||||
|
]
|
||||||
, simpleModule oneSecond $ do
|
, simpleModule oneSecond $ do
|
||||||
mode <- read_mode
|
mode <- read_mode
|
||||||
unread <-
|
unread <-
|
||||||
if mode >= Orga
|
if mode >= Orga
|
||||||
then notmuch "count" "folder:hera/Inbox" "tag:unread" |> captureTrim
|
then notmuch "count" "folder:hera/Inbox" "tag:unread" |> captureTrim
|
||||||
else pure "0"
|
else pure "0"
|
||||||
pure $ memptyIfFalse (unread /= "0") (Just [i|<span foreground='\#d20f39'>Unread: #{unread}</span>|])
|
when' (unread /= "0") $ withColor "d20f39" [i|Unread: #{unread}|]
|
||||||
, simpleModule oneSecond $ do
|
, simpleModule oneSecond $ do
|
||||||
mode <- read_mode
|
mode <- read_mode
|
||||||
inbox <-
|
inbox <-
|
||||||
if mode == Leisure
|
if mode == Leisure
|
||||||
then notmuch "count" "folder:hera/Inbox" |> captureTrim
|
then notmuch "count" "folder:hera/Inbox" |> captureTrim
|
||||||
else pure "0"
|
else pure "0"
|
||||||
pure $ memptyIfFalse (inbox /= "0") (Just [i|<span foreground='\#e53443'>Inbox: #{inbox}</span>|])
|
when' (inbox /= "0") $ withColor "e53443" [i|Inbox: #{inbox}|]
|
||||||
, simpleModule oneSecond $ do
|
, simpleModule oneSecond $ do
|
||||||
mode <- read_mode
|
mode <- read_mode
|
||||||
codeMails <-
|
codeMails <-
|
||||||
if mode == Code
|
if mode == Code
|
||||||
then notmuch "count" "folder:hera/Code" |> captureTrim
|
then notmuch "count" "folder:hera/Code" |> captureTrim
|
||||||
else pure "0"
|
else pure "0"
|
||||||
pure $ memptyIfFalse (codeMails /= "0") (Just [i|<span foreground='\#8839ef'>Code Mails: #{codeMails}</span>|])
|
when' (codeMails /= "0") $ withColor "8839ef" [i|Code Mails: #{codeMails}|]
|
||||||
, simpleModule (5 * oneSecond) $ do
|
, simpleModule (5 * oneSecond) $ do
|
||||||
mode <- read_mode
|
mode <- read_mode
|
||||||
codeUpdates <-
|
codeUpdates <-
|
||||||
if mode == Code
|
if mode == Code
|
||||||
then fromMaybe 0 . readMaybe . toString . Text.replace " unread articles" "" . decodeUtf8 <$> tryCmd (exe "software-updates" "-x" "print-unread")
|
then fromMaybe 0 . readMaybe . toString . Text.replace " unread articles" "" . decodeUtf8 <$> tryCmd (exe "software-updates" "-x" "print-unread")
|
||||||
else pure 0
|
else pure 0
|
||||||
pure $ memptyIfFalse (codeUpdates /= 0) (Just [i|<span foreground='\#179299'>Code Updates: #{codeUpdates}</span>|])
|
when' (codeUpdates /= 0) $ withColor "179299" [i|Code Updates: #{codeUpdates}|]
|
||||||
, simpleModule (5 * oneSecond) $ do
|
, simpleModule (5 * oneSecond) $ do
|
||||||
dirs <- listDirectory "/home/maralorn/git"
|
dirs <- listDirectory "/home/maralorn/git"
|
||||||
dirty <- fmap toText <$> filterM (isDirty . ("/home/maralorn/git/" <>)) dirs
|
dirty <- fmap toText <$> filterM (isDirty . ("/home/maralorn/git/" <>)) dirs
|
||||||
pure $ memptyIfFalse (not (null dirty)) (Just [i|<span foreground='\#e64443'>Dirty: #{Text.intercalate " " dirty}</span>|])
|
when' (not $ null dirty) $ withColor "e64443" [i|Dirty: #{Text.intercalate " " dirty}|]
|
||||||
, simpleModule (5 * oneSecond) $ do
|
, simpleModule (5 * oneSecond) $ do
|
||||||
dirs <- listDirectory "/home/maralorn/git"
|
dirs <- listDirectory "/home/maralorn/git"
|
||||||
unpushed <- fmap toText <$> filterM (isUnpushed . ("/home/maralorn/git/" <>)) dirs
|
unpushed <- fmap toText <$> filterM (isUnpushed . ("/home/maralorn/git/" <>)) dirs
|
||||||
pure $ memptyIfFalse (not (null unpushed)) (Just [i|<span foreground='\#fe640b'>Unpushed: #{Text.intercalate " " unpushed}</span>|])
|
when' (not $ null unpushed) $ withColor "fe640b" [i|Unpushed: #{Text.intercalate " " unpushed}|]
|
||||||
, simpleModule 1 $ do
|
, simpleModule 1 $ do
|
||||||
atomically $ takeTMVar (update mode_var)
|
atomically $ takeTMVar (update mode_var)
|
||||||
mode <- read_mode
|
mode <- read_mode
|
||||||
pure $ Just [i|<span foreground='\#7287fd'>#{show mode}</span>|]
|
withColor "7287fd" (show mode)
|
||||||
]
|
]
|
||||||
foldConcurrently_
|
foldConcurrently_
|
||||||
[ void $ simpleModule oneSecond getMode mode_var
|
[ void $ simpleModule oneSecond getMode mode_var
|
||||||
|
|
Loading…
Reference in a new issue