scripts.nix 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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="M($VOL_PERC%)"
  35. else
  36. RESULT="$VOL_PERC%"
  37. fi
  38. echo "{\"text\": \"$RESULT\"}"
  39. '';
  40. executable = true;
  41. };
  42. mic = {
  43. target = ".config/waybar/mic.sh";
  44. text = ''
  45. VOLUME_INFO=$(wpctl get-volume @DEFAULT_AUDIO_SOURCE@)
  46. VOL_NUM=$(echo "$VOLUME_INFO" | awk '{print $2}')
  47. VOL_PERC=$(awk -v n="$VOL_NUM" 'BEGIN {print int(n * 100)}')
  48. if [[ "$VOLUME_INFO" == *"[MUTED]"* ]]; then
  49. RESULT="M($VOL_PERC%)"
  50. else
  51. RESULT="$VOL_PERC%"
  52. fi
  53. echo "{\"text\": \"$RESULT\"}"
  54. '';
  55. executable = true;
  56. };
  57. net = {
  58. target = ".config/waybar/net.sh";
  59. executable = true;
  60. text = ''
  61. #!/usr/bin/env bash
  62. # Get default network interface
  63. DEVICE=$(ip route | awk '/default/ {print $5; exit}')
  64. if [[ -n "$DEVICE" ]]; then
  65. # Get local IPv4 address
  66. IP=$(ip -4 addr show "$DEVICE" | awk '/inet / {print $2}' | cut -d/ -f1 | head -n1)
  67. if [[ -n "$IP" ]]; then
  68. RESULT="$DEVICE ($IP)"
  69. else
  70. RESULT="$DEVICE (no ip)"
  71. fi
  72. else
  73. RESULT="Disconnected"
  74. fi
  75. echo "{\"text\": \"$RESULT\"}"
  76. '';
  77. };
  78. mic-mute = {
  79. target = ".config/waybar/mic-mute.sh";
  80. text = ''
  81. #!/usr/bin/env bash
  82. # Toggle mute
  83. amixer set 'Capture' toggle
  84. # Check new state
  85. if amixer get Capture | grep -q '\[off\]'; then
  86. notify-send "Microphone Muted" "Your mic has been muted." -i microphone-sensitivity-muted-symbolic
  87. else
  88. notify-send "Microphone Unmuted" "Your mic is live." -i microphone-sensitivity-high-symbolic
  89. fi
  90. '';
  91. executable = true;
  92. };
  93. output-mute = {
  94. target = ".config/waybar/output-mute.sh";
  95. text = ''
  96. #!/usr/bin/env bash
  97. # Toggle mute
  98. amixer set 'Master' toggle
  99. # Check new state
  100. if amixer get Master | grep -q '\[off\]'; then
  101. notify-send "Master Muted" "You may no longer hear." -i audio-volume-muted-symbolic
  102. else
  103. notify-send "Master Unmuted" "You may hear now." -i audio-volume-high-symbolic
  104. fi
  105. '';
  106. executable = true;
  107. };
  108. };
  109. };
  110. }