<commit_before>#!/bin/sh
#For those of us who made our swap partitions a little bit too small ;)

usage() {
  echo "Run 'systemctl hibernate' only if the amount of memory in usage does not exceed the amount of available swap space.

Usage:
  safehibernate.sh [OPTIONS]
  -h: show this dialog
  -c: only check if hibernation is possible. Return 1 if so or else return 0"
}

if [ "$1" = "-h" ]; then
  usage
  exit 0
fi

fs=$(vmstat -s | grep 'free swap' | tr -s ' ' | cut -d ' ' -f 2)
um=$(vmstat -s | grep 'used memory' | tr -s ' ' | cut -d ' ' -f 2)
check_only=$(for x in "$@"; do if [ "$x" = "-c" ]; then echo 1; fi; done)

if [ $um -lt $fs ]; then
  if [ "$check_only" = 1 ]; then 
    echo 1
  else 
    systemctl hibernate
  fi
else
  if [ "$check_only" = 1 ]; then 
    echo 0
  else
    xmessage -center 'Cannot hibernate. Too much memory is in use.'
  fi
fi<commit_msg>safehibernate.sh - remove loop checking for -c arg. we do not have a complicated set of options here. just checking arg 1 is sufficient<commit_after>#!/bin/sh
#For those of us who made our swap partitions a little bit too small ;)

usage() {
  echo "Run 'systemctl hibernate' only if the amount of memory in usage does not exceed the amount of available swap space.

Usage:
  safehibernate.sh [OPTIONS]
  -h: show this dialog
  -c: only check if hibernation is possible. Return 1 if so or else return 0"
}

if [ "$1" = "-h" ] || [ "$#" -gt 1 ]; then
  usage
  exit 0
fi

fs=$(vmstat -s | grep 'free swap' | tr -s ' ' | cut -d ' ' -f 2)
um=$(vmstat -s | grep 'used memory' | tr -s ' ' | cut -d ' ' -f 2)

if [ $um -lt $fs ]; then
  if [ "$1" = "-c" ]; then 
    echo 1
  else 
    systemctl hibernate
  fi
else
  if [ "$1" = "-c" ]; then 
    echo 0
  else
    xmessage -center 'Cannot hibernate. Too much memory is in use.'
  fi
fi
{'fraction_non_alphanumeric': 0.12997787610619468, 'fraction_numerical': 0.012721238938053098, 'mean_word_length': 2.6693711967545637, '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': '5748186', 'n_tokens_mistral': 674, 'n_tokens_neox': 626, 'n_words': 285}