次のような機能を作りたい
if (vim is running in powershell)
call system("only works in powershell")
else
echo "Skipping powershell command"
誰かがvimが実行されているプログラムを知る方法を知っていますか?
編集:echo &termどちらの場合も「win32」を出力します。
次のような機能を作りたい
if (vim is running in powershell)
call system("only works in powershell")
else
echo "Skipping powershell command"
誰かがvimが実行されているプログラムを知る方法を知っていますか?
編集:echo &termどちらの場合も「win32」を出力します。
私が見るところから、vimが何から実行されたかを確認する必要はありません。オプションでPowerShellでコマンドを実行するように&shell指示された場合、vimはPowerShellでコマンドを実行するため、の値を確認する必要があります。&shellシェルの名前が次の場合posh、チェックは次のように実行できます。
if stridx(&shell, 'posh')!=-1
call system('only works in powershell')
else
echo 'Skipping powershell command'
endif
。しかし、私はむしろ、PowerShellを次のようなもので直接実行することをお勧めします
call system('posh -c '.shellescape('only works in powershell'))
(注:'posh -c '文字列が実際にどのように表示されるかはわかりません)または一時的なset&shellオプション:
let savedsh=[&shell, &shellcmdflag, &shellxquote, &shellxescape, &shellquote, &shellpipe, &shellredir]
set shell=posh shellcmdflag=-c shellxquote=\" shellquote=\" shellpipe=> shellredir=>
try
call system('only works in powershell')
finally
let [&shell, &shellcmdflag, &shellxquote, &shellxescape, &shellquote, &shellpipe, &shellredir]=savedsh
endtry
(繰り返しますが、オプションの正確な値についてはわかりません):これらの方法のコマンドは常にPowerShellで実行されます。
確認でき$termます。たとえば、私のcygwinと、では、としてgit bash取得$termし cygwinます。
Powershellの場合、プロファイルに次のように設定し、それを確認できます。
$env:TERM = "posh"
&shellcmdとpowershellの両方でcmd.exeが実行されることに注意してください。