指定されたパスのファイルに対してリストで指定された文字列を検索し、Quickfixリストを返すpowershellスクリプトです。
vimgrepでいいじゃんとか言わないで…
<#
.SYNOPSIS
指定されたパスのファイルに対してリストで指定された文字列を検索し、Quickfixリストを返します。
.EXAMPLE
Get-QuickfixListByList -targetFiles *.sql -matchStrings "table1","table2" | out-file test.out -Encoding default
#>
function Get-QuickfixListByList(){
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[string[]]
#検索するファイルのパス
$targetFiles,
[string[]]
[Parameter(Mandatory=$true)]
#検索する文字列
$matchStrings
)
Process{
foreach($targetFile in $targetFiles){
foreach($matchString in $matchStrings){
$hits = Select-String -Path $targetFile -Pattern $matchString
if($hits.length -gt 0){
foreach($hit in $hits){
$line = $hit.Line
$lineNumber = $hit.LineNumber
foreach($match in $hit.Matches){
$col = $match.Index + 1
"$targetFile|$lineNumber col $col| $line"
}
}
}
}
}
}
}
import-moduleしてから、下記の様に使用します。
Get-QuickfixListByList -targetFiles *.sql -matchStrings "table1","table2" | out-file test.out -Encoding default
作成したファイルをvimで読み込みます。
:GetVimgrepFile test.out