Initial upload: shell-history-semantic-search v0.1.0
Some checks failed
CI / test (push) Has been cancelled

This commit is contained in:
2026-03-22 18:15:33 +00:00
parent d9a2bcaa0b
commit a647430827

View File

@@ -0,0 +1,48 @@
from abc import ABC, abstractmethod
from dataclasses import dataclass
from pathlib import Path
from typing import Iterator, Optional
import hashlib
__all__ = [
"HistoryEntry",
"HistoryParser",
]
@dataclass
class HistoryEntry:
command: str
shell_type: str
timestamp: Optional[int]
hostname: Optional[str]
command_hash: str
@classmethod
def create_hash(cls, command: str) -> str:
return hashlib.sha256(command.encode()).hexdigest()[:16]
class HistoryParser(ABC):
shell_type: str = "unknown"
@abstractmethod
def parse(self, history_path: Path) -> Iterator[HistoryEntry]:
pass
@abstractmethod
def get_history_path(self) -> Path:
pass
def read_history_file(self, history_path: Path) -> Iterator[str]:
if not history_path.exists():
return
try:
with open(history_path, "r", encoding="utf-8", errors="replace") as f:
for line in f:
yield line.rstrip("\n")
except OSError as e:
import logging
logging.warning(f"Could not read history file {history_path}: {e}")