<p align="center">
Library of the useful <a href="https://xon.sh/tutorial_macros.html">macros</a> for the <a href="https://xon.sh/">xonsh shell</a>.
</p>
<p align="center">
If you like the idea click ⭐ on the repo and <a href="https://twitter.com/intent/tweet?text=Nice%20xontrib%20for%20the%20xonsh%20shell!&url=https://github.com/anki-code/xontrib-macro-lib" target="_blank">tweet</a>.
</p>
## Installation
To install use pip:
```bash
xpip install xontrib-macro-lib
# or: xpip install -U git+https://github.com/anki-code/xontrib-macro-lib
```
## Usage
By loading the whole module - recommended for interactive usage (type `macrolib.<Tab>`):
```xsh
xontrib load macrolib
with! macrolib.data.Write('/tmp/hello'):
world
```
By importing certain macro - recommended for scripts:
```xsh
from xontrib.macrolib.data import Write
with! Write('/tmp/hello'):
world
```
## Macro list
### Block (xonsh builtin)
```python
from xonsh.contexts import Block
with! Block() as b:
any
text
here
b.macro_block
# 'any\ntext\nhere\n\n'
b.lines
# ['any', 'text', 'here', '']
```
### Write
Write a file from block ([rich list of parameters](https://github.com/anki-code/xontrib-macro-lib/blob/main/xontrib/macrolib/data.py#L12)):
```xsh
from xontrib.macrolib.data import Write
with! Write('/tmp/t/hello.xsh', chmod=0o600, exec='u', replace=True, makedir=True, verbose=True):
echo world
## 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 `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](https://en.wikipedia.org/wiki/Shebang_(Unix)) use `Write(..., shebang="#!/bin/xonsh")`.
### JsonBlock
Make json block and use it as dict:
```python
from xontrib.macrolib.data import JsonBlock
with! JsonBlock() as j:
{"hello": "world"}
j['hello']
# 'world'
```
### Run Once
Run the code once and save mark about it in [XONSH_DATA_DIR](https://xon.sh/envvars.html#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:
```python
from xontrib.macrolib.run import Once
with! Once('First install'):
if $(which pacman):
pacman -S vim htop
elif $(which apt):
apt update && apt install -y vim htop
```
### RunInDocker
```xsh
from xontrib.macrolib.docker import RunInDocker as docker
with! docker(): # default: image='ubuntu', executor='bash'
echo hello
# hello
```
### RunInXonshDocker
```python
from xontrib.macrolib.docker import RunInXonshDocker as Doxer
with! Doxer(): # default: image='xonsh/xonsh:slim', executor='/usr/local/bin/xonsh'
echo Installing...
pip install -U -q pip lolcat
echo "We are in docker container now!" | lolcat
# We are in docker container now! (colorized)
```
This is the same as:
```python
docker run -it --rm xonsh/xonsh:slim xonsh -c @("""
pip install -U -q pip lolcat
echo "We are in docker container now!" | lolcat
""")
```
## Known issues
Context Manager Macro picks up comments from outside the block and ignore the initial comments in the block ([4207](https://github.com/xonsh/xonsh/issues/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](https://github.com/xonsh/xontrib-cookiecutter).
Raw data
{
"_id": null,
"home_page": "https://github.com/anki-code/xontrib-macro-lib",
"name": "xontrib-macro-lib",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "",
"author": "anki-code",
"author_email": "no@no.no",
"download_url": "https://files.pythonhosted.org/packages/09/08/fbef2d2932599d3868135823c8e340410d396cebd04eaa78a8f3434beeed/xontrib-macro-lib-0.2.0.tar.gz",
"platform": "any",
"description": "<p align=\"center\">\nLibrary of the useful <a href=\"https://xon.sh/tutorial_macros.html\">macros</a> for the <a href=\"https://xon.sh/\">xonsh shell</a>.\n</p>\n\n<p align=\"center\"> \nIf you like the idea click \u2b50 on the repo and <a href=\"https://twitter.com/intent/tweet?text=Nice%20xontrib%20for%20the%20xonsh%20shell!&url=https://github.com/anki-code/xontrib-macro-lib\" target=\"_blank\">tweet</a>.\n</p>\n\n\n## Installation\n\nTo install use pip:\n\n```bash\nxpip install xontrib-macro-lib\n# or: xpip install -U git+https://github.com/anki-code/xontrib-macro-lib\n```\n\n## Usage\n\nBy loading the whole module - recommended for interactive usage (type `macrolib.<Tab>`): \n```xsh\nxontrib load macrolib\nwith! macrolib.data.Write('/tmp/hello'):\n world\n```\n\nBy importing certain macro - recommended for scripts:\n```xsh\nfrom xontrib.macrolib.data import Write\nwith! Write('/tmp/hello'):\n world\n```\n\n## Macro list\n\n### Block (xonsh builtin)\n```python\nfrom xonsh.contexts import Block\n\nwith! Block() as b:\n any\n text\n here\n\nb.macro_block\n# 'any\\ntext\\nhere\\n\\n'\nb.lines\n# ['any', 'text', 'here', '']\n```\n\n### Write\n\nWrite a file from block ([rich list of parameters](https://github.com/anki-code/xontrib-macro-lib/blob/main/xontrib/macrolib/data.py#L12)):\n\n```xsh\nfrom xontrib.macrolib.data import Write\n\nwith! Write('/tmp/t/hello.xsh', chmod=0o600, exec='u', replace=True, makedir=True, verbose=True):\n echo world\n \n## Make directories: /tmp/t\n## Write to file: /tmp/t/hello.xsh\n## Set chmod: rw- --- ---\n## Set exec: rwx --- ---\n\n/tmp/t/hello.xsh\n# world\n```\nThere is also `Replace()` macro with `mode='w', replace=True, makedir=True, replace_keep='a'`.\n\nNote! 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](https://en.wikipedia.org/wiki/Shebang_(Unix)) use `Write(..., shebang=\"#!/bin/xonsh\")`.\n\n### JsonBlock\n\nMake json block and use it as dict:\n\n```python\nfrom xontrib.macrolib.data import JsonBlock\n\nwith! JsonBlock() as j:\n {\"hello\": \"world\"}\n\nj['hello']\n# 'world'\n```\n\n### Run Once\n\nRun the code once and save mark about it in [XONSH_DATA_DIR](https://xon.sh/envvars.html#xonsh-data-dir). \nIn 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.\n\nExample:\n```python\nfrom xontrib.macrolib.run import Once\n\nwith! Once('First install'):\n if $(which pacman):\n pacman -S vim htop\n elif $(which apt):\n apt update && apt install -y vim htop\n```\n\n### RunInDocker\n\n```xsh\nfrom xontrib.macrolib.docker import RunInDocker as docker\n\nwith! docker(): # default: image='ubuntu', executor='bash'\n echo hello\n\n# hello\n```\n\n### RunInXonshDocker\n\n```python\nfrom xontrib.macrolib.docker import RunInXonshDocker as Doxer\n\nwith! Doxer(): # default: image='xonsh/xonsh:slim', executor='/usr/local/bin/xonsh'\n echo Installing...\n pip install -U -q pip lolcat\n echo \"We are in docker container now!\" | lolcat\n \n# We are in docker container now! (colorized)\n```\n\nThis is the same as:\n```python\ndocker run -it --rm xonsh/xonsh:slim xonsh -c @(\"\"\"\npip install -U -q pip lolcat\necho \"We are in docker container now!\" | lolcat\n\"\"\")\n```\n\n## Known issues\n\nContext Manager Macro picks up comments from outside the block and ignore the initial comments in the block ([4207](https://github.com/xonsh/xonsh/issues/4207)). We can fix it in the xontrib by checking the indentation in the beginning line and the end line. PR is welcome!\n\n## Credits\n\nThis package was created with [xontrib cookiecutter template](https://github.com/xonsh/xontrib-cookiecutter).\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Library of the useful macroses for the xonsh shell.",
"version": "0.2.0",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2f48b03cee8f7507a95ddf94654a59b1357dc6d6e458afeded52e80fd412a80f",
"md5": "fc0204afced34823dab19074a573bd1a",
"sha256": "4aa084d8b451cf889939c30730082aa0bc4c7c2bfe5f1281c9b6ec4da3d408d9"
},
"downloads": -1,
"filename": "xontrib_macro_lib-0.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fc0204afced34823dab19074a573bd1a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 7046,
"upload_time": "2023-03-18T21:00:30",
"upload_time_iso_8601": "2023-03-18T21:00:30.645363Z",
"url": "https://files.pythonhosted.org/packages/2f/48/b03cee8f7507a95ddf94654a59b1357dc6d6e458afeded52e80fd412a80f/xontrib_macro_lib-0.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0908fbef2d2932599d3868135823c8e340410d396cebd04eaa78a8f3434beeed",
"md5": "b74291254790725ea91598e42731c85e",
"sha256": "b37a3499c9c87ce6f1d1fd0f275b8a36f9305c9a0afb1332f628efd1c140e59b"
},
"downloads": -1,
"filename": "xontrib-macro-lib-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "b74291254790725ea91598e42731c85e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 6337,
"upload_time": "2023-03-18T21:00:32",
"upload_time_iso_8601": "2023-03-18T21:00:32.364675Z",
"url": "https://files.pythonhosted.org/packages/09/08/fbef2d2932599d3868135823c8e340410d396cebd04eaa78a8f3434beeed/xontrib-macro-lib-0.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-03-18 21:00:32",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "anki-code",
"github_project": "xontrib-macro-lib",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "xonsh",
"specs": []
}
],
"lcname": "xontrib-macro-lib"
}