xxh/xonssh_xxh/xonshrc.xsh

40 lines
1.4 KiB
Text
Raw Normal View History

2020-02-29 13:38:33 +00:00
import sys, argparse
2020-02-08 21:57:47 +00:00
2020-02-27 22:27:28 +00:00
del $LS_COLORS # https://github.com/xonsh/xonsh/issues/3055
2020-02-29 13:38:33 +00:00
$UPDATE_OS_ENVIRON=True
2020-02-24 21:09:17 +00:00
$XXH_HOME = pf"{__file__}".absolute().parent
2020-02-29 13:38:33 +00:00
2020-02-24 21:09:17 +00:00
$PIP_TARGET = $XXH_HOME / 'pip'
2020-02-29 13:38:33 +00:00
$PIP_XONTRIB_TARGET = $PIP_TARGET / 'xontrib'
if not $PIP_XONTRIB_TARGET.exists():
mkdir -p @($PIP_XONTRIB_TARGET)
2019-11-03 13:06:26 +00:00
$PYTHONPATH = $PIP_TARGET
2020-02-24 21:09:17 +00:00
$PATH = [ p"$PYTHONHOME" / 'bin', $XXH_HOME ] + $PATH
sys.path.append(str($PIP_TARGET))
sys.path.remove('') if '' in sys.path else None
2020-02-23 08:49:42 +00:00
aliases['pip'] = ['python','-m','pip']
2020-02-29 13:38:33 +00:00
2020-03-01 07:24:58 +00:00
def _xxh_pip(args): # https://github.com/xonsh/xonsh/issues/3463
if args and 'install' in args and '-h' not in args and '--help' not in args:
print('\033[0;33mRun xpip in xontrib safe mode\033[0m')
pip_xontrib_tmp = $PIP_XONTRIB_TARGET.parent / 'xontrib-safe'
2020-02-29 13:38:33 +00:00
mv @($PIP_XONTRIB_TARGET) @(pip_xontrib_tmp)
2020-03-01 07:24:58 +00:00
pip @(args)
2020-02-29 15:28:39 +00:00
mkdir -p @($PIP_XONTRIB_TARGET)
2020-03-01 07:24:58 +00:00
if list(pip_xontrib_tmp.glob('*')):
bash -c $(echo mv @(pip_xontrib_tmp / '*') @($PIP_XONTRIB_TARGET))
2020-02-29 13:38:33 +00:00
rm -r @(pip_xontrib_tmp)
else:
2020-03-01 07:24:58 +00:00
pip @(args)
2020-02-29 13:38:33 +00:00
2020-03-01 07:24:58 +00:00
aliases['xpip'] = _xxh_pip
del _xxh_pip
2019-11-03 13:06:26 +00:00
2020-02-24 21:09:17 +00:00
for plugin_path in sorted(($XXH_HOME / 'plugins').glob('*')):
if (plugin_path / 'xonshrc.xsh').exists():
sys.path.append(str(plugin_path))
2020-02-16 14:00:51 +00:00
__import__('xonshrc')
del sys.modules['xonshrc']
2020-02-24 21:09:17 +00:00
sys.path.remove(str(plugin_path))