Skip to content

Instantly share code, notes, and snippets.

@jessebutryn
Created June 8, 2019 16:25
Show Gist options
  • Select an option

  • Save jessebutryn/b208420a7e1cadecddf0737f26a3a10d to your computer and use it in GitHub Desktop.

Select an option

Save jessebutryn/b208420a7e1cadecddf0737f26a3a10d to your computer and use it in GitHub Desktop.
This script will create a 12 week lifting program based on your 1 rep maxes
#!/usr/bin/env bash
# VARIABLES
##################################
weeks[1]='70:5'
weeks[2]='75:3'
weeks[3]='80:1'
weeks[4]='75:5'
weeks[5]='80:3'
weeks[6]='85:1'
weeks[7]='80:5'
weeks[8]='85:3'
weeks[9]='90:1'
weeks[10]='85:5'
weeks[11]='90:3'
weeks[12]='95:1'
TXT_BLD=$(tput bold)
TXT_RST=$(tput sgr0)
TXT_GRN=$(tput setaf 2)
# FUNCTIONS
##################################
echo.help () {
# Displays help and usage information
cat <<EOF
This script will create a 12 week lifting program based on your 1 rep maxes.
Usage: $(basename "$0") -d 350 -b 250 -s 350
$(basename "$0") [-h] -d deadlift_max -b bench_max -s squat_max
-h Print help output.
-d Specify your 1 rep deadlift max.
-b Specify your 1 rep bench press max.
-s Specify your 1 rep squat max.
EOF
exit 10
}
calc_percent () {
local max
local per
max=$1
per=$2
per=$(awk -v p="$per" 'BEGIN{ print p / 100 }')
awk -v p="$per" -v m="$max" 'BEGIN{ printf("%.0f", m * p) }'
}
print_week () {
local week=$1
local wper=$2
local wrep=$3
local bench=$(calc_percent "$mbench" "$wper")
local dead=$(calc_percent "$mdead" "$wper")
local squat=$(calc_percent "$msquat" "$wper")
printf '%25s\n\n' "${TXT_BLD}----------Week ${week}----------${TXT_RST}"
for i in squat bench dead; do
for ((n=1;n<=5;n++)); do
printf '%18s%15s\n' "${TXT_GRN}${i}${TXT_RST}:" "${!i} x ${wrep}"
done
echo
done
}
# ARGUMENTS
##################################
(($#<1)) && echo.help
while getopts b:d:s:h opt; do
case $opt in
h) echo.help;;
b) mbench=$OPTARG;;
d) mdead=$OPTARG;;
s) msquat=$OPTARG;;
*) printf '%s\n' "Unknown Option: $opt" >&2; echo.help;;
esac
done
# RUN
##################################
for ((w=1;w<=12;w++)); do
p=$(awk -F\: '{print $1}' <<<"${weeks[w]}")
r=$(awk -F\: '{print $2}' <<<"${weeks[w]}")
print_week "$w" "$p" "$r"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment