我有vim插件,可以在不同的机器上运行,有时需要根据是Windows、Linux还是Mac来做不同的事情。
测试操作系统最简单的方法是什么?我知道我可以解析:version命令的输出。有没有更简单的东西可以揭示操作系统?
发布于 2011-05-27 00:45:57
来自谷歌:您可以使用has()
和:help feature-list
下的特性列表来确定Vim的类型(以及在哪个操作系统下运行)。
if has('win32')
... win32 specific stuff ...
endif
从feature-list帮助主题中搜索"version of Vim“,这应该会将您带到可以查看的不同版本。
发布于 2011-05-27 13:04:54
除了@John的回答之外,这里还有一个可能的操作系统的完整列表:
"▶2 os.fullname
for s:os.fullname in ["unix", "win16", "win32", "win64", "win32unix", "win95",
\ "mac", "macunix", "amiga", "os2", "qnx", "beos", "vms"]
if has(s:os.fullname)
break
endif
let s:os.fullname='unknown'
endfor
"▶2 os.name
if s:os.fullname[-3:] is 'nix' || s:os.fullname[:2] is 'mac' ||
\s:os.fullname is 'qnx' || s:os.fullname is 'vms'
let s:os.name='posix'
elseif s:os.fullname[:2] is 'win'
let s:os.name='nt'
elseif s:os.fullname is 'os2'
let s:os.name='os2'
else
let s:os.name='other'
endif
"▲2
这是我的frawor插件用来确定当前操作系统的代码。
发布于 2011-05-27 00:56:02
由于我对Python的喜爱:
python << endpython
import sys
sys.platform
endpython
如果需要,也可以使用os.name
。
https://stackoverflow.com/questions/6146633
复制