Advertisement
Guest User

context3.sh

a guest
Jun 15th, 2012
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.65 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. function usage
  4. {
  5.     echo "Usage $0 <file name> <line> <context>"
  6.     exit 1
  7. }
  8.  
  9. code_file=$1
  10. lineno=$2
  11. context=$3
  12.  
  13.  
  14. if [ "$lineno" = "" ] ; then
  15.     usage
  16. fi
  17.  
  18. if [ "$context" = "" ] ; then
  19.     context=6
  20. fi
  21.  
  22. if [ "$context" -lt "4" ] ; then
  23.    context=4
  24. fi
  25.  
  26. if [ $(($context % 2 )) != "0" ] ; then
  27.         context=$(($context + 1))
  28. fi
  29.  
  30. start_line=$(($lineno - ($context / 2)))
  31. end_line=$(($lineno + ($context / 2)))
  32.  
  33. cat -n $code_file | tail -n +$start_line | head -n $(($context + 1))
  34.  
  35. echo
  36. echo ---
  37. echo
  38.  
  39. hash=$(git blame $code_file -L $lineno,$lineno |cut -d " " -f 1)
  40. git --no-pager show $hash $code_file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement