在window中 让makefile 自动补全生效
· One min read
以管理员身份打开PowerShell,然后执行:
# 查看当前执行策略
Get-ExecutionPolicy
# 将执行策略设置为 RemoteSigned(推荐)
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
# 或者设置为 Bypass(临时解决方案)
Set-ExecutionPolicy Bypass -Scope CurrentUser -Force
# 验证更改
Get-ExecutionPolicy -List
在powershell 中
notepad $PROFILE
编辑文件
# Make 命令补全函数
function MakeCompletion {
param($wordToComplete, $commandAst, $cursorPosition)
$makefile = Get-ChildItem -File | Where-Object {
$_.Name -in @('Makefile', 'makefile', 'GNUmakefile')
} | Select-Object -First 1
if ($makefile) {
$targets = Get-Content $makefile.FullName |
Select-String '^\s*([a-zA-Z0-9_-]+):' |
ForEach-Object { $_.Matches.Groups[1].Value } |
Sort-Object -Unique
$targets | Where-Object { $_ -like "$wordToComplete*" } |
ForEach-Object {
[System.Management.Automation.CompletionResult]::new(
$_,
$_,
'ParameterValue',
$_
)
}
}
}
# 注册补全
Register-ArgumentCompleter -CommandName make -ScriptBlock $function:MakeCompletion
现在可以了
make
输入tab 会自动补全