<commit_before>function contents_or_blank(filename)
  local contents = ""
  local stream = io.open(filename, "rb")
  if stream then
    contents = stream:read("*a")
    stream:close()
  end
  return contents
end

function shellprompt_os_getpowerinfo()
  local charging = nil
  local curcharge = nil
  local maxcharge = nil
  for i, bat in ipairs({"BAT1"}) do
    local info = contents_or_blank("/proc/acpi/battery/"..bat.."/info")
    local state = contents_or_blank("/proc/acpi/battery/"..bat.."/state")
    charging = state:match("charging state:%s*(%a+)")
    curcharge = state:match("remaining capacity:%s*(%d+)")
    maxcharge = info:match("last full capacity:%s*(%d+)")
  end
  local percent = math.max(0, math.min(100, curcharge*100/maxcharge))
  return {charging=charging, percent=percent}
end<commit_msg>Linux battery charge defaults to 100% if information unavailable<commit_after>function contents_or_blank(filename)
  local contents = ""
  local stream = io.open(filename, "rb")
  if stream then
    contents = stream:read("*a")
    stream:close()
  end
  return contents
end

function shellprompt_os_getpowerinfo()
  local charging = nil
  local curcharge = nil
  local maxcharge = nil
  for i, bat in ipairs({"BAT1"}) do
    local info = contents_or_blank("/proc/acpi/battery/"..bat.."/info")
    local state = contents_or_blank("/proc/acpi/battery/"..bat.."/state")
    charging = state:match("charging state:%s*(%a+)")
    curcharge = state:match("remaining capacity:%s*(%d+)")
    maxcharge = info:match("last full capacity:%s*(%d+)")
  end
  curcharge = curcharge or 100
  maxcharge = maxcharge or 100
  local percent = math.max(0, math.min(100, curcharge*100/maxcharge))
  return {charging=charging, percent=percent}
end
{'fraction_non_alphanumeric': 0.144335825186889, 'fraction_numerical': 0.01437607820586544, 'mean_word_length': 4.454545454545454, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2066308', 'n_tokens_mistral': 593, 'n_tokens_neox': 561, 'n_words': 137}