Repository navigation
fix: the basics, verified in a real shell, and release 0.5.2 #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9aa08a8
f35d354
4fa6a9f
f12ef2a
5f918c0
c2ddba9
c19e2cd
96451dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| """mem — your shell history, understood.""" | ||
|
|
||
| __version__ = "0.5.1" | ||
| __version__ = "0.5.2" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| """Text rules shared by both output surfaces, the CLI and the Ctrl+R finder. | ||
|
|
||
| Standard library only: the finder imports it before Rich is loaded. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
|
|
||
| def printable(text: str) -> str: | ||
| """Replace every character a terminal would act on, rather than show, with ``?``. | ||
|
|
||
| History is untrusted input — whatever somebody pasted into a shell — and a | ||
| stray escape sequence repaints the screen, sets a colour that bleeds into | ||
| every later row, or rewrites the window title, purely by being listed. | ||
| """ | ||
| return "".join(ch if ch.isprintable() or ch == " " else "?" for ch in text) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| from __future__ import annotations | ||
|
|
||
| import math | ||
| import os | ||
| from collections.abc import Sequence | ||
|
|
||
| from mem import picks | ||
|
|
@@ -145,6 +146,42 @@ def matches(command: str, query_terms: Sequence[str]) -> bool: | |
| return all(term in lowered for term in query_terms) | ||
|
|
||
|
|
||
| # --- what counts as history -------------------------------------------------- | ||
| # | ||
| # Capture, storage, the finder and import all decide what a command is, and the | ||
| # finder cannot import Pydantic, so the rule lives here beside `matches`. | ||
|
|
||
|
|
||
| def canonical(command: str) -> str | None: | ||
| """The command as history stores and compares it, or None if it is not history. | ||
|
|
||
| Surrounding whitespace is dropped, so ``ls`` and ``ls `` are one command. | ||
| mem's own invocations are not history: recording them made a repeated search | ||
| answer itself, and wrote ``mem forget SECRET`` back to disk as it deleted it. | ||
| """ | ||
| command = command.strip() | ||
| if not command or _runs_mem(command): | ||
| return None | ||
| return command | ||
|
|
||
|
|
||
| def repo_name(repo: str | None) -> str: | ||
| """How listings show a repo: its directory name, or ``global``.""" | ||
| if not repo: | ||
| return "global" | ||
| return os.path.basename(repo.rstrip("/")) or repo | ||
|
|
||
|
|
||
| def _runs_mem(command: str) -> bool: | ||
| """True when the first word, after any NAME=value prefixes, is mem.""" | ||
| for word in command.split(): | ||
| name, equals, _ = word.partition("=") | ||
| if equals and name.isidentifier(): | ||
| continue | ||
| return os.path.basename(word) == "mem" | ||
|
Comment on lines
+177
to
+181
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When mem is invoked through a shell wrapper or later in a compound command—such as Useful? React with 👍 / 👎. |
||
| return False | ||
|
|
||
|
|
||
| def score( | ||
| command: str, | ||
| ts: int | float, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For users upgrading from 0.5.1, persisted work sessions can already contain
mem ...commands, butread_all_sessions()does not applyranking.canonical()and this loop still renders every stored command and subsequently offers it for replay. Thusmem sessioncontinues to list legacy self-invocations even though command-history readers now hide them; session commands and summaries need equivalent normalization.Useful? React with 👍 / 👎.