scripts.nix 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. { pkgs, lib, ... }:
  2. {
  3. home = {
  4. file = {
  5. clock = {
  6. target = ".config/waybar/clock.sh";
  7. text = ''
  8. # Generate the formatted date string
  9. formatted_date=$(LC_TIME=nb_NO.UTF-8 date +"%H:%M %A, %b %d" | tr '[:upper:]' '[:lower:]' | sed 's/\.//g')
  10. # Output as JSON for Waybar
  11. printf '{"text": "%s"}\n' "$formatted_date"
  12. '';
  13. executable = true;
  14. };
  15. memory = {
  16. target = ".config/waybar/memory.sh";
  17. text = ''
  18. free -m | awk '
  19. /^Mem:/ {
  20. current_gb = $3 / 1024;
  21. total_gb = $2 / 1024;
  22. printf "{\"text\": \"%.1fG/%.1fG\"}\n", current_gb, total_gb
  23. }'
  24. '';
  25. executable = true;
  26. };
  27. volume = {
  28. target = ".config/waybar/volume.sh";
  29. text = ''
  30. VOLUME_INFO=$(wpctl get-volume @DEFAULT_AUDIO_SINK@)
  31. VOL_NUM=$(echo "$VOLUME_INFO" | awk '{print $2}')
  32. VOL_PERC=$(awk -v n="$VOL_NUM" 'BEGIN {print int(n * 100)}')
  33. if [[ "$VOLUME_INFO" == *"[MUTED]"* ]]; then
  34. RESULT="Muted ($VOL_PERC%)"
  35. else
  36. RESULT="$VOL_PERC%"
  37. fi
  38. echo "{\"text\": \"$RESULT\"}"
  39. '';
  40. executable = true;
  41. };
  42. mic-mute = {
  43. target = ".config/waybar/mic-mute.sh";
  44. text = ''
  45. #!/usr/bin/env bash
  46. # Toggle mute
  47. amixer set 'Capture' toggle
  48. # Check new state
  49. if amixer get Capture | grep -q '\[off\]'; then
  50. notify-send "Microphone Muted" "Your mic has been muted." -i microphone-sensitivity-muted-symbolic
  51. else
  52. notify-send "Microphone Unmuted" "Your mic is live." -i microphone-sensitivity-high-symbolic
  53. fi
  54. '';
  55. executable = true;
  56. };
  57. output-mute = {
  58. target = ".config/waybar/output-mute.sh";
  59. text = ''
  60. #!/usr/bin/env bash
  61. # Toggle mute
  62. amixer set 'Master' toggle
  63. # Check new state
  64. if amixer get Master | grep -q '\[off\]'; then
  65. notify-send "Master Muted" "You may no longer hear." -i audio-volume-muted-symbolic
  66. else
  67. notify-send "Master Unmuted" "You may hear now." -i audio-volume-high-symbolic
  68. fi
  69. '';
  70. executable = true;
  71. };
  72. };
  73. };
  74. }