Skip to content

Instantly share code, notes, and snippets.

@troyunverdruss
Last active April 30, 2019 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save troyunverdruss/ca7e4444dba60ff30a5afd0635b76949 to your computer and use it in GitHub Desktop.
Save troyunverdruss/ca7e4444dba60ff30a5afd0635b76949 to your computer and use it in GitHub Desktop.
#!/bin/bash
# in ~/.gitconfig
# [alias]
# lines = !~/bin/calculate-changed-lines.sh
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
CURRENT_REPO_PATH=$(git rev-parse --show-toplevel)
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
printf "Repo: ${CURRENT_REPO_PATH}\n"
printf "Branch: ${CURRENT_BRANCH}\n"
REMOVED=$(git diff master | grep "^-" | grep -v "^---" | wc -l | sed -e 's/[[:space:]]//g')
ADDED=$(git diff master | grep "^+" | grep -v "^+++" | wc -l | sed -e 's/[[:space:]]//g')
TOTAL=$((REMOVED + ADDED))
printf "${GREEN}+${ADDED} added${NC}, ${RED}-${REMOVED} removed${NC} (${TOTAL} total)\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment