From bfa8d772d0e8d95e4a62b724d8e8921213a33bca Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Thu, 29 Aug 2024 20:16:13 -0400 Subject: [PATCH] waybar: setup binPath --- .../services/randomWallpaper/script.rb | 0 .../services/waybar/default.nix | 91 +++++++++---------- .../services/waybar/scripts/check-battery.sh | 18 ++++ .../services/waybar/scripts/mako-dnd.sh | 17 ++++ 4 files changed, 78 insertions(+), 48 deletions(-) mode change 100644 => 100755 homeManagerModules/services/randomWallpaper/script.rb create mode 100755 homeManagerModules/services/waybar/scripts/check-battery.sh create mode 100755 homeManagerModules/services/waybar/scripts/mako-dnd.sh diff --git a/homeManagerModules/services/randomWallpaper/script.rb b/homeManagerModules/services/randomWallpaper/script.rb old mode 100644 new mode 100755 diff --git a/homeManagerModules/services/waybar/default.nix b/homeManagerModules/services/waybar/default.nix index 7acaa185..6a421e5d 100644 --- a/homeManagerModules/services/waybar/default.nix +++ b/homeManagerModules/services/waybar/default.nix @@ -50,8 +50,7 @@ in { }; "hyprland/submap" = { - on-click = ''${lib.getExe' - config.wayland.windowManager.hyprland.package "hyprctl"} dispatch submap reset''; + on-click = ''hyprctl dispatch submap reset''; }; "sway/workspaces" = { @@ -68,21 +67,20 @@ in { }; "sway/mode" = { - on-click = ''${lib.getExe' config.wayland.windowManager.sway.package "swaymsg"} mode default''; + on-click = ''swaymsg mode default''; }; "sway/scratchpad" = { format = "{icon} {count}"; format-icons = ["" ""]; - on-click = "${lib.getExe' config.wayland.windowManager.sway.package "swaymsg"} scratchpad show"; + on-click = "swaymsg scratchpad show"; show-empty = false; tooltip = true; tooltip-format = "{app}: {title}"; }; "custom/app-close" = { - on-click = ''${lib.getExe' - config.wayland.windowManager.hyprland.package "hyprctl"} dispatch killactive || ${lib.getExe' config.wayland.windowManager.sway.package "swaymsg"} kill''; + on-click = ''hyprctl dispatch killactive || swaymsg kill''; format = "󰅗"; tooltip-format = "Close the focused window."; }; @@ -94,25 +92,7 @@ in { }; battery = let - checkBattery = pkgs.writeShellScript "check-battery" '' - if [ -d /sys/class/power_supply/BAT0 ]; then - BAT=/sys/class/power_supply/BAT0 - elif [ -d /sys/class/power_supply/BAT1 ]; then - BAT=/sys/class/power_supply/BAT1 - else - echo "No battery found." - exit 1 - fi - CRIT=''${1:-10} - NOTIFY=${lib.getExe' pkgs.libnotify "notify-send"} - - stat=$(${lib.getExe' pkgs.coreutils "cat"} $BAT/status) - perc=$(${lib.getExe' pkgs.coreutils "cat"} $BAT/capacity) - - if [[ $perc -le $CRIT ]] && [[ $stat == "Discharging" ]]; then - $NOTIFY --urgency=critical --icon=dialog-error "Battery Critical" "Current charge: $perc%". - fi - ''; + checkBattery = pkgs.writeShellScript "check-battery" (builtins.readFile ./scripts/check-battery.sh); in { format = "{icon}"; format-icons = ["󰁺" "󰁻" "󰁼" "󰁽" "󰁾" "󰁿" "󰂀" "󰂁" "󰂂" "󰁹"]; @@ -148,7 +128,7 @@ in { format = ""; format-connected = " {num_connections}"; format-disabled = ""; # an empty format will hide the module - on-clic = lib.getExe' pkgs.blueberry "blueberry"; + on-click = "blueberry"; tooltip-format = "{controller_alias} {controller_address}"; tooltip-format-connected = '' @@ -172,7 +152,7 @@ in { }; ignored-sinks = ["Easy Effects Sink"]; - on-click = "${lib.getExe pkgs.pavucontrol} -t 3"; + on-click = "pavucontrol -t 3"; scroll-step = 5; }; @@ -182,7 +162,7 @@ in { format-ethernet = "󰈀"; format-icons = ["󰤟" "󰤢" "󰤥" "󰤨"]; format-wifi = "{icon}"; - on-click = "${lib.getExe pkgs.networkmanager_dmenu} -i"; + on-click = "networkmanager_dmenu -i"; tooltip-format = "{ifname} via {gwaddr} 󰊗"; tooltip-format-disconnected = "Disconnected"; tooltip-format-ethernet = "{ifname} "; @@ -192,23 +172,8 @@ in { tray = {spacing = 15;}; "custom/dnd" = let - mako-dnd = pkgs.writeShellScript "mako-dnd" '' - show() { - MAKO_MODE=$(${lib.getExe' pkgs.mako "makoctl"} mode) - if ${lib.getExe' pkgs.coreutils "echo"} "$MAKO_MODE" | ${lib.getExe' pkgs.gnugrep "grep"} -q "do-not-disturb"; then - ${lib.getExe' pkgs.coreutils "printf"} '{"text": "󰂛", "class": "on", "tooltip": "Notifications snoozed."}\n' - else - ${lib.getExe' pkgs.coreutils "printf"} '{"text": "󰂚", "class": "off","tooltip": "Notifications enabled."}\n' - fi - } - - toggle() { - ${lib.getExe' pkgs.mako "makoctl"} mode -t do-not-disturb - ${lib.getExe' pkgs.procps "pkill"} -SIGRTMIN+2 .waybar-wrapped - } - - [ $# -gt 0 ] && toggle || show - ''; + mako-dnd = + pkgs.writeShellScript "mako-dnd" (builtins.readFile ./scripts/mako-dnd.sh); in { exec = "${mako-dnd}"; interval = "once"; @@ -219,13 +184,13 @@ in { "custom/logout" = { format = "󰤆"; - on-click = ''${lib.getExe config.programs.rofi.package} -i -show power-menu -modi "power-menu:${lib.getExe pkgs.rofi-power-menu} --choices=logout/lockscreen/suspend/shutdown/reboot"''; + on-click = ''rofi -i -show power-menu -modi "power-menu:rofi-power-menu --choices=logout/lockscreen/suspend/shutdown/reboot"''; tooltip-format = "Manage your session."; }; "custom/menu" = { format = "󰀻"; - on-click = "${lib.getExe pkgs.nwg-drawer}"; + on-click = "nwg-drawer"; tooltip-format = "Touch-friendly application menu."; }; @@ -354,7 +319,37 @@ in { systemd.user.services.waybar = { Install.WantedBy = lib.mkForce (lib.optional (cfg.desktop.hyprland.enable) "hyprland-session.target" ++ lib.optional (cfg.desktop.sway.enable) "sway-session.target"); - Service.Restart = lib.mkForce "no"; + + Service = { + Environment = lib.mkForce [ + "PATH=${ + lib.makeBinPath ([ + config.programs.rofi.package + config.wayland.windowManager.hyprland.package + config.wayland.windowManager.sway.package + ] + ++ (with pkgs; [ + blueberry + bluez + coreutils + getopt + gnugrep + libnotify + mako + networkmanager + networkmanager_dmenu + nwg-drawer + pavucontrol + procps + rofi-power-menu + systemd + ])) + }" + ]; + + Restart = lib.mkForce "no"; + }; + Unit.BindsTo = lib.optional (cfg.desktop.hyprland.enable) "hyprland-session.target" ++ lib.optional (cfg.desktop.sway.enable) "sway-session.target"; }; diff --git a/homeManagerModules/services/waybar/scripts/check-battery.sh b/homeManagerModules/services/waybar/scripts/check-battery.sh new file mode 100755 index 00000000..96d5ae49 --- /dev/null +++ b/homeManagerModules/services/waybar/scripts/check-battery.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +if [ -d /sys/class/power_supply/BAT0 ]; then + BAT=/sys/class/power_supply/BAT0 +elif [ -d /sys/class/power_supply/BAT1 ]; then + BAT=/sys/class/power_supply/BAT1 +else + echo "No battery found." + exit 1 +fi + +CRIT=''${1:-10} +STAT=$(cat $BAT/status) +PERC=$(cat $BAT/capacity) + +if [[ $PERC -le $CRIT ]] && [[ $STAT == "Discharging" ]]; then + notify-send --urgency=critical --icon=dialog-error "Battery Critical" "Current charge: $PERC%". +fi diff --git a/homeManagerModules/services/waybar/scripts/mako-dnd.sh b/homeManagerModules/services/waybar/scripts/mako-dnd.sh new file mode 100755 index 00000000..ed4ff233 --- /dev/null +++ b/homeManagerModules/services/waybar/scripts/mako-dnd.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +show() { + MAKO_MODE=$(makoctl mode) + if echo "$MAKO_MODE" | grep -q "do-not-disturb"; then + printf '{"text": "󰂛", "class": "on", "tooltip": "Notifications snoozed."}\n' + else + printf '{"text": "󰂚", "class": "off","tooltip": "Notifications enabled."}\n' + fi +} + +toggle() { + makoctl mode -t do-not-disturb + pkill -SIGRTMIN+2 .waybar-wrapped +} + +[ $# -gt 0 ] && toggle || show