From a846f50b42d883242252dd2225839cfcc3842a57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Eug=C3=AAnio?= Date: Wed, 8 Feb 2023 12:41:46 -0300 Subject: [PATCH] waybar: only show playerctl status when playing --- user/waybar.nix | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/user/waybar.nix b/user/waybar.nix index 5611364..862247c 100644 --- a/user/waybar.nix +++ b/user/waybar.nix @@ -94,13 +94,22 @@ in on-scroll-up = "${mpc} vol +10"; on-scroll-down = "${mpc} vol -10"; }; - "custom/playerctl" = { - format = "{}"; - exec = "${pkgs.playerctl}/bin/playerctl --ignore-player=mpd metadata title"; - on-click = "${pkgs.playerctl}/bin/playerctl --ignore-player=mpd play-pause"; - interval = 1; - tooltip = false; - }; + "custom/playerctl" = + let + playerctl = "${pkgs.playerctl}/bin/playerctl --ignore-player=mpd"; + statusScript = pkgs.writeShellScript "waybar-playerctl-status" '' + test "$(env LC_ALL=C ${playerctl} status title)" = "Playing" \ + && ${playerctl} metadata title \ + || echo "" + ''; + in + { + format = "{}"; + exec = "${statusScript}"; + on-click = "${playerctl} play-pause"; + interval = 1; + tooltip = false; + }; "sway/language" = { format = "{short} {variant}"; }; "custom/caffeine" = { format = "{}";