add script to change power profile

This commit is contained in:
Adithya 2023-03-16 23:36:17 +05:30
parent 2d84bd3201
commit 27a77c6ddd
No known key found for this signature in database
GPG key ID: 0C7F35F4F821290F
3 changed files with 120 additions and 62 deletions

View file

@ -1,7 +1,9 @@
{ pkgs, ... }:
{ osConfig, pkgs, ... }:
{
xdg.configFile."scripts/power_menu.sh" = {
xdg.configFile = {
"scripts/power_menu.sh" = {
executable = true;
text = ''
#!/bin/sh
@ -33,10 +35,10 @@
chpower "$(printf "%b" "$OPTIONS" | sort | ${pkgs.rofi-wayland}/bin/rofi -dmenu -p "Power Menu")"
'';
executable = true;
};
xdg.configFile."scripts/volume_up.sh" = {
"scripts/volume_up.sh" = {
executable = true;
text = ''
#!/bin/sh
@ -45,10 +47,10 @@
${pkgs.wireplumber}/bin/wpctl set-mute @DEFAULT_AUDIO_SINK@ 0
[ $(${pkgs.wireplumber}/bin/wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk -F': ' '{print $2}' | sed 's/\.//') -lt 100 ] && ${pkgs.wireplumber}/bin/wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+
'';
executable = true;
};
xdg.configFile."scripts/tmux_sessions.sh" = {
"scripts/tmux_sessions.sh" = {
executable = true;
text = ''
#!/bin/sh
@ -62,6 +64,51 @@
${pkgs.kitty}/bin/kitty ${pkgs.tmux}/bin/tmux -u attach-session -dEt "$SESSION"
;;
esac'';
};
"scripts/power_profile.sh" =
let
sudo = "/run/wrappers/bin/sudo";
cpupower = "${osConfig.boot.kernelPackages.cpupower}/bin/cpupower";
powerprofilesctl = "${pkgs.power-profiles-daemon}/bin/powerprofilesctl";
in {
executable = true;
text = ''
#!/bin/sh
set -eu
POWER_PROFILE_FILE="$HOME/.cache/power_profile"
POWER_PROFILE="powersave"
if [ -f "$POWER_PROFILE_FILE" ]; then
POWER_PROFILE="$(<$POWER_PROFILE_FILE)"
fi
case "$1" in
"toggle")
if [ "$POWER_PROFILE" == "powersave" ]; then
${sudo} ${cpupower} frequency-set --governor performance > /dev/null
${powerprofilesctl} set performance
POWER_PROFILE="performance"
elif [ "$POWER_PROFILE" == "performance" ]; then
${sudo} ${cpupower} frequency-set --governor powersave > /dev/null
${powerprofilesctl} set power-saver
POWER_PROFILE="powersave"
fi
echo $POWER_PROFILE > $POWER_PROFILE_FILE
;;
"icon")
if [ "$POWER_PROFILE" == "powersave" ]; then
echo "󰌪"
elif [ "$POWER_PROFILE" == "performance" ]; then
echo "󰓅"
fi
;;
*)
;;
esac
'';
};
};
}

View file

@ -1,4 +1,4 @@
{ pkgs, ... }:
{ config, pkgs, ... }:
{
programs.waybar.enable = true;
@ -12,7 +12,7 @@
height = 28;
modules-left = [ "sway/workspaces" "sway/window" "sway/mode" ];
modules-center = [ ];
modules-right = [ "tray" "idle_inhibitor" "network" "bluetooth" "pulseaudio" "backlight" "battery" "clock" ];
modules-right = [ "tray" "custom/power_profile" "idle_inhibitor" "network" "bluetooth" "pulseaudio" "backlight" "battery" "clock" ];
"sway/mode" = {
"format" = "{}";
};
@ -88,6 +88,16 @@
"tray" = {
"spacing" = 4;
};
"custom/power_profile" =
let
script = "${config.xdg.configHome}/scripts/power_profile.sh";
in {
exec = "${script} icon";
on-click = "${script} toggle";
format = "{}";
tooltip = false;
interval = "10";
};
};
};
}

View file

@ -58,7 +58,8 @@ window#waybar.solo {
#tray,
#mode,
#idle_inhibitor,
#bluetooth {
#bluetooth,
#custom-power_profile {
padding: 0 10px;
color: @foreground;
background-color: @background;