config

Personal configuration.
git clone git://code.dwrz.net/config
Log | Files | Refs

uncommitted (1270B)


      1 #!/usr/bin/env bash
      2 
      3 check_repo() {
      4   local d="$1"
      5 
      6   >&2 echo "Checking ${d}"
      7 
      8   # Change into the directory.
      9   cd "${d}" || exit 1
     10 
     11   # Check for uncommitted changes.
     12   git update-index --refresh > /dev/null 2>&1
     13   if git diff-index --quiet HEAD -- ; then
     14     # OK; nothing to commit.
     15     return
     16   fi
     17 
     18   # If changes exist, check their age relative to the last commit.
     19   last_commit_time=$(git log -1 --date=unix --format=%cd)
     20   current_time=$(date +%s)
     21   elapsed_sec=$(("${current_time}" - "${last_commit_time}"))
     22   elapsed_min=$(("${elapsed_sec}" / 60))
     23 
     24   # Ignore changes that aren't old enough to warrant a warning.
     25   if ! [[ "${elapsed_min}" -ge "${WARNING_MINUTES}" ]]; then
     26     return
     27   fi
     28 
     29   notify-send --urgency=low "$d" \
     30 	      "${elapsed_min} minutes since the last commit."
     31 }
     32 
     33 main() {
     34   # How many minutes to wait before displaying a warning; default 15.
     35   readonly WARNING_MINUTES="${1:-15}"
     36 
     37   >&2 echo "Checking uncommitted in the last ${WARNING_MINUTES} minutes."
     38 
     39   pass repositories | while read -r d; do
     40     if ! [[ -d "$d" ]]; then
     41       err "$0: ${d} is not a directory"
     42       continue
     43     fi
     44     if ! [[ -d "$d/.git/" ]]; then
     45       err "$0: %{d} is not a git repo; ignoring"
     46       continue
     47     fi
     48 
     49     check_repo "${d}"
     50 
     51   done
     52 }
     53 
     54 main "$@"