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

Uploaded Python 3

File details

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

File metadata

  • Download URL: xontrib_dalias-0.0.8.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.8.tar.gz
Algorithm Hash digest
SHA256 5f1df040e0e91f4ceee0d5f99045fd24804f512e0b7bc16ba1ed2028d15eaa58
MD5 0d391208f8aa056db7a8d393c4df8b9d
BLAKE2b-256 a26a4a49e3e992411cf5fc27ad807cc36078d518dfacf3b14eaa1b7a01c7c21c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xontrib_dalias-0.0.8-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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 89ccdcab642699cba51985d13b5765c0577bc3093130d4e9f7e56ff85ee6a393
MD5 5a0b91db810cd8f417ef1d9fadf17c14
BLAKE2b-256 d4580cc342e775e34e0df0c39c69ae10ba7098ba3d74a30558786638b0036195

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