Debian-facile

Bienvenue sur Debian-Facile, site d'aide pour les nouveaux utilisateurs de Debian.

Vous n'êtes pas identifié(e).

Raw Paste Créer un nouveau Paste

Sans titre - #D4C58D2D09

  1. #!/bin/bash
  2.  
  3. # Icons
  4. volumeIcon=""
  5. dateIcon=""
  6. timeIcon=""
  7. musicIcon=""
  8. playIcon=""
  9. pauseIcon=""
  10. stopIcon=""
  11. hddIcon=""
  12. ramIcon=""
  13. batteryIcon=""
  14.  
  15. # Send the header so that i3bar knows we want to use JSON:
  16. echo '{ "version": 1 }'
  17.  
  18. # Begin the endless array.
  19. echo '['
  20.  
  21. # We send an empty first array of blocks to make the loop simpler:
  22. echo '[]'
  23.  
  24. # Now send blocks with information forever:
  25. while :;
  26. do
  27. # MOC
  28. title=$(mocp -i | grep -E ^SongTitle: | cut -d ":" -f2 | cut -c 2-)
  29. artist=$(mocp -i | grep -E ^Artist: | cut -d ":" -f2 | cut -c 2-)
  30. album=$(mocp -i | grep -E ^Album: | cut -d ":" -f2 | cut -c 2-)
  31. state=$(mocp -i | grep -E ^State: | cut -d ":" -f2 | cut -c 2-)
  32.  
  33. if [ $state = "PLAY" ]; then
  34. mocp="${musicIcon} [ ${playIcon} ${state} ] ${title} - ${artist} (${album})"
  35. elif [ $state = "PAUSE" ]; then
  36. mocp="${musicIcon} [ ${pauseIcon} ${state} ] ${title} - ${artist} (${album})"
  37. elif [ ${state} = "STOP" ]; then
  38. mocp="${musicIcon} [ ${stopIcon} ${state} ]"
  39. else
  40. mocp=""
  41. fi
  42.  
  43. # Volume
  44. volume=$(amixer get Master -M | grep -oE -m1 '[[:digit:]]*%' | cut -d '%' -f 1)
  45.  
  46. if [ $volume -eq 0 ]; then # si = 0
  47. volumeIcon=""
  48. elif [ $volume -gt 0 ] && [ $volume -lt 50 ]; then
  49. volumeIcon=""
  50. elif [ $volume -ge 51 ]; then
  51. volumeIcon=""
  52. fi
  53.  
  54.  
  55. # Disk
  56. fullDisk=$(df -h | grep -i "sda1" | awk '{print $2}')
  57. usedDisk=$(df -h | grep -i "sda1" | awk '{print $3}')
  58.  
  59. # Ram
  60. fullRam=$(free -m | grep 'Mem' | awk '{ print $2}')
  61. usedRam=$(free -m | grep 'Mem' | awk '{ print $3}')
  62.  
  63. # Swap
  64. fullSwap=$(free -m | grep 'Swap' | awk '{ print $2}')
  65. usedSwap=$(free -m | grep 'Swap' | awk '{ print $3}')
  66.  
  67. # Battery
  68. battery=$(acpi -b | awk '{print $4}' | cut -d ',' -f 1)
  69. batteryTime=$(acpi -b | awk '{print $5}')
  70. batteryState=$(acpi -b | awk '{print $6}')
  71.  
  72. if [ "$batteryState" = "until" ]; then
  73. batteryState="avant charge complète"
  74. elif [ "$batteryState" = "remaining" ]; then
  75. batteryState="restant"
  76. fi
  77.  
  78. # Date
  79. date=$(date +"%A %e %B %Y")
  80.  
  81. # Time
  82. time=$(date +"%T")
  83.  
  84. # Open array
  85. echo ",["
  86.  
  87. # MOC
  88. echo "{"
  89. echo "\"full_text\":\"${mocp}\","
  90. echo "\"color\":\"#e16c76\""
  91. echo "}"
  92.  
  93. # Volume
  94. echo ",{"
  95. echo "\"full_text\":\"${volumeIcon} ${volume}\","
  96. echo "\"color\":\"#99c47a\""
  97. echo "}"
  98.  
  99. # Disk
  100. echo ",{"
  101. echo "\"full_text\":\"${hddIcon} ${usedDisk}/${fullDisk}Go\","
  102. echo "\"color\":\"#d29b66\""
  103. echo "}"
  104.  
  105. # Ram
  106. echo ",{"
  107. echo "\"full_text\":\"${ramIcon} ${usedRam}/${fullRam} Mo\","
  108. echo "\"color\":\"#61b0f0\""
  109. echo "}"
  110.  
  111. # Swap
  112. echo ",{"
  113. echo "\"full_text\":\"${hddIcon} ${usedSwap}/${fullSwap} Mo\","
  114. echo "\"color\":\"#c779de\""
  115. echo "}"
  116.  
  117. # Battery
  118. echo ",{"
  119. echo "\"full_text\":\"${batteryIcon} ${battery} (${batteryTime} ${batteryState})\","
  120. echo "\"color\":\"#ffffff\""
  121. echo "}"
  122.  
  123. # Date
  124. echo ",{"
  125. echo "\"full_text\":\"${dateIcon} ${date}\","
  126. echo "\"color\":\"#56b7c3\""
  127. echo "}"
  128.  
  129. # Time
  130. echo ",{"
  131. echo "\"full_text\":\"${timeIcon} ${time}\","
  132. echo "\"color\":\"#dfc559\""
  133. echo "}"
  134.  
  135. # Close array
  136. echo "]"
  137. done

Pied de page des forums

Propulsé par FluxBB