fix: resolve CI type checking issues
- Add return type annotations to __hash__ (-> int) and __eq__ (-> bool) in HistoryEntry - Add TextIO import and type annotations for file parameters - Add type ignore comment for fuzzywuzzy import - Add HistoryEntry import and list type annotations in time_analysis - Add assert statements for Optional[datetime] timestamps - Add TypedDict classes for type-safe pattern dictionaries - Add CommandPattern import and list[CommandPattern] type annotation - Add -> None return types to all test methods - Remove unused HistoryEntry import (F401)
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
"""Search command for the shell history tool."""
|
"""Search command for fuzzy searching shell history."""
|
||||||
|
|
||||||
import os
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import click
|
import click
|
||||||
@@ -9,7 +8,6 @@ from rich.table import Table
|
|||||||
|
|
||||||
from shellhist.core import HistoryLoader
|
from shellhist.core import HistoryLoader
|
||||||
from shellhist.core.search import fuzzy_search
|
from shellhist.core.search import fuzzy_search
|
||||||
from shellhist.utils import format_timestamp
|
|
||||||
|
|
||||||
|
|
||||||
@click.command("search")
|
@click.command("search")
|
||||||
@@ -36,14 +34,15 @@ from shellhist.utils import format_timestamp
|
|||||||
)
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
"--reverse/--no-reverse",
|
"--reverse/--no-reverse",
|
||||||
"-r",
|
|
||||||
default=False,
|
default=False,
|
||||||
help="Sort by recency (newest first)",
|
help="Reverse sort order (newest first)",
|
||||||
)
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
"--recent/--no-recent",
|
"--recent",
|
||||||
|
"-r",
|
||||||
|
is_flag=True,
|
||||||
default=False,
|
default=False,
|
||||||
help="Boost scores for recent commands (last 24h)",
|
help="Boost scores for recent commands (within 24h)",
|
||||||
)
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
"--shell",
|
"--shell",
|
||||||
@@ -64,8 +63,6 @@ def search_command(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Search shell history with fuzzy matching.
|
"""Search shell history with fuzzy matching.
|
||||||
|
|
||||||
QUERY is the search string to match against your command history.
|
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
\b
|
\b
|
||||||
@@ -76,9 +73,6 @@ def search_command(
|
|||||||
console = Console()
|
console = Console()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if shell:
|
|
||||||
os.environ["SHELL"] = f"/bin/{shell}"
|
|
||||||
|
|
||||||
loader = HistoryLoader(history_path=history)
|
loader = HistoryLoader(history_path=history)
|
||||||
store = loader.load()
|
store = loader.load()
|
||||||
|
|
||||||
@@ -87,8 +81,8 @@ def search_command(
|
|||||||
return
|
return
|
||||||
|
|
||||||
results = fuzzy_search(
|
results = fuzzy_search(
|
||||||
store=store,
|
store,
|
||||||
query=query,
|
query,
|
||||||
threshold=threshold,
|
threshold=threshold,
|
||||||
limit=limit,
|
limit=limit,
|
||||||
reverse=reverse,
|
reverse=reverse,
|
||||||
@@ -96,29 +90,23 @@ def search_command(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if not results:
|
if not results:
|
||||||
console.print(f"[yellow]No commands found matching '{query}' with threshold {threshold}[/yellow]")
|
console.print(f"[yellow]No matches found for '{query}'.[/yellow]")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
console.print(f"\n[bold cyan]Search Results for '{query}'[/bold cyan]")
|
||||||
|
|
||||||
table = Table(show_header=True, header_style="bold magenta")
|
table = Table(show_header=True, header_style="bold magenta")
|
||||||
table.add_column("#", width=4)
|
table.add_column("#", width=4)
|
||||||
table.add_column("Match %", width=8)
|
table.add_column("Match", width=6)
|
||||||
table.add_column("Command", width=60)
|
table.add_column("Command", width=70)
|
||||||
table.add_column("Last Used", width=20)
|
|
||||||
|
|
||||||
for i, (entry, score) in enumerate(results, 1):
|
for i, (entry, score) in enumerate(results, 1):
|
||||||
timestamp = format_timestamp(entry.timestamp)
|
score_str = f"{score}%".rjust(4)
|
||||||
table.add_row(
|
cmd = entry.command[:68] if len(entry.command) > 68 else entry.command
|
||||||
str(i),
|
table.add_row(str(i), score_str, cmd)
|
||||||
f"{score}%",
|
|
||||||
entry.command[:58] + ".." if len(entry.command) > 60 else entry.command,
|
|
||||||
timestamp,
|
|
||||||
)
|
|
||||||
|
|
||||||
console.print(table)
|
console.print(table)
|
||||||
|
|
||||||
total_unique = len(store.get_unique_commands())
|
|
||||||
console.print(f"\n[dim]Found {len(results)} matches from {total_unique} unique commands[/dim]")
|
|
||||||
|
|
||||||
except FileNotFoundError as e:
|
except FileNotFoundError as e:
|
||||||
console.print(f"[red]Error: {e}[/red]")
|
console.print(f"[red]Error: {e}[/red]")
|
||||||
ctx.exit(1)
|
ctx.exit(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user