My personal dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bar.rb 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #!/usr/bin/env ruby
  2. require 'rubygems'
  3. require 'barr'
  4. $pcounter = 0
  5. class Battery < Barr::Block
  6. def initialize opts={}
  7. super
  8. end
  9. def update!
  10. @output = `acpi --battery`
  11. @percent = Regexp.new('.*?(\\d+)(%)',Regexp::IGNORECASE).match(@output)[1]
  12. percent = @percent.to_i
  13. @time = Regexp.new('(\\d+)(.)(\\d+)',Regexp::IGNORECASE).match(@output).to_s
  14. @charging = `acpi --battery | grep "Charging"`.length > 1 ? true : false
  15. # Background color
  16. case percent
  17. when 90 .. 100
  18. @bgcolor = "#009f2d"
  19. when 80 .. 89
  20. @bgcolor = "#189228"
  21. when 70 .. 79
  22. @bgcolor = "#2F8523"
  23. when 60 .. 69
  24. @bgcolor = "#47781E"
  25. when 50 .. 59
  26. @bgcolor = "#5E6B19"
  27. when 40 .. 49
  28. @bgcolor = "#765D15"
  29. when 30 .. 39
  30. @bgcolor = "#8D5010"
  31. when 20 .. 29
  32. @bgcolor = "#A5430B"
  33. when 10 .. 19
  34. @bgcolor = "#BC3606"
  35. else
  36. @bgcolor = "#D42901"
  37. end
  38. # Icons
  39. if percent >= 90
  40. @icon = "\uf240"
  41. elsif percent >= 60
  42. @icon = "\uf241"
  43. elsif percent >= 40
  44. @icon = "\uf242"
  45. elsif percent > 10
  46. @icon = "\uf243"
  47. else
  48. @icon = "\uf244"
  49. end
  50. if not @charging
  51. if percent <= 3 and ($pcounter % 12) == 0
  52. %x{notify-send "Battery at 3%"}
  53. elsif percent <= 5 and ($pcounter % 12) == 0
  54. %x{notify-send "Battery at 5%"}
  55. elsif percent <= 10 and ($pcounter % 24) == 0
  56. %x{notify-send "Battery at 10%"}
  57. end
  58. end
  59. $pcounter += 1
  60. if @charging
  61. @icon = "\uf0e7"
  62. end
  63. @output = @percent + '% (' + @time + ')'
  64. end
  65. end
  66. class Volume < Barr::Block
  67. def initialize opts={} # Don't forget to accept your options hash!
  68. # super ensures the common configurable options can be set
  69. super
  70. end
  71. def update!
  72. @stat = %x(amixer get Master | tail -n 1 | cut -d '[' -f 3 | sed 's/]//g')
  73. @cmd = %x(amixer get Master |grep % |awk '{print $5}'|sed 's/[^0-9]//g' |head -1)
  74. if @stat == "on\n"
  75. @icon = "\uf028"
  76. else
  77. @icon = "\uf026"
  78. end
  79. @bgcolor = "#a12c2c"
  80. @output = @cmd + "%"
  81. end
  82. end
  83. class Brightness < Barr::Block
  84. def initialize opts={} # Don't forget to accept your options hash!
  85. # super ensures the common configurable options can be set
  86. super
  87. end
  88. def update!
  89. @cmd = %x(xbacklight)
  90. @icon = "\uf185"
  91. @bgcolor = "#d8c825"
  92. @output = @cmd.to_i.to_s + "%"
  93. end
  94. end
  95. @man = Barr::Manager.new
  96. i3 = Barr::Blocks::I3.new(fgcolor: '#ffffff',
  97. bgcolor: '#145266',
  98. focus_markers: %w(| |),
  99. interval: 0.25,
  100. icon: "\uf009")
  101. clock = Barr::Blocks::Clock.new(bgcolor: '#371E5E',
  102. format: '%r - %d %b %Y',
  103. icon: "\uf073",
  104. align: :c)
  105. weather = Barr::Blocks::Temperature.new(bgcolor: '#4A072B',
  106. align: :l,
  107. location: '22664159',
  108. icon: "\uf0c2",
  109. interval: 1500)
  110. hdd = Barr::Blocks::HDD.new bgcolor: '#444444', device: 'sda2', interval: 300
  111. local = Barr::Blocks::IP.new device: 'wlp8s0', bgcolor: '#937739', align: :r, icon: "\uf1ce"
  112. bat = Battery.new align: :r
  113. vol = Volume.new interval: 1, align: :r
  114. bright = Brightness.new interval: 1, align: :r
  115. # Left
  116. @man.add i3
  117. @man.add weather
  118. @man.add hdd
  119. # Right
  120. @man.add bright
  121. @man.add vol
  122. @man.add local
  123. @man.add bat
  124. # Center
  125. @man.add clock
  126. @man.run!