<?php //limit the output of a text string function limitText($x, $length) { if (strlen($x) <= $length) { return $x; } else { $y = substr($x, 0, $length) . '...'; return $y; } } // EXAMPLE $string = 'long string text long string text long string text long string text long string text long string text long string text '; $limitString = limitText($string, 20); echo $limitString; // output = long string text lon...
} printf("\n"); } printf("\n"); } // Display stats infos if (count($stats)) { printf("[47;30m%-122s[0m\n", "Stats for the last " . count($commits) . " commits (within the last {$iteration} days)"); printf("%-20s %-20s %-20s %s\n", "", "Commits", "Files", ""); foreach ($stats as $committer => $stat) { displayValue(limitText($stat['name'], 20), 21); displayValue($stat['totalCommits'], 8, "0;33"); displayValue($stat['percentCommits'] . '%', 13); displayValue($stat['totalFiles'], 8, "0;33"); displayValue($stat['percentFiles'] . '%', 13); displayValue(limitText($committer, 39), 40); printf("\n"); } printf("\n"); } //---------- // Functions //---------- function getCurrentBranch($gitDir) { $cmd = sprintf("git --git-dir='%s/.git' branch | grep \\* | sed 's/* //g'", $gitDir); exec($cmd, $branch); if (count($branch) == 0) { exit('No branch selected in ' . $gitDir); } return $branch[0];