I desire for Vim to detect when it has been launched from within Firefox
(to edit a text area or whatever[*1]. Initially I spotted I could do
this with:
if exists('$MOZILLA_FIVE_HOME')
Then at some point Firefox (or whatever it was called at the time)
hatefully stopped setting that variable. I spotted another one it was
now setting, so the test became:
if exists('$MOZ_PLUGIN_PATH') || exists('$MOZILLA_FIVE_HOME')
Recently I spotted it'd hatefully broken again, so looked to see what
variables are being set:
:!env | grep -i moz
MOZ_LAUNCHED_CHILD=
Sounds plausible. Except that it turns out that Vim is unable to
distinguish an environment variable whose value is the empty string from
one which doesn't exist at all.
exists('$MOZ_LAUNCHED_CHILD') claims that it doesn't exist.
expand('$MOZ_LAUNCHED_CHILD') expands it not to the empty string, but to
the literal '$MOZ_LAUNCHED_CHILD'.
Hateful!
So now it appears I have to shell out to the env command. What started
as simply testinig for the existence of one variable is now:
let in_firefox = 0
if exists('$MOZ_PLUGIN_PATH') || exists('$MOZILLA_FIVE_HOME')
let in_firefox = 1
else
call system('env | grep -q ^MOZ_LAUNCHED_CHILD=')
let in_firefox = v:shell_error == 0
endif
if in_firefox
Smylers
[*1] Over the years there've been a succession of Firefox extensions
which offer this in some way or other, before then becoming incompatible
or otherwise disappearing. Their hate has varied (though always present
in some form) and their names forgettable. I'm not even sure which
extension I've got doing this at the moment.