2020-03-13 15:22:53 +00:00
|
|
|
#!/usr/bin/env xonsh
|
|
|
|
#
|
|
|
|
# This entrypoint is to allow xxh getting current environment variables
|
|
|
|
# and pass some of them to xxh session to seamless transition to host.
|
|
|
|
#
|
|
|
|
# Usage in xonsh: source xxh.xsh [ordinary xxh arguments]
|
|
|
|
#
|
|
|
|
|
|
|
|
from base64 import b64encode
|
|
|
|
|
|
|
|
def b64e(s):
|
|
|
|
return b64encode(str(s).encode()).decode()
|
|
|
|
|
|
|
|
local_xxh_home = p"~/.xxh"
|
|
|
|
|
|
|
|
env_args = []
|
|
|
|
local_plugins_dir = local_xxh_home / 'xxh/plugins'
|
|
|
|
for local_plugin_dir in local_plugins_dir.glob(f'*-xonsh-*'):
|
|
|
|
local_plugin_env = local_plugin_dir / 'env'
|
|
|
|
if local_plugin_env.exists():
|
|
|
|
with open(local_plugin_env) as f:
|
|
|
|
plugin_envs = f.read().split('\n')
|
|
|
|
for e in plugin_envs:
|
|
|
|
if e in ${...}:
|
2020-03-13 15:42:34 +00:00
|
|
|
if '+v' in $ARGS or '+vv' in $ARGS:
|
|
|
|
print(f'Plugin {local_plugin_dir.name} environment: {e}='+str(${e}), file=sys.stderr)
|
2020-03-13 15:40:30 +00:00
|
|
|
env_args += ['+eb', "%s=%s" % ( e, b64e(${e}) ) ]
|
2020-03-13 15:22:53 +00:00
|
|
|
|
2020-03-13 15:40:30 +00:00
|
|
|
./xxh @($ARGS) +s xonsh @(env_args)
|
2020-03-13 15:22:53 +00:00
|
|
|
|