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:

  • 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.
    • @parts - split by whitespaces 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.9.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.9-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: xontrib_dalias-0.0.9.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.9.tar.gz
Algorithm Hash digest
SHA256 3a4c7698080c532f7961877686d399f952c0227a772b8dad6c4f0a61c4d27519
MD5 05b851002d01f18d98f6f377bf28b5a8
BLAKE2b-256 f3e196e93253cfd7b964a638fcc0e9b211ec3bca7a3f2a733a6bc9c8d1d2192f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xontrib_dalias-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for xontrib_dalias-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 255a1c3df3e4773fddd6baae378e20118434acdf1347594edd109ac221a050f3
MD5 3ac0e03b431ec52b4ab0f6d065801860
BLAKE2b-256 3aac46adf179098a4aa71cf21ec87dbf88b2738f38c226f506e50fab80fb2f7c

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