Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
VSCodeのDiffを実行するファンクション
<#
.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