Library of the useful macros for the xonsh shell.
If you like the idea click
Installation
To install use pip:
xpip install xontrib-macro-lib
# or: xpip install -U git+https://github.com/anki-code/xontrib-macro-lib
Macro list
RunOnce
Run the code once and save mark about it in XONSH_DATA_DIR. In the next run the code will not be executed if it was not changed. If the code will be changed it will be executed again.
Example:
from xontrib.macro_lib.run_once import RunOnce
with! RunOnce('First install'):
if $(which pacman):
pacman -S vim htop
elif $(which apt):
apt update && apt install -y vim htop
RunInXonshDocker
from xontrib.macro_lib.docker import RunInXonshDocker as Doxer
with! Doxer():
pip install -U -q pip lolcat
echo "We are in docker container now!" | lolcat
This is the same as:
docker run -it --rm xonsh/xonsh:slim xonsh -c @("""
pip install -U -q pip lolcat
echo "We are in docker container now!" | lolcat
""")
JsonBlock
from xontrib.macro_lib.data import JsonBlock
with! JsonBlock() as j:
{
"hello": "world"
}
j['hello']
# 'world'
Block (xonsh builtin)
from xonsh.contexts import Block
with! Block() as b:
qwe
asd
zxc
b.macro_block
# 'qwe\nasd\nzxc\n\n'
b.lines
# ['qwe', 'asd', 'zxc', '']
Known issues
Context Manager Macros pick up comments from outside the block (4207). We can fix it in the xontrib by checking the indentation in the beginning line and the end line. PR is welcome!
Credits
This package was created with xontrib cookiecutter template.