Skip to main content

Library for parsing config files for sxhkd, and command-line programs using it

Project description

sxhkd-parser

sxhkd-parser is a mostly complete library written in Python 3.7 for parsing sxhkd configs.

It has no dependencies and will not have any in the future.

Bundled tools

  • hkcheck: Lint your keybinds.
  • hkexport: Export your keybinds to various formats including HTML and plaintext.
  • hkwatch: Tail the sxhkd status fifo and output the current mode.
  • hkfind: Get hotkeys that match given search criteria.
  • hkxargs: Execute commands on a keybind's command for editing them, retrieving some information from them, or running linters on them.
  • hkdebug: Retrieve information useful for debugging the config.

For more, see the modules prefixed with hk in sxhkd_parser/cli/.

Goals

  • Provide a high-level library for manipulating sxhkd configs
  • Be a test-bed for compatible extensions to sxhkdrc syntax

Interface Stability

The library API has no guarantees about stability (yet), but the interface of the CLI tools should be relatively more stable.

This project follows semantic versioning. On v1.0.0, the library API will be stable and the CLI tools will be split into a separate Python package after which they can start to have dependencies.

Quickstart

Install

We will use pipx because it is convenient. pipx is available on distro repositories.

Run pipx install sxhkd-parser.

Manuals

If your system uses man-db, include export MANPATH="$HOME/.local/pipx/venvs/sxhkd-parser/share/man:" in .profile, .bashrc, or any startup config file of your choice.

Run man <TOOL> for the details of each tool. man 7 sxhkd-parser also has the background information needed to use them.

Print all your keybinds

from sxhkd_parser import *

for bind_or_err in read_sxhkdrc('sxhkdrc'):
    if isinstance(bind_or_err, SXHKDParserError):
        print(bind_or_err)
        continue
    keybind = bind_or_err
    print(keybind)
    keybind.hotkey.get_tree().print_tree()
    keybind.command.get_tree().print_tree()

Include sections and descriptions

from sxhkd_parser import *

handler = SimpleSectionHandler(r'^#\s*(?P<name>[A-Z. /-]+):$')
parser = SimpleDescriptionParser(r'^#\s*(?P<description>[A-Z][^.]+\.)$')
for bind_or_err in read_sxhkdrc('sxhkdrc', section_handler=handler, metadata_parser=parser):
    if isinstance(bind_or_err, SXHKDParserError):
        print(bind_or_err)
        continue
    keybind = bind_or_err
    print(keybind)
    keybind.hotkey.get_tree().print_tree()
    keybind.command.get_tree().print_tree()
handler.get_tree().print_tree()

In this example, the description for a keybind is the comment immediately preceding the start of the keybind that matches the given regex.

Terminology

  1. Hotkey: The sequence of chords needed to activate a command.
  2. Command: The command passed to the shell after the hotkey is completed.
  3. Keybind: The entity that encompasses the above.

I'm aware that "hotkey" and "keybind" are interchangeable and have the meaning of (3) above, so any suggestions for renaming (1) are welcome.

Limitations

To maintain simplicity in the implementation, some uncommon features of sxhkd are unsupported. The list follows:

  • Inconsistent location of : to indicate noabort across the permutations of a hotkey:
    • Each Hotkey object has a single noabort_index attribute. This will not change.
    • So, it's best to keep : outside of any sequences.
  • Alphanumeric ranges within sequences of the form {s1,s2,s3,...,sn}:
    • These are OK:
      • Alphabetic: A-Z, a-z, A-F, a-f, A-z (within ASCII)
      • Numeric: 0-9, 5-8
    • These are not: 0-A, A-0
    • I'm open to changing this if there's a good justification for it.
  • Command cycling:
    • The library enforces the invariant that, within each keybind, the number of permutations of the hotkey and the command are equal.
    • It's undocumented and thus unlikely to be used that much anyway.

Also, using @ or ~ at the start of the hotkey instead of just before the keysym (as documented in the manpage of sxhkd) is unsupported. Use the documented syntax.

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

sxhkd-parser-0.1.0.tar.gz (75.1 kB view details)

Uploaded Source

Built Distribution

sxhkd_parser-0.1.0-py3-none-any.whl (82.8 kB view details)

Uploaded Python 3

File details

Details for the file sxhkd-parser-0.1.0.tar.gz.

File metadata

  • Download URL: sxhkd-parser-0.1.0.tar.gz
  • Upload date:
  • Size: 75.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.2

File hashes

Hashes for sxhkd-parser-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0bacb1852a95161f96c5727f7caf0362c2f875b3a87b6aa754270f4b7578bd19
MD5 f771e3448bbf73b221b6c52d3b23bfbe
BLAKE2b-256 4759ba78b5cfc10cdf47aab003171116ca429b9cb0747d74d50c9606471f4a91

See more details on using hashes here.

File details

Details for the file sxhkd_parser-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sxhkd_parser-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 82.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.2

File hashes

Hashes for sxhkd_parser-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c9d7f05b439a513879d7c70f887902650f8ffa3e63c195d42747c3d84f4d45b
MD5 92765fef41578eada5466f7efa714a88
BLAKE2b-256 a0f4bdc249ce5e70d82eab8fe4ab1b5b193bee32aacbdcd7acab2ec84cd39131

See more details on using hashes here.

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