Skip to main content

Configurable Ctrl-W algorithm, xontrib and CLI.

Project description

Configurable Ctrl-W (see gifs to understand what that means).

# TODO: gifs

This project addresses the pitfalls of xonsh (a brilliant project btw) builtin Ctrl-W functionality.

What exactly was wrong? There was no way to configure which characters are considered equivalent (and hence, to be deleted on a Ctrl-W keystoke). Say you wanted to edit a ‘cmd a/very/long/path’ and press a C-W. Then everything till space is removed, which often is not the desired behaviour.

Ok, so how to configure such a thing? Mathematically such configuration is equivalent to a partition of the set of all characters. In terms of implementation, disjoint set union data structure can be used to maintain partitions. Using a DSU is not really a requirement; however it turns out to be the simplest and cleanest implementation.

See docstring for load_partitions in cctrlw/algo.py to understand the approach used to define partitions.

Default cw_modes.json defines the following partitions:

  • S: singletons

  • ldu: {{a..z}, {0..9}, {A..Z}}

  • ldup: compared to ldu: elements of {!”#$%&’()*+,-./:;<=>?@[]^_`{|}~} are now equivalent

  • Ldp: compared to ldup: lower and upper letters are now merged

  • Ap: compared to Ldp: digits and letters are now merged

  • W: compared to Ap: digits and punctuation are merged

Xonsh default Ctrl-W corresponds to W, hence the name.

In terms of actual usage this module provides a CLI and a xontrib for use with xonsh:

  • CLI: run python -m cctrlw.cli -h for details.

  • Xontrib: add xontrib load xonsh_cctrlw to your .xonshrc. Then you can modify your config by setting $CW_MODE and $CW_CONFIG environment variables. Defaults are $CW_MODE = ‘Ap’ and $CW_CONFIG = ‘<package location>/cw_modes.json’.

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

cctrlw-0.4.tar.gz (7.1 kB view hashes)

Uploaded Source

Built Distribution

cctrlw-0.4-py3-none-any.whl (8.0 kB view hashes)

Uploaded Python 3

Supported by

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