Colorize Subversion SVN (modification of post by Bishop view diff)
diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1186"></script>download | new post
Colorize STAT, UPDATE and DIFF (without params) commands output for Subversion (svn) and Mercurial (hg).
Here’s a PowerShell functions that you can use to make those numerous commands you run every day via the PowerShell CLI a little easier to read by adding colors.
Autodetect for svn or hg.
Update autodetect to work with psdrives that are a UNC path. Also now works with repositorys in the root directory of drive.
Added $args to each function so you can do things like sd -r2 -rtip -U0
- # detect source control management software
- function findscm {
- $scm = ''
- :selectscm foreach ($_ in @('svn', 'hg')) {
- $dir = (Get-Location).ProviderPath.trimEnd("\")
- while ($dir.Length -gt 3) {
- if (Test-Path ([IO.Path]::combine(($dir), ".$_"))) {
- $scm = $_
- break selectscm
- }
- $dir = $dir -Replace '\\[^\\]+$', ''
- }
- }
- return $scm
- }
- # draw output
- function drawlines($colors, $cmd) {
- $scm = findscm
- if (!$cmd -or !$scm) { return }
- foreach ($line in (&$scm ($cmd).split())) {
- $color = $colors[[string]$line[0]]
- if ($color) {
- write-host $line -Fore $color
- } else {
- write-host $line
- }
- }
- }
- # svn stat
- function st {
- drawlines @{ "A"="Magenta"; "D"="Red"; "C"="Yellow"; "G"="Blue"; "M"="Cyan"; "U"="Green"; "?"="DarkGray"; "!"="DarkRed" } "stat $args"
- }
- # svn update
- function su {
- drawlines @{ "A"="Magenta"; "D"="Red"; "U"="Green"; "C"="Yellow"; "G"="Blue"; } "up $args"
- }
- # svn diff
- function sd {
- drawlines @{ "@"="Magenta"; "-"="Red"; "+"="Green"; "="="DarkGray"; } "diff $args"
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
PowerShell Code Repository