diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8c5790840..5fb0a63aa 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,6 +12,7 @@ Current Developments * Automatically enhance colors for readability in the default terminal (cmd.exe) on Windows. This functionality can be enabled/disabled with the $INTENSIFY_COLORS_ON_WIN environment variable. +* Added ``Ellipsis`` lookup to ``__xonsh_env__`` to allow environment variable checks, e.g. ``'HOME' in ${...}`` **Changed:** diff --git a/docs/tutorial.rst b/docs/tutorial.rst index 5a7897c43..53a9c529b 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -197,6 +197,14 @@ examples in action: Not bad, xonsh, not bad. +If you want to check if an environment variable is present in your current +session (say, in your awesome new ``xonsh`` script) you can pass an Ellipsis to +the ``${}`` operator: + +.. code-block:: xonshcon + + >>> 'HOME' in ${...} + True Running Commands ============================== diff --git a/xonsh/environ.py b/xonsh/environ.py index c35512de6..65af405a1 100644 --- a/xonsh/environ.py +++ b/xonsh/environ.py @@ -585,6 +585,8 @@ class Env(MutableMapping): # def __getitem__(self, key): + if key is Ellipsis: + return self m = self._arg_regex.match(key) if (m is not None) and (key not in self._d) and ('ARGS' in self._d): args = self._d['ARGS']