我希望使用稀疏结帐编辑器就地编辑git nvim信息。我有下面的代码,几乎可以工作。
function Choose () {
begin {
$file = New-TemporaryFile
}
process
{
$_ >> $file
}
end {
nvim $file
Get-Content $file
Remove-Item $file
}
}
function Git-Sparse-Checkout-Edit
{
git sparse-checkout list | Choose | git sparse-checkout set --stdin
}如果我写
git sparse-checkout list | Choose然后,在git稀疏签出命令的输出上打开nvim编辑器,当我'wq‘(保存和退出)时,文件的内容被写入stdout。但当我尝试
git sparse-checkout list | Choose | git sparse-checkout set --stdin而不是打开编辑器,整个窗口终端停止,我不得不杀死它。我的选择功能是否正确实现?
发布于 2022-08-08 07:36:58
function Choose () {
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[string[]]
$Text
)
begin {
$file = New-TemporaryFile
$Text
}
process
{
foreach ($line in $Text){
$line >> $file
}
}
end{
start-process nvim $file -wait
Get-Content $file
Remove-Item $file
}
}并使用它编辑git稀疏签出列表。
function Git-Sparse-Checkout-Edit
{
git sparse-checkout list | Choose | git sparse-checkout set --stdin
}使用启动过程似乎是阻止管道停滞的关键,但我不知道为什么。
https://stackoverflow.com/questions/73273823
复制相似问题