I would like to make a function which does the following
if (vim is running in powershell)
call system("only works in powershell")
else
echo "Skipping powershell command"
Does anyone know how to tell what program vim is being run from?
EDIT: echo &term
outputs "win32" in both cases.
From what I see you don't need to check what vim was run from. You need to check the value of &shell
because vim will run command in powershell if &shell
option tells it to run command in powershell. If name of the shell is posh
then checking may be done with
if stridx(&shell, 'posh')!=-1
call system('only works in powershell')
else
echo 'Skipping powershell command'
endif
. But I would rather suggest to run powershell directly with something like
call system('posh -c '.shellescape('only works in powershell'))
(note: I am not sure about what 'posh -c '
string should actually look like) or temporary set &shell option:
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
(again, not sure about exact values of options): these ways command will always run in powershell.
You can check $term
. For example on my cygwin
and git bash
, I get $term
as cygwin
.
For Powershell, you may set in your profile the following and check against that:
$env:TERM = "posh"
Note that &shell
will cmd.exe for both cmd and powershell.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.