Skip to content

Instantly share code, notes, and snippets.

@mersinvald
Last active May 24, 2018 11:29
Show Gist options
  • Save mersinvald/b244c73dac730016ceab971e190a8ab3 to your computer and use it in GitHub Desktop.
Save mersinvald/b244c73dac730016ceab971e190a8ab3 to your computer and use it in GitHub Desktop.
Prints how much time one could have fun with friends or make out with {girl,boy}friend, but compiled h{is,er} Gentoo
#!/bin/bash
# Description: Prints how much time one could have fun with friends or make out with {girl,boy}friend, but compiled h{is,er} Gentoo
# Author: Mike Lubints (aka mersinvald) 2016
#
# Dependencies:
# bash
# bc
# genlop
#
# Note: runs from root (or with portage rights)
source /etc/portage/make.conf
CACHE=$(pwd)/genlop_cache
# if no genlop ouput is cached, run it
if [ ! -f $CACHE ]; then
# Get merge history
HISTORY=$(genlop -l | sed -r 's/\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g' | sed 's/.*>>>//g' | sed 's/ //g' | sed 's/.*\///g' | sed 's/-[0-9].*$//g')
genlop -t $(echo $HISTORY) | sed -r 's/\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g' > $CACHE
else
echo "Using cacned genlop output. If you want dry run, do \"rm $CACHE\""
fi
# Grepping mtime line
MTIME=$(grep "merge time" $CACHE | sed 's/ //g' | sed 's/ //g' | sed 's/mergetime://g' | sed 's/and//g' | sed 's/\.//g' | sed 's/hour.\?/h/g' | sed 's/minute.\?/m/g' | sed -e 's/second.\?/s/g' | sed 's/ms/m/g' | sed 's/,//g' )
# Grepping lists of h, m, s
H=$(echo $MTIME | sed 's/[0-9]\+m//g' | sed 's/[0-9]\+s//g' | sed 's/h//g')
M=$(echo $MTIME | sed 's/[0-9]\+h//g' | sed 's/[0-9]\+s//g' | sed 's/m//g')
S=$(echo $MTIME | sed 's/[0-9]\+h//g' | sed 's/[0-9]\+m//g' | sed 's/s//g')
# Summing
H=$(echo $H | sed 's/ / + /g' | bc)
M=$(echo $M | sed 's/ / + /g' | bc)
S=$(echo $S | sed 's/ / + /g' | bc)
# Formatting
M=$(echo $M + \($S / 60\) | bc)
S=$(echo $S % 60 | bc)
H=$(echo $H + \($M / 60\) | bc)
M=$(echo $M % 60 | bc)
D=$(echo $H / 24 | bc)
H=$(echo $H % 24 | bc)
# Making user sad
NORM='\033[0m'
BOLD='\033[1m'
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
MAGENTA='\033[0;35m'
printf "You spent ${RED}$D days${NORM}, ${MAGENTA}$H hours${NORM}, ${GREEN}$M minutes${NORM} and ${YELLOW}$S seconds${NORM} compiling your Gentoo\n"
@mersinvald
Copy link
Author

Place your results here in the comments!

Mine:
6 days, 10 hours, 23 minutes and 53 seconds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment