Skip to main content

Verified line-addressed file editor using lnhash addresses

Project description

exhash — Verified Line-Addressed File Editor

exhash combines Can Bölük's very clever line number + hash editing system with the powerful and expressive syntax of the classic ex editor.

Install via pip to get both a convenient Python API, and native CLI binaries:

pip install exhash

Or install just the CLI binaries via cargo:

cargo install exhash

lnhash format

We refer to an lnhash as a tag of the form lineno|hash|, where hash is the lower 16 bits of Rust's DefaultHasher over the line content. exhash is just like ex, except that addresses must be in lnhash format. Addresses like %, ., etc are not permitted.

CLI

The native Rust binaries are installed into your PATH via pip.

View

# Shows every line prefixed with its lnhash
lnhashview path/to/file.txt
# Optional line number range to show
lnhashview path/to/file.txt 10 20

Edit

# Substitute on one line
exhash file.txt '12|abcd|s/foo/bar/g'

# Append multiline text (terminated by a single dot)
exhash file.txt '12|abcd|a' <<'EOF'
new line 1
new line 2
.
EOF

# Dry-run
exhash --dry-run file.txt '12|abcd|d'

For a/i/c commands, provide the text block on stdin:

printf "new line 1\nnew line 2\n.\n" | exhash file.txt "2|beef|a"

Stdin filter mode

cat file.txt | exhash --stdin - '1|abcd|s/foo/bar/'

In --stdin mode, multiline a/i/c text blocks are not available.

Python API

from exhash import exhash, lnhash, lnhashview, line_hash

Viewing

text = "foo\nbar\n"
view = lnhashview(text)  # ["1|a1b2|  foo", "2|c3d4|  bar"]

Editing

exhash(text, cmds) takes the text and a required list of command strings (use [] for no-op). For a/i/c commands, lines after the command are the text block (no . terminator needed):

addr = lnhash(1, "foo")  # "1|a1b2|"
res = exhash(text, [f"{addr}s/foo/baz/"])
print(res.text())      # "baz\nbar"
print(res.modified)    # [1]

# Multiple commands
a1, a2 = lnhash(1, "foo"), lnhash(2, "bar")
res = exhash(text, [f"{a1}s/foo/FOO/", f"{a2}s/bar/BAR/"])

# Append multiline text (no dot terminator)
res = exhash(text, [f"{addr}a\nnew line 1\nnew line 2"])

EditResult

  • .lines — list of output lines
  • .hashes — lnhash for each output line
  • .modified — 1-based line numbers of modified/added lines
  • .deleted — 1-based line numbers of removed lines (in original)
  • .text() — joined output
  • .view() — output in lnhash format
  • repr() — shows only modified lines in lnhash format

Tests

cargo test && pytest -q

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

exhash-0.1.3.tar.gz (22.5 kB view details)

Uploaded Source

Built Distributions

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

exhash-0.1.3-cp313-cp313-manylinux_2_34_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

exhash-0.1.3-cp313-cp313-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

exhash-0.1.3-cp312-cp312-manylinux_2_34_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

exhash-0.1.3-cp312-cp312-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

exhash-0.1.3-cp311-cp311-manylinux_2_34_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

exhash-0.1.3-cp311-cp311-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

exhash-0.1.3-cp310-cp310-manylinux_2_34_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

exhash-0.1.3-cp310-cp310-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file exhash-0.1.3.tar.gz.

File metadata

  • Download URL: exhash-0.1.3.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for exhash-0.1.3.tar.gz
Algorithm Hash digest
SHA256 2bb9ee0fb6a9e0105c7784ed2e04e2a0891404205f3251224b8182bdc1520167
MD5 f9456d43ccf8e1ae568d40e540c06fe2
BLAKE2b-256 75ad89dd673728a064d7e3e0ba9170eb4089a39ddff51bed4b60faf72edb1406

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.1.3.tar.gz:

Publisher: ci.yml on AnswerDotAI/exhash

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exhash-0.1.3-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for exhash-0.1.3-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a02f8889dec81354346bf5ecc9b167471ecb71eb691fe82008d88ff2d91e33a5
MD5 65334f371bbc414ba6e75a47d5f9572c
BLAKE2b-256 8683c30fbc54b89c5200634369e598648ed47bfe0267298366e6c412e9954d7b

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.1.3-cp313-cp313-manylinux_2_34_x86_64.whl:

Publisher: ci.yml on AnswerDotAI/exhash

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exhash-0.1.3-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for exhash-0.1.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d91f0f0812fb79ef9bad61afe92a70943d1f1731242c12a81f6e7f75ec6e1bc1
MD5 02d1270f89f9dd134675a8562b5583c5
BLAKE2b-256 d64c0bdc7395328be54908054a635ae00798c30aa9430fbd3445e856b7a75145

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.1.3-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: ci.yml on AnswerDotAI/exhash

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exhash-0.1.3-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for exhash-0.1.3-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 eb8de4ff5c118e34472042faf0caf43640e612f61464786311f22b2fe5236d23
MD5 9047ae28c4e18eeac53b614618f0bdcf
BLAKE2b-256 90af16737b4ab9c2f4cd7a2d5ce0b207b10a1a83bbdec6886f6d6152399062d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.1.3-cp312-cp312-manylinux_2_34_x86_64.whl:

Publisher: ci.yml on AnswerDotAI/exhash

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exhash-0.1.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for exhash-0.1.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f4559238b61846c787d8a5369fcb2eb47644fd2939203168d1e2937c0888fc57
MD5 137ed128933d62cb1d160e34c914c980
BLAKE2b-256 4d05045ff2508e98daebe45abfe1a722a44820638890a06cfc5a934ce8c9fd05

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.1.3-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: ci.yml on AnswerDotAI/exhash

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exhash-0.1.3-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for exhash-0.1.3-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c97918693ed62982cfdf7c31bc6b39e8f547ad8c0abf9e490dd05b6eff62c77c
MD5 88a2693527c43936315da8fb9da9089a
BLAKE2b-256 f17bf60c96f40d133df4156190ba1d7469ae1fa6054fdf9fa57d93e71595cde1

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.1.3-cp311-cp311-manylinux_2_34_x86_64.whl:

Publisher: ci.yml on AnswerDotAI/exhash

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exhash-0.1.3-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for exhash-0.1.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 70a2a7d408cf944c0c675c2398c5248d64aa2814c0bbd776ff0fb4a49bf1f085
MD5 b7858af6f9340d3e51d7da67e0fe61ab
BLAKE2b-256 e2a3c06d61f4fc1164023b39c3ce0a782f4517a75b177f0dcef5b10f1046c105

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.1.3-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: ci.yml on AnswerDotAI/exhash

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exhash-0.1.3-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for exhash-0.1.3-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 37da3524e43de5d97a639ad86a424f169ab7625391c05024a0895b6954fa0e38
MD5 c9c44dbbfe5f19536e5944520ff3676e
BLAKE2b-256 947937807220ebc1d1c648162ca900b1f2658b25d288e17f2939a1fbd7f7dc7a

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.1.3-cp310-cp310-manylinux_2_34_x86_64.whl:

Publisher: ci.yml on AnswerDotAI/exhash

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exhash-0.1.3-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for exhash-0.1.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2d651d0648677f43c67b49ac90c9d5b077ac46fe8b60db18fce9d788216a9a4c
MD5 2f7f97dcec94b462b7f0bcffcf57a64b
BLAKE2b-256 d054943eb51f74419e2c35719a30b36a4801dbe145e369e61299c7f19289dd18

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.1.3-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: ci.yml on AnswerDotAI/exhash

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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