Skip to main content

Library of decorator aliases for the xonsh shell.

Project description

Library of decorator aliases (daliases) for the xonsh shell.

If you like the idea click ⭐ on the repo and tweet.

Installation

To install use pip:

xpip install xontrib-dalias
# or
xpip install 'xontrib-dalias[dict,yaml]'  # With extra decorators.

Load:

xontrib load dalias

Usage

Transform output to object

Decorators:

XSH.aliases['@split'] = _mod({"output_format": _split_output}, "Alias decorator. Output format: list of parts.") XSH.aliases['@split-lines'] = _mod({"output_format": _split_lines_output}, "Alias decorator. Output format: list of splitted lines.") XSH.aliases['@split-lexer'] = _mod({"output_format": _lexer_split_output}, "Alias decorator. Output format: list of parts by xonsh lexer (same as @$()).") XSH.aliases['@split-lexer-lines'] = _mod({"output_format": _lexer_split_lines_output}, "Alias decorator. Output format: list of splitted lines by xonsh lexer (same as @$()).")

  • Default:
    • @lines - return list of lines.
    • @json - json to Python dict.
    • @jsonl - json lines to Python list with dict objects.
    • @path - string to pathlib.Path.
    • @split - split output by whitespaces.
    • @split-lines - split output lines by whitespaces.
    • @split-lexer - split output into parts using xonsh lexer. It's the same as builtin @$() operator.
    • @split-lexer-lines - split output lines into parts using xonsh lexer. It's the same as builtin @$() operator.
  • Extra (xpip install 'xontrib-dalias[dict,yaml]'):
    • @dict - dict-like object (json, JavaScript object, Python dict) to Python dict.
    • @dictl - dict-like objects (json, JavaScript object, Python dict) to Python list with dict objects.
    • @yaml - YAML to Python dict.

Examples

$(@lines ls /)
# ['/bin', '/etc', '/home']

$(@json echo '{"a":1}')  # Try with `curl` ;)
# dict({"a":1})

$(@jsonl echo '{"a":1}\n{"b":2}')
# [{'a': 1}, {'b': 2}]

docker inspect @($(@json docker ps --format json)['ID'])
# Container info


$(@path which -s xonsh)
# Path('/path/to/xonsh')

$(@path which -s xonsh).parent
# Path('/path/to')

$(@path echo '/tmp1\n/tmp2')
# [Path('/tmp1'), Path('/tmp2')]

$(@path echo ' ')  # Safe
# None

$(@path echo ' \n\n/tmp1')  # Safe
# [Path('/tmp1')]


aliases['ydig'] = '@yaml dig +yaml'  # Update `dig` via `brew install bind` to have `+yaml`.
y = $(ydig google.com)
y[0]['type']
# 'MESSAGE'

Piping into decorated alias to get object:

$(echo '{"a":1}' | @json cat)
# dict({"a":1})
aliases['@j'] = '@json cat'
$(echo '{"a":1}' | @j)
# dict({"a":1})

Error handling

Default decorators:

  • @err - set $RAISE_SUBPROC_ERROR=True for the command.
  • @noerr - set $RAISE_SUBPROC_ERROR=False for the command.

Examples:

$RAISE_SUBPROC_ERROR = True  # General environment.
if ![@noerr ls nononofile]:  # Do not raise exception in case of error.
    echo file 

Credits

This package was created with xontrib template.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xontrib_dalias-0.0.10.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xontrib_dalias-0.0.10-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file xontrib_dalias-0.0.10.tar.gz.

File metadata

  • Download URL: xontrib_dalias-0.0.10.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for xontrib_dalias-0.0.10.tar.gz
Algorithm Hash digest
SHA256 d379030c709e461be807d4509ec0a05d0841891b7f6f8b642a4d336b12b5ded2
MD5 87fbf7af99e3eca6a45d8a020968a81f
BLAKE2b-256 f4446ca4b663c37088c030c2ddbfc954ef80b8f164bae37ae09241d756a6b759

See more details on using hashes here.

File details

Details for the file xontrib_dalias-0.0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for xontrib_dalias-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 ad5cb4c1d597e5e18abde4fa3acbe47bcb7b89bb086777634b163ec5f6eb9c2e
MD5 62b28820559467e965d761e5997dec13
BLAKE2b-256 e140ceba87846fe850f56de34b0cdc5ce5f84a7eec258adac33cee77d6937a98

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page