scripts.nix 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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, %d %b" | 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. IP=$(ip -4 addr show "$DEVICE" | awk '/inet / {print $2}' | cut -d/ -f1 | head -n1)
  66. RESULT="$DEVICE"
  67. else
  68. RESULT="Disconnected"
  69. fi
  70. echo "{\"text\": \"$RESULT\"}"
  71. '';
  72. };
  73. mic-mute = {
  74. target = ".config/waybar/mic-mute.sh";
  75. text = ''
  76. #!/usr/bin/env bash
  77. # Toggle mute
  78. amixer set 'Capture' toggle
  79. # Check new state
  80. if amixer get Capture | grep -q '\[off\]'; then
  81. notify-send "Microphone Muted" "Your mic has been muted." -i microphone-sensitivity-muted-symbolic
  82. else
  83. notify-send "Microphone Unmuted" "Your mic is live." -i microphone-sensitivity-high-symbolic
  84. fi
  85. '';
  86. executable = true;
  87. };
  88. output-mute = {
  89. target = ".config/waybar/output-mute.sh";
  90. text = ''
  91. #!/usr/bin/env bash
  92. # Toggle mute
  93. amixer set 'Master' toggle
  94. # Check new state
  95. if amixer get Master | grep -q '\[off\]'; then
  96. notify-send "Master Muted" "You may no longer hear." -i audio-volume-muted-symbolic
  97. else
  98. notify-send "Master Unmuted" "You may hear now." -i audio-volume-high-symbolic
  99. fi
  100. '';
  101. executable = true;
  102. };
  103. screenshot = {
  104. target = "Scripts/ss.sh";
  105. text = ''
  106. FILE=~/Pictures/Screenshots/$(date +%F_%T).png
  107. grim -g "$(slurp)" "$FILE"
  108. wl-copy < "$FILE"
  109. swappy -f "$FILE"
  110. '';
  111. executable = true;
  112. };
  113. #futhark-xkb = {
  114. # target = ".config/xkb/symbols/futhark";
  115. # text = ''
  116. # default partial alphanumeric_keys
  117. # xkb_symbols "basic" {
  118. #
  119. # name[Group1]= "Futhark";
  120. #
  121. # key <AD04> { [ U16A0 ] }; // f -> ᚠ
  122. #
  123. # include "no(basic)"
  124. # };
  125. # '';
  126. #};
  127. };
  128. };
  129. }