Skip to content

Instantly share code, notes, and snippets.

@stknohg
Created September 25, 2017 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stknohg/98e12a01ee449cecbe48865633bb7be6 to your computer and use it in GitHub Desktop.
Save stknohg/98e12a01ee449cecbe48865633bb7be6 to your computer and use it in GitHub Desktop.
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