rubber-ducky 1.5.0__py3-none-any.whl → 1.5.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ducky/crumb.py +84 -0
- ducky/ducky.py +188 -492
- rubber_ducky-1.5.1.dist-info/METADATA +198 -0
- rubber_ducky-1.5.1.dist-info/RECORD +13 -0
- {rubber_ducky-1.5.0.dist-info → rubber_ducky-1.5.1.dist-info}/top_level.txt +0 -1
- crumbs/disk-usage/disk-usage.sh +0 -12
- crumbs/disk-usage/info.txt +0 -3
- crumbs/git-log/git-log.sh +0 -24
- crumbs/git-log/info.txt +0 -3
- crumbs/git-status/git-status.sh +0 -21
- crumbs/git-status/info.txt +0 -3
- crumbs/process-list/info.txt +0 -3
- crumbs/process-list/process-list.sh +0 -20
- crumbs/recent-files/info.txt +0 -3
- crumbs/recent-files/recent-files.sh +0 -13
- crumbs/system-health/info.txt +0 -3
- crumbs/system-health/system-health.sh +0 -58
- rubber_ducky-1.5.0.dist-info/METADATA +0 -210
- rubber_ducky-1.5.0.dist-info/RECORD +0 -24
- {rubber_ducky-1.5.0.dist-info → rubber_ducky-1.5.1.dist-info}/WHEEL +0 -0
- {rubber_ducky-1.5.0.dist-info → rubber_ducky-1.5.1.dist-info}/entry_points.txt +0 -0
- {rubber_ducky-1.5.0.dist-info → rubber_ducky-1.5.1.dist-info}/licenses/LICENSE +0 -0
ducky/crumb.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from datetime import UTC, datetime
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Dict, Any, Optional
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class CrumbManager:
|
|
8
|
+
"""Manages crumb storage for command shortcuts."""
|
|
9
|
+
|
|
10
|
+
def __init__(self, config_dir: Optional[Path] = None):
|
|
11
|
+
if config_dir is None:
|
|
12
|
+
config_dir = Path.home() / ".ducky"
|
|
13
|
+
self.config_dir = config_dir
|
|
14
|
+
self.crumbs_file = self.config_dir / "crumbs.json"
|
|
15
|
+
self.config_dir.mkdir(parents=True, exist_ok=True)
|
|
16
|
+
|
|
17
|
+
def load_crumbs(self) -> Dict[str, Any]:
|
|
18
|
+
"""Load crumbs from JSON file, returning empty dict if not found."""
|
|
19
|
+
if not self.crumbs_file.exists():
|
|
20
|
+
return {}
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
with open(self.crumbs_file, "r") as f:
|
|
24
|
+
return json.load(f)
|
|
25
|
+
except (json.JSONDecodeError, IOError):
|
|
26
|
+
return {}
|
|
27
|
+
|
|
28
|
+
def save_crumbs(self, crumbs: Dict[str, Any]) -> None:
|
|
29
|
+
"""Save crumbs to JSON file."""
|
|
30
|
+
try:
|
|
31
|
+
with open(self.crumbs_file, "w") as f:
|
|
32
|
+
json.dump(crumbs, f, indent=2)
|
|
33
|
+
except IOError as e:
|
|
34
|
+
print(f"Warning: Could not save crumbs: {e}")
|
|
35
|
+
|
|
36
|
+
def save_crumb(
|
|
37
|
+
self,
|
|
38
|
+
name: str,
|
|
39
|
+
prompt: str,
|
|
40
|
+
response: str,
|
|
41
|
+
command: str,
|
|
42
|
+
) -> None:
|
|
43
|
+
"""Add or update a crumb."""
|
|
44
|
+
crumbs = self.load_crumbs()
|
|
45
|
+
crumbs[name] = {
|
|
46
|
+
"prompt": prompt,
|
|
47
|
+
"response": response,
|
|
48
|
+
"command": command,
|
|
49
|
+
"explanation": "",
|
|
50
|
+
"created_at": datetime.now(UTC).isoformat(),
|
|
51
|
+
}
|
|
52
|
+
self.save_crumbs(crumbs)
|
|
53
|
+
|
|
54
|
+
def get_crumb(self, name: str) -> Optional[Dict[str, Any]]:
|
|
55
|
+
"""Retrieve a crumb by name."""
|
|
56
|
+
crumbs = self.load_crumbs()
|
|
57
|
+
return crumbs.get(name)
|
|
58
|
+
|
|
59
|
+
def list_crumbs(self) -> Dict[str, Any]:
|
|
60
|
+
"""Return all crumbs."""
|
|
61
|
+
return self.load_crumbs()
|
|
62
|
+
|
|
63
|
+
def delete_crumb(self, name: str) -> bool:
|
|
64
|
+
"""Remove a crumb. Returns True if deleted, False if not found."""
|
|
65
|
+
crumbs = self.load_crumbs()
|
|
66
|
+
if name in crumbs:
|
|
67
|
+
del crumbs[name]
|
|
68
|
+
self.save_crumbs(crumbs)
|
|
69
|
+
return True
|
|
70
|
+
return False
|
|
71
|
+
|
|
72
|
+
def update_explanation(self, name: str, explanation: str) -> bool:
|
|
73
|
+
"""Update explanation for a crumb. Returns True if updated, False if not found."""
|
|
74
|
+
crumbs = self.load_crumbs()
|
|
75
|
+
if name in crumbs:
|
|
76
|
+
crumbs[name]["explanation"] = explanation
|
|
77
|
+
self.save_crumbs(crumbs)
|
|
78
|
+
return True
|
|
79
|
+
return False
|
|
80
|
+
|
|
81
|
+
def has_crumb(self, name: str) -> bool:
|
|
82
|
+
"""Check if a crumb exists."""
|
|
83
|
+
crumbs = self.load_crumbs()
|
|
84
|
+
return name in crumbs
|