Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- acpi_battery = %x[ acpi -b ]
- if acpi_battery.empty?
- puts "Battery not conected. Exiting."
- exit
- end
- $battery_status = acpi_battery.split(' ')[2].gsub(',', '')
- $battery_percentage = acpi_battery.split(' ')[3].gsub('%,', '').to_i
- def notification message, urgency, icon
- command = "notify-send --urgency=#{ urgency } 'Battery at #{ $battery_percentage }%' '\n #{ message }'"
- if not icon.nil?
- command += " --icon #{ icon }"
- end
- system command
- end
- def wall message
- system "sudo wall 'Battery at #{ $battery_percentage }% \n #{ message }'"
- end
- u = 'critical'
- i = '/usr/share/icons/HighContrast/scalable/emblems/emblem-important.svg'
- if $battery_status == "Discharging"
- case $battery_percentage
- when 10..19
- m = "Not long left. Get the power cord."
- u = 'normal'
- i = nil
- when 6..9
- m = "Plug-in the power cord."
- when 3..5
- m = "Wrap it up!"
- when 1..2
- m = "Oh, well... guess it's important..."
- when 0
- m = "Your're own your own. Good Luck!"
- else
- m = nil
- end
- notification(m, u, i) if not m.nil?
- end
- if $battery_status == "Charging"
- if (80..100).include? $battery_percentage
- notification "Enough charging!", u, i
- end
- end
- puts "Battery at #{ $battery_percentage }%"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement