Skip to main content

Configurable Ctrl-W algorithm, xontrib and CLI.

Project description

# cctrlw

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

This project addresses the pitfalls of [xonsh](https://xon.sh/) (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 ‘cd to/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](https://en.wikipedia.org/wiki/Partition_of_a_set) of the set of all characters. In terms of implementation, [disjoint set union data structure](https://en.wikipedia.org/wiki/Disjoint-set_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](https://github.com/ggdwbg/cctrlw/blob/main/cctrlw/algo.py#L166) for load_partitions in cctrlw/algo.py to understand the approach used to define partitions.

## Default configuration

Default cw_modes.json defines the following partitions:

  • S: singletons

  • ldu: {{a..z}, {0..9}, {A..Z}} (3 nontrivial classes)

  • ldup: compared to ldu: elements of string.punctuation are now equivalent (4 nontrivial classes)

  • Ldp: compared to ldup: lower and upper are merged (3 nontrivial classes)

  • Ap: compared to Ldp: digits and letters are merged (2 nontrivial classes)

  • W: compared to Ap: digits and punctuation are merged (1 nontrivial class, but space is not punctuation and still lives in a singleton)

Xonsh default Ctrl-W corresponds to W (approximately, because it removes trailing whitespace, which is never done in default config).

You can use your own config and add space to, for example, your custom ldu, then space will be removed automatically (furthermore, FASFfdsf dsfsfdsf ` would turn into `FASF with a single keystroke). Or do something completely different, that’s why it’s named config.

## What’s included

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

    Controlling state is done through envvars:
    • $CW_MODE: active partition; default: Ap.

    • $CW_CONFIG: active configuration json; default: <package location>/cw_modes.json

    • $CW_DEBUG: true to to see debug messages like what partition is loaded, false to disable; default: false.

## What could be improved

See TODOs.txt. Major ones could be:
  • a (subjectively) better version of whole-word-jumping

  • *sh plugin that uses CLI; originally cli was implemented exactly with that in mind.

    Learning bash/*sh is not really that interesting, so this may never end up done, but maybe fish is not as bad.

  • configurable __repr__ for dsu.

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.5.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

cctrlw-0.5-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file cctrlw-0.5.tar.gz.

File metadata

  • Download URL: cctrlw-0.5.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5

File hashes

Hashes for cctrlw-0.5.tar.gz
Algorithm Hash digest
SHA256 c2d661d838eb71fed1ac812b381b36fd55aa26be1ee7c8164dd430c98bcdc3fa
MD5 57f5e62908f4b6bf4c82f0c0b63b445f
BLAKE2b-256 b34f398ed2fa04c4daa354252f9a828bbd0959280f7f1cc695eb7bcd0edf2ce5

See more details on using hashes here.

File details

Details for the file cctrlw-0.5-py3-none-any.whl.

File metadata

  • Download URL: cctrlw-0.5-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5

File hashes

Hashes for cctrlw-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6fdecd75c2fcd4c3619bb4a9aba5b6cc93394b45b6c8594dd1ae7aa62daff014
MD5 86ac354a5c9c1993f8abeeffd23173e6
BLAKE2b-256 6bb725a936d621da3577b40eebdf16dd38f34ad45d06ffea1d41977162e0c735

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