#!/bin/sh # # Show line authors of a file # P4 environment variables should be set up already if [ $# -eq 0 ] then echo "Usage: p4blame.sh [file]" exit 1 fi check_length() { pad_length=0 truncate_length=0 if [ ${#1} -lt $max_length ] then pad_length=`expr $max_length - ${#1}` fi if [ ${#1} -gt $max_length ] then truncate_length=`expr ${#1} - $max_length` fi } pad() { i=0 padding="" while [ $i -lt $pad_length ] do padding=${padding}" " i=$[i+1] done } max_length=15 tmpfile=/tmp/content.txt p4 annotate -cq $1 > $tmpfile changes=$(cat $tmpfile | awk '{print substr($1, 0, length($1)-1); }' | sort -u) for change in $changes do author=$(p4 -ztag describe $change | grep user | awk '{print $3}') check_length $author if [ $truncate_length -eq 0 ] then pad sed -i "s/${change}:/${author}:${padding}/g" $tmpfile fi if [ $pad_length -eq 0 ] then author=$(echo $author $truncate_length | awk '{print substr($1, 0, length($1)-$2); }') sed -i "s/${change}:/${author}:/g" $tmpfile fi done cat $tmpfile