configuration.nix/home/scripts.nix

128 lines
3.4 KiB
Nix
Raw Normal View History

2023-03-16 23:36:17 +05:30
{ osConfig, pkgs, ... }:
2023-03-17 22:44:27 +05:30
let
notify-send = "${pkgs.libnotify}/bin/notify-send";
dmenu = "${pkgs.rofi-wayland}/bin/rofi -dmenu";
in
2023-03-15 22:11:59 +05:30
{
2023-03-16 23:36:17 +05:30
xdg.configFile = {
"scripts/power_menu.sh" = {
executable = true;
text = ''
#!/bin/sh
2023-03-15 22:11:59 +05:30
2023-03-16 23:36:17 +05:30
set -eu
2023-03-15 22:11:59 +05:30
2023-03-16 23:36:17 +05:30
chpower() {
case "$1" in
"")
;;
Shutdown)
exec systemctl poweroff
;;
Reboot)
exec systemctl reboot
;;
Hibernate)
exec systemctl hibernate
;;
Logout)
swaymsg exit
;;
*)
2023-03-17 22:44:27 +05:30
${notify-send} -t 1500 -u low "Invalid Option"
2023-03-16 23:36:17 +05:30
;;
esac
}
2023-03-15 22:11:59 +05:30
2023-03-16 23:36:17 +05:30
OPTIONS="Shutdown\nReboot\nHibernate\nLogout"
2023-03-17 22:44:27 +05:30
chpower "$(printf "%b" "$OPTIONS" | sort | ${dmenu} -p "Power Menu")"
2023-03-16 23:36:17 +05:30
'';
};
2023-03-17 22:44:27 +05:30
"scripts/volume_up.sh" =
let
wpctl = "${pkgs.wireplumber}/bin/wpctl";
in
{
executable = true;
text = ''
#!/bin/sh
2023-03-16 23:36:17 +05:30
2023-03-17 22:44:27 +05:30
set -eu
2023-03-16 23:36:17 +05:30
2023-03-17 22:44:27 +05:30
${wpctl} set-mute @DEFAULT_AUDIO_SINK@ 0
[ $(${wpctl} get-volume @DEFAULT_AUDIO_SINK@ | awk -F': ' '{print $2}' | sed 's/\.//') -lt 100 ] && ${wpctl} set-volume @DEFAULT_AUDIO_SINK@ 5%+
'';
};
2023-03-16 23:36:17 +05:30
2023-03-17 22:44:27 +05:30
"scripts/tmux_sessions.sh" =
let
kitty = "${pkgs.kitty}/bin/kitty";
tmux = "${pkgs.tmux}/bin/tmux";
in
{
executable = true;
text = ''
#!/bin/sh
2023-03-16 23:36:17 +05:30
2023-03-17 22:44:27 +05:30
set -eu
2023-03-16 23:36:17 +05:30
2023-03-17 22:44:27 +05:30
SESSION="$(${tmux} list-sessions -F "(#{session_attached}) #S [#{pane_current_command} in #{pane_current_path}] #{pane_title}" | sort | ${dmenu} -p "Running TMUX Sessions" | awk '{print $2}')"
case "$SESSION" in
"")
;;
*)
${kitty} ${tmux} -u attach-session -dEt "$SESSION"
;;
esac'';
};
2023-03-16 23:36:17 +05:30
"scripts/power_profile.sh" =
let
sudo = "/run/wrappers/bin/sudo";
cpupower = "${osConfig.boot.kernelPackages.cpupower}/bin/cpupower";
powerprofilesctl = "${pkgs.power-profiles-daemon}/bin/powerprofilesctl";
2023-03-17 00:15:25 +05:30
in
{
executable = true;
text = ''
#!/bin/sh
2023-03-16 23:36:17 +05:30
2023-03-17 00:15:25 +05:30
set -eu
2023-03-16 23:36:17 +05:30
2023-03-17 00:15:25 +05:30
POWER_PROFILE_FILE="$HOME/.cache/power_profile"
POWER_PROFILE="powersave"
2023-03-16 23:36:17 +05:30
2023-03-17 00:15:25 +05:30
if [ -f "$POWER_PROFILE_FILE" ]; then
POWER_PROFILE="$(<$POWER_PROFILE_FILE)"
fi
2023-03-16 23:36:17 +05:30
2023-03-17 00:15:25 +05:30
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
2023-03-17 22:44:27 +05:30
${notify-send} -u normal "Power Profile" "Switched to $POWER_PROFILE mode."
2023-03-17 00:15:25 +05:30
;;
"icon")
if [ "$POWER_PROFILE" == "powersave" ]; then
echo "󰌪"
elif [ "$POWER_PROFILE" == "performance" ]; then
echo "󰓅"
fi
2023-03-16 23:36:17 +05:30
;;
*)
;;
2023-03-17 00:15:25 +05:30
esac
'';
};
2023-03-15 22:11:59 +05:30
};
}