
context3.sh
By: a guest on
Jun 15th, 2012 | syntax:
Bash | size: 0.65 KB | hits: 61 | expires: Never
#!/bin/bash
function usage
{
echo "Usage $0 <file name> <line> <context>"
exit 1
}
code_file=$1
lineno=$2
context=$3
if [ "$lineno" = "" ] ; then
usage
fi
if [ "$context" = "" ] ; then
context=6
fi
if [ "$context" -lt "4" ] ; then
context=4
fi
if [ $(($context % 2 )) != "0" ] ; then
context=$(($context + 1))
fi
start_line=$(($lineno - ($context / 2)))
end_line=$(($lineno + ($context / 2)))
cat -n $code_file | tail -n +$start_line | head -n $(($context + 1))
echo
echo ---
echo
hash=$(git blame $code_file -L $lineno,$lineno |cut -d " " -f 1)
git --no-pager show $hash $code_file