Make status script resilient and add playerctl
This commit is contained in:
parent
fabc119955
commit
e0e0a52c84
1 changed files with 9 additions and 4 deletions
|
@ -4,7 +4,7 @@ let
|
||||||
statusScript = pkgs.writeHaskellScript
|
statusScript = pkgs.writeHaskellScript
|
||||||
{
|
{
|
||||||
name = "status-script";
|
name = "status-script";
|
||||||
bins = [ pkgs.notmuch pkgs.coreutils pkgs.git ];
|
bins = [ pkgs.notmuch pkgs.coreutils pkgs.git pkgs.playerctl ];
|
||||||
imports = [
|
imports = [
|
||||||
"Control.Exception"
|
"Control.Exception"
|
||||||
"System.Directory"
|
"System.Directory"
|
||||||
|
@ -18,11 +18,16 @@ let
|
||||||
|
|
||||||
isDirty gitDir = ((/= "") <$> (git "-C" gitDir "status" "--porcelain" |> captureTrim)) `catch` (\(_ :: SomeException) -> pure True)
|
isDirty gitDir = ((/= "") <$> (git "-C" gitDir "status" "--porcelain" |> captureTrim)) `catch` (\(_ :: SomeException) -> pure True)
|
||||||
isUnpushed gitDir = do
|
isUnpushed gitDir = do
|
||||||
gitHead <- ignoreFailure (git "-C" gitDir "rev-parse" "HEAD" |> captureTrim)
|
gitHead <- tryCmd (git "-C" gitDir "rev-parse" "HEAD")
|
||||||
origin <- ignoreFailure (git "-C" gitDir "rev-parse" "origin/HEAD" |> captureTrim)
|
origin <- tryCmd (git "-C" gitDir "rev-parse" "origin/HEAD")
|
||||||
|
say [i|#{gitDir :: FilePath}|]
|
||||||
|
say [i|head: #{gitHead}, origin: #{origin}|]
|
||||||
pure (gitHead /= origin)
|
pure (gitHead /= origin)
|
||||||
|
|
||||||
|
tryCmd x = ignoreFailure x |> captureTrim
|
||||||
|
|
||||||
main = do
|
main = do
|
||||||
|
playing <- Text.intercalate " " . fmap decodeUtf8 . filter (/= "") <$> mapM tryCmd [playerctl "status", playerctl "metadata" "title", playerctl "metadata" "artist"]
|
||||||
mode <- getMode
|
mode <- getMode
|
||||||
unread <- notmuch "count" "folder:hera/Inbox" "tag:unread" |> captureTrim
|
unread <- notmuch "count" "folder:hera/Inbox" "tag:unread" |> captureTrim
|
||||||
inbox <- notmuch "count" "folder:hera/Inbox" |> captureTrim
|
inbox <- notmuch "count" "folder:hera/Inbox" |> captureTrim
|
||||||
|
@ -30,7 +35,7 @@ let
|
||||||
dirty <- fmap toText <$> filterM (isDirty . ("/home/maralorn/git/"<>)) dirs
|
dirty <- fmap toText <$> filterM (isDirty . ("/home/maralorn/git/"<>)) dirs
|
||||||
unpushed <- fmap toText <$> filterM (isUnpushed . ("/home/maralorn/git/"<>)) dirs
|
unpushed <- fmap toText <$> filterM (isUnpushed . ("/home/maralorn/git/"<>)) dirs
|
||||||
say . Text.intercalate " " $
|
say . Text.intercalate " " $
|
||||||
[show mode] ++
|
[playing, show mode] ++
|
||||||
memptyIfFalse ((unread /= "0") && mode >= Orga) (one [i|Unread: #{unread}|]) ++
|
memptyIfFalse ((unread /= "0") && mode >= Orga) (one [i|Unread: #{unread}|]) ++
|
||||||
memptyIfFalse ((inbox /= "0") && mode >= Leisure) (one [i|Inbox: #{inbox}|]) ++
|
memptyIfFalse ((inbox /= "0") && mode >= Leisure) (one [i|Inbox: #{inbox}|]) ++
|
||||||
memptyIfFalse (length unpushed /= 0) (one [i|Unpushed: #{Text.intercalate " " unpushed}|]) ++
|
memptyIfFalse (length unpushed /= 0) (one [i|Unpushed: #{Text.intercalate " " unpushed}|]) ++
|
||||||
|
|
Loading…
Reference in a new issue