Skip to content

Instantly share code, notes, and snippets.

@lmmx
Last active August 29, 2015 14:19
Show Gist options
  • Save lmmx/99d2f45c690d16e2a307 to your computer and use it in GitHub Desktop.
Save lmmx/99d2f45c690d16e2a307 to your computer and use it in GitHub Desktop.
Automated git status summary shell function (Bash/inline Python). See https://github.com/lmmx/devnotes/wiki/Automated-git-status-summary
function gnews {
gitnews="$(git status --porcelain)";
export gitnews;
gitreport="$(python -c 'from os import environ as e; gnew=e["gitnews"].split("\n");\
mods=[stat[3:] for stat in gnew if stat[0]=="M"];\
adds=[stat[3:] for stat in gnew if stat[0]=="A"];\
dels=[stat[3:] for stat in gnew if stat[0]=="D"];\
rens=[stat[3:] for stat in gnew if stat[0]=="R"];\
cops=[stat[3:] for stat in gnew if stat[0]=="C"];\
upds=[stat[3:] for stat in gnew if stat[0]=="U"];\
modreport=["Changed ".join(["",", ".join(statuslist)]) for statuslist in [mods] if len(mods)>0];\
addreport=["Added ".join(["",", ".join(statuslist)]) for statuslist in [adds] if len(adds)>0];\
delreport=["Deleted ".join(["",", ".join(statuslist)]) for statuslist in [dels] if len(dels)>0];\
renreport=["Renamed ".join(["",", ".join(statuslist)]) for statuslist in [rens] if len(rens)>0];\
copreport=["Copied ".join(["",", ".join(statuslist)]) for statuslist in [cops] if len(cops)>0];\
updreport=["Updated ".join(["",", ".join(statuslist)]) for statuslist in [upds] if len(upds)>0];\
report=[". ".join(stats) for stats in [modreport,addreport,delreport,renreport,copreport,updreport] if len(stats)>0];\
print ". ".join(report)')";
unset gitnews;
echo "$gitreport";
}
function getgot {
git add .;
commitment="$(gnews)";
git commit -m "$commitment";
git push origin master;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment