<commit_before>###########################################
# Battery plugin for oh-my-zsh            #
# Original Author: <NAME> (peterhoeg) #
# Email: <EMAIL>              #
###########################################
# Author: <NAME> (neuralsandwich)     #
# Email: <EMAIL>         #
# Modified to add support for Apple Mac   #
###########################################
# Author: J (927589452)                   #
# Modified to add support for FreeBSD     #
###########################################

if [[ "$OSTYPE" = darwin* ]]; then

  function battery_is_charging() {
    ioreg -rc AppleSmartBattery | command grep -q '^.*"ExternalConnected"\ =\ Yes'
  }

  function battery_pct() {
    local smart_battery_status="$(ioreg -rc AppleSmartBattery)"
    local -F maxcapacity=$(command grep '^.*"MaxCapacity"\ =\ ' <<< $smart_battery_status | sed -e 's/^.*"MaxCapacity"\ =\ //')
    local -F currentcapacity=$(command grep '^.*"CurrentCapacity"\ =\ ' <<< $smart_battery_status | sed -e 's/^.*CurrentCapacity"\ =\ //')
    local -i pct=$(( (currentcapacity/maxcapacity) * 100 ))
    echo $pct
  }

  function battery_pct_remaining() {
    if battery_is_charging; then
      echo "External Power"
    else
      battery_pct
    fi
  }

  function battery_time_remaining() {
    local smart_battery_status="$(ioreg -rc "AppleSmartBattery")"
    if [[ $(echo $smart_battery_status | command grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]]; then
      timeremaining=$(echo $smart_battery_status | command grep '^.*"AvgTimeToEmpty"\ =\ ' | sed -e 's/^.*"AvgTimeToEmpty"\ =\ //')
      if [ $timeremaining -gt 720 ]; then
        echo "::"
      else
        echo "~$((timeremaining / 60)):$((timeremaining % 60))"
      fi
    else
      echo "∞"
    fi
  }
<commit_msg>battery: remove redundant grep calls in battery_pct function<commit_after>###########################################
# Battery plugin for oh-my-zsh            #
# Original Author: <NAME> (peterhoeg) #
# Email: <EMAIL>              #
###########################################
# Author: <NAME> (neuralsandwich)     #
# Email: <EMAIL>         #
# Modified to add support for Apple Mac   #
###########################################
# Author: J (927589452)                   #
# Modified to add support for FreeBSD     #
###########################################

if [[ "$OSTYPE" = darwin* ]]; then

  function battery_is_charging() {
    ioreg -rc AppleSmartBattery | command grep -q '^.*"ExternalConnected"\ =\ Yes'
  }

  function battery_pct() {
    local battery_status="$(ioreg -rc AppleSmartBattery)"
    local -i capacity=$(sed -n -e '/MaxCapacity/s/^.*"MaxCapacity"\ =\ //p' <<< $battery_status)
    local -i current=$(sed -n -e '/CurrentCapacity/s/^.*"CurrentCapacity"\ =\ //p' <<< $battery_status)
    echo $(( current * 100 / capacity ))
  }

  function battery_pct_remaining() {
    if battery_is_charging; then
      echo "External Power"
    else
      battery_pct
    fi
  }

  function battery_time_remaining() {
    local smart_battery_status="$(ioreg -rc "AppleSmartBattery")"
    if [[ $(echo $smart_battery_status | command grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]]; then
      timeremaining=$(echo $smart_battery_status | command grep '^.*"AvgTimeToEmpty"\ =\ ' | sed -e 's/^.*"AvgTimeToEmpty"\ =\ //')
      if [ $timeremaining -gt 720 ]; then
        echo "::"
      else
        echo "~$((timeremaining / 60)):$((timeremaining % 60))"
      fi
    else
      echo "∞"
    fi
  }

{'fraction_non_alphanumeric': 0.2412507171543316, 'fraction_numerical': 0.011474469305794608, 'mean_word_length': 3.0831381733021077, 'pattern_counts': {'":': 2, '<': 23, '<?xml version=': 0, '>': 11, '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': '1766459', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1072, 'n_words': 260}