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 = []
|
2020-03-13 16:00:25 +00:00
|
|
|
local_shell_dir = local_xxh_home / 'xxh/shells/xxh-shell-xonsh-appimage'
|
2020-03-13 15:22:53 +00:00
|
|
|
local_plugins_dir = local_xxh_home / 'xxh/plugins'
|
2020-03-15 17:20:47 +00:00
|
|
|
for local_package_dir in [local_shell_dir]+sorted(local_plugins_dir.glob(f'*-xonsh-*')):
|
|
|
|
plugin_name = local_package_dir.name
|
|
|
|
local_package_env = local_package_dir / 'env'
|
|
|
|
if local_package_env.exists():
|
|
|
|
plugin_env_name = plugin_name.upper().replace('-', '_')
|
|
|
|
with open(local_package_env) as f:
|
2020-03-13 15:22:53 +00:00
|
|
|
plugin_envs = f.read().split('\n')
|
|
|
|
for e in plugin_envs:
|
|
|
|
if e in ${...}:
|
2020-03-15 17:20:47 +00:00
|
|
|
xonsh_exec = '__xonsh__.env["%s"]=%s' % (e, repr(${e}))
|
|
|
|
bash_env = plugin_env_name + '_EXE_' + e
|
|
|
|
bash_exec = f'export {bash_env}={b64e(xonsh_exec)}'
|
|
|
|
|
2020-03-13 15:42:34 +00:00
|
|
|
if '+v' in $ARGS or '+vv' in $ARGS:
|
2020-03-15 17:20:47 +00:00
|
|
|
print(f'Plugin {local_package_dir.name} xonsh exec: {xonsh_exec}', file=sys.stderr)
|
|
|
|
print(f'Plugin {local_package_dir.name} bash exec: {bash_exec}', file=sys.stderr)
|
|
|
|
|
|
|
|
env_args += ['+heb', b64e(bash_exec)]
|
2020-03-13 15:22:53 +00:00
|
|
|
|
2020-03-13 22:07:43 +00:00
|
|
|
xxh @($ARGS) +s xonsh @(env_args)
|
2020-03-13 15:22:53 +00:00
|
|
|
|