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.
    • @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.
    • @yaml - YAML to Python dict.

Examples

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

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

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.7.tar.gz (5.9 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.7-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: xontrib_dalias-0.0.7.tar.gz
  • Upload date:
  • Size: 5.9 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.7.tar.gz
Algorithm Hash digest
SHA256 7f56454b30ec6f378181c5fb5ef6965b7a321eb3827a36e4bbc96ce2bb10d8ec
MD5 11f2e49613fcb272c7384590a50622fd
BLAKE2b-256 957b8f7214c47bbb41ef734c9d060190842e4b5ee4d8bcac2cbe837d7835c1b6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xontrib_dalias-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 5.5 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 2249136ba43388b358ee979aa062211286536cba3c55ca5d558d6dadd63409cc
MD5 11e30fa82ff3cecc7a817fed99f30506
BLAKE2b-256 be42351b71514b1f531c331714a2efe62cac7b496fdf5f137210b59a5c478909

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