1
0

scripts.nix 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. };
  43. };
  44. }