You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromxontrib.macro.dataimportWritewith! Write('/tmp/t/hello.xsh', chmod=0o700, replace=True, makedir=True, format={'name': 'world'}, verbose=True):
echo {name}
## Make directories: /tmp/t## Write to file: /tmp/t/hello.xsh## Set chmod: rw- --- ---## Set exec: rwx --- ---/tmp/t/hello.xsh# world
There is also data.Replace() macro with mode='w', replace=True, makedir=True, replace_keep='a'.
Note! There is an upstream issue described below in "Known issues" section - the first lines that begin from # will be ignored in the block. As workaround to create shebang use Write(..., shebang="#!/bin/xonsh").
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:
fromxontrib.macro.runimportOncewith! Once('First install'):
if $(whichpacman):
pacman-Svimhtopelif $(whichapt):
aptupdate&&aptinstall-yvimhtop
fromxontrib.macro.containerimportRunInXonshPodmanasPodwith! Pod(): # default: image='xonsh/xonsh:slim', executor='/usr/local/bin/xonsh'echoInstalling...
pipinstall-U-qpiplolcatecho"We are in podman container now!"|lolcat# We are in podman container now! (colorized)
This is the same as:
podmanrun-it--rmxonsh/xonsh:slimxonsh-c @("""pip install -U -q pip lolcatecho "We are in podman container now!" | lolcat""")
signal.DisableInterrupt
This macro allows disabling SIGINT (Ctrl+C) for group of commands.
fromxontrib.macro.signalimportDisableInterruptechostartwith! DisableInterrupt():
echo'sleep start'sleep10echo'sleep end'echofinish# start# sleep start# [Press Ctrl+C]# KeyboardInterrupt will be raised at the end of current transaction.# sleep end# Exception KeyboardInterrupt: KeyboardInterrupt was received during transaction.
Known issues
Context Manager Macro picks up comments from outside the block and ignore the initial comments in 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!
Related
spec-mod - Library of xonsh subprocess specification modifiers e.g. $(@json echo '{}').