Often in my scripts I have some ugly snippets like the following:
vim9script
var bin = ""
if has("win32")
bin = "\\bin"
else
bin = "/bin"
endif
g:path_with_bin = g:path .. bin
The same happens when it comes to environment variables since they are expressed as $MY_VARIABLE
syntax in OSX and Linux systems and %MY_VARIABLE%
in Windows (at least when using cmd.exe
).
I am wondering if there are functions that recognise the OS and prevent us to explicitely use conditionals, something like
g:path_with_bin = g:path .. adjust_slashes(bin)
that sets slash-backslashes automatically depending on the OS, or, for environment variables, something like the following:
env_var_set(MY_VARIABLE, value)
which set $MY_VARIABLE
or %MY_VARIABLE%
to value
depending on the OS.
:h env<C-d>
…