Created
September 25, 2017 08:59
-
-
Save stknohg/98e12a01ee449cecbe48865633bb7be6 to your computer and use it in GitHub Desktop.
VSCodeのDiffを実行するファンクション
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSYS | |
VSCodeのDiffを実行します。 | |
.PARAMETER LeftFile | |
比較元ファイル名を指定します。 | |
.PARAMETER RightFile | |
比較ファイル名を指定します。 | |
.PARAMETER NewWindow | |
比較結果を新しいウィンドウで表示するか指定します。 | |
#> | |
function Invoke-VSCodeDiff { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory = $true, Position = 0)] | |
[string]$LeftFile, | |
[Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 1)] | |
[string]$RightFile, | |
[Parameter(Mandatory = $false)] | |
[Switch]$NewWindow | |
) | |
# validation | |
try { | |
[void](Get-Command code -ErrorAction Stop) | |
} catch { | |
Write-Error "Visual Studio Code(code) is not installed." | |
return | |
} | |
if (-not (Test-Path $LeftFile -PathType Leaf)) { | |
Write-Error ("{0} is not found." -f $LeftFile) | |
return | |
} | |
if (-not (Test-Path $RightFile -PathType Leaf)) { | |
Write-Error ("{0} is not found." -f $RightFile) | |
return | |
} | |
# diff | |
if ($NewWindow) { | |
code --new-window --diff $LeftFile $RightFile | |
return | |
} | |
code --diff $LeftFile $RightFile | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment