sentence-menu 1.0.0__tar.gz

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.
@@ -0,0 +1,49 @@
1
+ Metadata-Version: 2.4
2
+ Name: sentence-menu
3
+ Version: 1.0.0
4
+ Summary: A command-line fuzzy menu keyed based on full sentences
5
+ Author-email: "@readwithai" <talwrii@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/talwrii/sentence-menu
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Environment :: Console
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Utilities
14
+ Requires-Python: >=3.8
15
+ Description-Content-Type: text/markdown
16
+
17
+ # sentence-menu
18
+ A command-line fuzzy command-menu keyed with full sentences which runs command.
19
+
20
+ This is unreviewed AI-generated code. It will likely become more reviewed if anyone uses it.
21
+
22
+ ## Motivation
23
+ I want to find snippets to do things based on what I have done before. I use the snippet framework I wrote, zshnip, but sometimes I want to be lazy and use full sentences.
24
+
25
+ ## Alternatives
26
+ `navi` is a menuing system with fuzzy search and tags which focuses on commands to run, but focuses on cheat sheet files (supporting several). I dislike editing files and if I have to edit a file to add a command I often won't do it.
27
+
28
+ `fzf` provides a fuzzy menu but is more a command line tool to build thigns than a complete solution.
29
+
30
+ `rofi` is another fuzzy menuing system designed for gui environments. It can automatically search your path for commands. Most desktop environments, like KDE or Gnome, provide some sort of fuzzy search.
31
+
32
+ I also sometimes use Obsidian to keep track of commands related to a topic. This can work well, but not for things I want to run quickly. I have a shortcut to popup Obsidian. You could use emacs org-mode for similar purposes.
33
+
34
+ You could also use an LLM.
35
+
36
+ ## Installation
37
+ pipx install sentence-menu
38
+
39
+ ## Usage
40
+ Interactively add a command: `sentence-menu add`
41
+
42
+ Interactively edit an entry: `sentence-menu edit`
43
+
44
+ Run a command: `sentence-menu`
45
+
46
+ Print a command to standard out: `sentence-menu echo`
47
+
48
+ ## About me
49
+ I am @readwithai. I make lots of small tools like this. I also make tools for reading with and without AI.
@@ -0,0 +1,33 @@
1
+ # sentence-menu
2
+ A command-line fuzzy command-menu keyed with full sentences which runs command.
3
+
4
+ This is unreviewed AI-generated code. It will likely become more reviewed if anyone uses it.
5
+
6
+ ## Motivation
7
+ I want to find snippets to do things based on what I have done before. I use the snippet framework I wrote, zshnip, but sometimes I want to be lazy and use full sentences.
8
+
9
+ ## Alternatives
10
+ `navi` is a menuing system with fuzzy search and tags which focuses on commands to run, but focuses on cheat sheet files (supporting several). I dislike editing files and if I have to edit a file to add a command I often won't do it.
11
+
12
+ `fzf` provides a fuzzy menu but is more a command line tool to build thigns than a complete solution.
13
+
14
+ `rofi` is another fuzzy menuing system designed for gui environments. It can automatically search your path for commands. Most desktop environments, like KDE or Gnome, provide some sort of fuzzy search.
15
+
16
+ I also sometimes use Obsidian to keep track of commands related to a topic. This can work well, but not for things I want to run quickly. I have a shortcut to popup Obsidian. You could use emacs org-mode for similar purposes.
17
+
18
+ You could also use an LLM.
19
+
20
+ ## Installation
21
+ pipx install sentence-menu
22
+
23
+ ## Usage
24
+ Interactively add a command: `sentence-menu add`
25
+
26
+ Interactively edit an entry: `sentence-menu edit`
27
+
28
+ Run a command: `sentence-menu`
29
+
30
+ Print a command to standard out: `sentence-menu echo`
31
+
32
+ ## About me
33
+ I am @readwithai. I make lots of small tools like this. I also make tools for reading with and without AI.
@@ -0,0 +1,28 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "sentence-menu"
7
+ version = "1.0.0"
8
+ description = "A command-line fuzzy menu keyed based on full sentences"
9
+ readme = "README.md"
10
+ license = {text = "MIT"}
11
+ requires-python = ">=3.8"
12
+ authors = [
13
+ {name = "@readwithai", email = "talwrii@gmail.com"},
14
+ ]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Environment :: Console",
18
+ "Intended Audience :: Developers",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Programming Language :: Python :: 3",
21
+ "Topic :: Utilities",
22
+ ]
23
+
24
+ [project.scripts]
25
+ sentence-menu = "sentence_menu.main:main"
26
+
27
+ [project.urls]
28
+ Homepage = "https://github.com/talwrii/sentence-menu"
File without changes
@@ -0,0 +1,169 @@
1
+ """sentence-menu: A command-line fuzzy menu keyed based on full sentences."""
2
+
3
+ import argparse
4
+ import json
5
+ import os
6
+ import subprocess
7
+ import sys
8
+ from pathlib import Path
9
+
10
+
11
+ def get_store_path():
12
+ xdg = os.environ.get("XDG_DATA_HOME", os.path.expanduser("~/.local/share"))
13
+ path = Path(xdg) / "sentence-menu" / "commands.json"
14
+ path.parent.mkdir(parents=True, exist_ok=True)
15
+ return path
16
+
17
+
18
+ def load_entries():
19
+ path = get_store_path()
20
+ if not path.exists():
21
+ return []
22
+ with open(path) as f:
23
+ return json.load(f)
24
+
25
+
26
+ def save_entries(entries):
27
+ path = get_store_path()
28
+ with open(path, "w") as f:
29
+ json.dump(entries, f, indent=2)
30
+
31
+
32
+ def fzf_select(entries):
33
+ if not entries:
34
+ print("No entries yet. Use 'sentence-menu add' to add one.", file=sys.stderr)
35
+ sys.exit(1)
36
+
37
+ lines = [e["sentence"] for e in entries]
38
+ input_text = "\n".join(lines)
39
+
40
+ try:
41
+ result = subprocess.run(
42
+ ["fzf", "--height=40%", "--reverse", "--prompt= "],
43
+ input=input_text,
44
+ stdout=subprocess.PIPE,
45
+ text=True,
46
+ )
47
+ except FileNotFoundError:
48
+ print("fzf is required but not installed.", file=sys.stderr)
49
+ print("Install it: https://github.com/junegunn/fzf", file=sys.stderr)
50
+ sys.exit(1)
51
+
52
+ if result.returncode != 0:
53
+ sys.exit(1)
54
+
55
+ selected = result.stdout.strip()
56
+ for e in entries:
57
+ if e["sentence"] == selected:
58
+ return e
59
+ return None
60
+
61
+
62
+ def cmd_add():
63
+ sentence = input("Sentence: ").strip()
64
+ if not sentence:
65
+ print("Aborted.", file=sys.stderr)
66
+ sys.exit(1)
67
+
68
+ command = input("Command: ").strip()
69
+ if not command:
70
+ print("Aborted.", file=sys.stderr)
71
+ sys.exit(1)
72
+
73
+ entries = load_entries()
74
+ entries.append({"sentence": sentence, "command": command})
75
+ save_entries(entries)
76
+ print(f"Added: {sentence}")
77
+
78
+
79
+ def cmd_edit():
80
+ import tempfile
81
+
82
+ entries = load_entries()
83
+ entry = fzf_select(entries)
84
+ if not entry:
85
+ return
86
+
87
+ editor = os.environ.get("VISUAL") or os.environ.get("EDITOR", "vi")
88
+
89
+ with tempfile.NamedTemporaryFile(mode="w", suffix=".txt", delete=False) as f:
90
+ f.write(f"Sentence: {entry['sentence']}\n")
91
+ f.write(f"Command: {entry['command']}\n")
92
+ tmppath = f.name
93
+
94
+ try:
95
+ subprocess.run([editor, tmppath])
96
+
97
+ with open(tmppath) as f:
98
+ lines = f.readlines()
99
+
100
+ for line in lines:
101
+ if line.startswith("Sentence:"):
102
+ new_sentence = line[len("Sentence:"):].strip()
103
+ if new_sentence:
104
+ entry["sentence"] = new_sentence
105
+ elif line.startswith("Command:"):
106
+ new_command = line[len("Command:"):].strip()
107
+ if new_command:
108
+ entry["command"] = new_command
109
+
110
+ save_entries(entries)
111
+ print("Updated.")
112
+ finally:
113
+ os.unlink(tmppath)
114
+
115
+
116
+ def cmd_run():
117
+ entries = load_entries()
118
+ entry = fzf_select(entries)
119
+ if entry:
120
+ import time
121
+ print(f"$ {entry['command']}", file=sys.stderr)
122
+ time.sleep(0.1)
123
+ os.execvp("sh", ["sh", "-c", entry["command"]])
124
+
125
+
126
+ def cmd_echo():
127
+ entries = load_entries()
128
+ entry = fzf_select(entries)
129
+ if entry:
130
+ print(entry["command"])
131
+
132
+
133
+ def cmd_remove():
134
+ entries = load_entries()
135
+ entry = fzf_select(entries)
136
+ if entry:
137
+ entries.remove(entry)
138
+ save_entries(entries)
139
+ print(f"Removed: {entry['sentence']}")
140
+
141
+
142
+ def main():
143
+ parser = argparse.ArgumentParser(
144
+ prog="sentence-menu",
145
+ description="A command-line fuzzy menu keyed based on full sentences.",
146
+ )
147
+ subparsers = parser.add_subparsers(dest="command")
148
+
149
+ subparsers.add_parser("add", help="Interactively add a command")
150
+ subparsers.add_parser("edit", help="Interactively edit an entry")
151
+ subparsers.add_parser("echo", help="Print a command to stdout")
152
+ subparsers.add_parser("remove", help="Remove an entry")
153
+
154
+ args = parser.parse_args()
155
+
156
+ if args.command == "add":
157
+ cmd_add()
158
+ elif args.command == "edit":
159
+ cmd_edit()
160
+ elif args.command == "echo":
161
+ cmd_echo()
162
+ elif args.command == "remove":
163
+ cmd_remove()
164
+ else:
165
+ cmd_run()
166
+
167
+
168
+ if __name__ == "__main__":
169
+ main()
@@ -0,0 +1,49 @@
1
+ Metadata-Version: 2.4
2
+ Name: sentence-menu
3
+ Version: 1.0.0
4
+ Summary: A command-line fuzzy menu keyed based on full sentences
5
+ Author-email: "@readwithai" <talwrii@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/talwrii/sentence-menu
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Environment :: Console
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Utilities
14
+ Requires-Python: >=3.8
15
+ Description-Content-Type: text/markdown
16
+
17
+ # sentence-menu
18
+ A command-line fuzzy command-menu keyed with full sentences which runs command.
19
+
20
+ This is unreviewed AI-generated code. It will likely become more reviewed if anyone uses it.
21
+
22
+ ## Motivation
23
+ I want to find snippets to do things based on what I have done before. I use the snippet framework I wrote, zshnip, but sometimes I want to be lazy and use full sentences.
24
+
25
+ ## Alternatives
26
+ `navi` is a menuing system with fuzzy search and tags which focuses on commands to run, but focuses on cheat sheet files (supporting several). I dislike editing files and if I have to edit a file to add a command I often won't do it.
27
+
28
+ `fzf` provides a fuzzy menu but is more a command line tool to build thigns than a complete solution.
29
+
30
+ `rofi` is another fuzzy menuing system designed for gui environments. It can automatically search your path for commands. Most desktop environments, like KDE or Gnome, provide some sort of fuzzy search.
31
+
32
+ I also sometimes use Obsidian to keep track of commands related to a topic. This can work well, but not for things I want to run quickly. I have a shortcut to popup Obsidian. You could use emacs org-mode for similar purposes.
33
+
34
+ You could also use an LLM.
35
+
36
+ ## Installation
37
+ pipx install sentence-menu
38
+
39
+ ## Usage
40
+ Interactively add a command: `sentence-menu add`
41
+
42
+ Interactively edit an entry: `sentence-menu edit`
43
+
44
+ Run a command: `sentence-menu`
45
+
46
+ Print a command to standard out: `sentence-menu echo`
47
+
48
+ ## About me
49
+ I am @readwithai. I make lots of small tools like this. I also make tools for reading with and without AI.
@@ -0,0 +1,9 @@
1
+ README.md
2
+ pyproject.toml
3
+ sentence_menu/__init__.py
4
+ sentence_menu/main.py
5
+ sentence_menu.egg-info/PKG-INFO
6
+ sentence_menu.egg-info/SOURCES.txt
7
+ sentence_menu.egg-info/dependency_links.txt
8
+ sentence_menu.egg-info/entry_points.txt
9
+ sentence_menu.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ sentence-menu = sentence_menu.main:main
@@ -0,0 +1 @@
1
+ sentence_menu
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+