command-manager-util 0.1.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,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 Sahaj Pratap Singh
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,50 @@
1
+ Metadata-Version: 2.1
2
+ Name: command-manager-util
3
+ Version: 0.1.0
4
+ Summary: This manages all the usesful commands at one place
5
+ Home-page: https://github.com/Sahaj001/Script-Manager
6
+ Author: Sahaj Pratap Singh
7
+ License: Apache 2.0
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.6
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+
15
+ # Script Manager
16
+
17
+ ## Overview
18
+
19
+ The **Script Manager** is a tool designed to help users organize and execute commands with ease. It allows you to create and manage categories, add or remove commands within those categories, and execute them directly. This tool is ideal for those who work with long or complex commands and prefer not to remember them or store them in multiple places.
20
+
21
+ ## Features
22
+
23
+ - **Category Management**: Create and remove categories to organize your commands.
24
+ - **Command Management**: Add and remove commands within categories as needed.
25
+ - **Command Execution**: Select and run commands directly from the tool.
26
+ - **No External Storage**: All commands and categories are stored within the tool itself.
27
+ - **Easy to Use**: A simple interface for easy command management.
28
+
29
+ ## Installation
30
+
31
+ Follow the installation steps in the repository to set up the Script Manager on your system.
32
+
33
+ ## Usage
34
+
35
+ Once installed, you can use the Script Manager to manage your commands.
36
+
37
+ - Create and organize categories.
38
+ - Add or remove commands within those categories.
39
+ - Execute commands directly with a simple interface.
40
+
41
+ ## Benefits
42
+
43
+ - **Simplified Workflow**: Easily manage and execute commands without needing to remember them.
44
+ - **No External Files Needed**: Everything stays within the tool, making it easy to maintain and backup.
45
+ - **Time-Saving**: Run your commands with a few simple actions, eliminating the need for manual typing.
46
+ - **Minimal Setup**: Get started quickly with no complex configurations.
47
+
48
+ ## Contributing
49
+
50
+ Feel free to fork the repository and contribute to the project.
@@ -0,0 +1,36 @@
1
+ # Script Manager
2
+
3
+ ## Overview
4
+
5
+ The **Script Manager** is a tool designed to help users organize and execute commands with ease. It allows you to create and manage categories, add or remove commands within those categories, and execute them directly. This tool is ideal for those who work with long or complex commands and prefer not to remember them or store them in multiple places.
6
+
7
+ ## Features
8
+
9
+ - **Category Management**: Create and remove categories to organize your commands.
10
+ - **Command Management**: Add and remove commands within categories as needed.
11
+ - **Command Execution**: Select and run commands directly from the tool.
12
+ - **No External Storage**: All commands and categories are stored within the tool itself.
13
+ - **Easy to Use**: A simple interface for easy command management.
14
+
15
+ ## Installation
16
+
17
+ Follow the installation steps in the repository to set up the Script Manager on your system.
18
+
19
+ ## Usage
20
+
21
+ Once installed, you can use the Script Manager to manage your commands.
22
+
23
+ - Create and organize categories.
24
+ - Add or remove commands within those categories.
25
+ - Execute commands directly with a simple interface.
26
+
27
+ ## Benefits
28
+
29
+ - **Simplified Workflow**: Easily manage and execute commands without needing to remember them.
30
+ - **No External Files Needed**: Everything stays within the tool, making it easy to maintain and backup.
31
+ - **Time-Saving**: Run your commands with a few simple actions, eliminating the need for manual typing.
32
+ - **Minimal Setup**: Get started quickly with no complex configurations.
33
+
34
+ ## Contributing
35
+
36
+ Feel free to fork the repository and contribute to the project.
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,32 @@
1
+ from setuptools import setup
2
+
3
+
4
+ def read_file():
5
+ with open("README.md", "r", encoding='utf-8') as f:
6
+ content = f.read()
7
+ return content
8
+
9
+
10
+ setup(
11
+ name="command-manager-util",
12
+ version="0.1.0",
13
+ description="This manages all the usesful commands at one place",
14
+ long_description=read_file(),
15
+ long_description_content_type="text/markdown",
16
+ author="Sahaj Pratap Singh",
17
+ url="https://github.com/Sahaj001/Script-Manager",
18
+ classifiers=[
19
+ "Programming Language :: Python :: 3",
20
+ "License :: OSI Approved :: Apache Software License",
21
+ "Operating System :: OS Independent",
22
+ ],
23
+ install_requires=[],
24
+ python_requires='>=3.6',
25
+ include_package_data=True,
26
+ entry_points={
27
+ 'console_scripts': [
28
+ 'scm=main:start', # Example command
29
+ ],
30
+ },
31
+ license="Apache 2.0", # Specify Apache 2.0 License
32
+ )
@@ -0,0 +1,50 @@
1
+ Metadata-Version: 2.1
2
+ Name: command-manager-util
3
+ Version: 0.1.0
4
+ Summary: This manages all the usesful commands at one place
5
+ Home-page: https://github.com/Sahaj001/Script-Manager
6
+ Author: Sahaj Pratap Singh
7
+ License: Apache 2.0
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.6
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+
15
+ # Script Manager
16
+
17
+ ## Overview
18
+
19
+ The **Script Manager** is a tool designed to help users organize and execute commands with ease. It allows you to create and manage categories, add or remove commands within those categories, and execute them directly. This tool is ideal for those who work with long or complex commands and prefer not to remember them or store them in multiple places.
20
+
21
+ ## Features
22
+
23
+ - **Category Management**: Create and remove categories to organize your commands.
24
+ - **Command Management**: Add and remove commands within categories as needed.
25
+ - **Command Execution**: Select and run commands directly from the tool.
26
+ - **No External Storage**: All commands and categories are stored within the tool itself.
27
+ - **Easy to Use**: A simple interface for easy command management.
28
+
29
+ ## Installation
30
+
31
+ Follow the installation steps in the repository to set up the Script Manager on your system.
32
+
33
+ ## Usage
34
+
35
+ Once installed, you can use the Script Manager to manage your commands.
36
+
37
+ - Create and organize categories.
38
+ - Add or remove commands within those categories.
39
+ - Execute commands directly with a simple interface.
40
+
41
+ ## Benefits
42
+
43
+ - **Simplified Workflow**: Easily manage and execute commands without needing to remember them.
44
+ - **No External Files Needed**: Everything stays within the tool, making it easy to maintain and backup.
45
+ - **Time-Saving**: Run your commands with a few simple actions, eliminating the need for manual typing.
46
+ - **Minimal Setup**: Get started quickly with no complex configurations.
47
+
48
+ ## Contributing
49
+
50
+ Feel free to fork the repository and contribute to the project.
@@ -0,0 +1,9 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ src/command_manager_util.egg-info/PKG-INFO
5
+ src/command_manager_util.egg-info/SOURCES.txt
6
+ src/command_manager_util.egg-info/dependency_links.txt
7
+ src/command_manager_util.egg-info/entry_points.txt
8
+ src/command_manager_util.egg-info/top_level.txt
9
+ src/main/__init__.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ scm = main:start
@@ -0,0 +1,248 @@
1
+ # main.py
2
+
3
+ import os
4
+ import curses
5
+ import subprocess
6
+ import sys
7
+
8
+ script_dir = os.path.dirname(os.path.realpath(__file__))
9
+ CATEGORY_DIR = os.path.join(script_dir, 'categories')
10
+
11
+
12
+ def create_category_directory():
13
+ """Create the categories directory if it doesn't exist."""
14
+ if not os.path.exists(CATEGORY_DIR):
15
+ os.makedirs(CATEGORY_DIR)
16
+
17
+
18
+ def add_category(category_name):
19
+ """Add a category by creating a file with the category name."""
20
+ file_path = os.path.join(CATEGORY_DIR, f"{category_name}.txt")
21
+ with open(file_path, 'w', encoding='utf-8') as file:
22
+ file.write("") # Optional: add initial content
23
+ return category_name
24
+
25
+
26
+ def remove_category(category_name):
27
+ """Remove a category by deleting the file with the category name."""
28
+ file_path = os.path.join(CATEGORY_DIR, f"{category_name}.txt")
29
+ if os.path.exists(file_path):
30
+ os.remove(file_path)
31
+ return category_name
32
+ return category_name
33
+
34
+
35
+ def get_categories():
36
+ """Retrieve the list of categories from the directory."""
37
+ return [f[:-4] for f in os.listdir(CATEGORY_DIR) if f.endswith('.txt')]
38
+
39
+
40
+ def add_line(filename, new_line):
41
+ with open(filename, 'a', encoding='utf-8') as file:
42
+ file.write(new_line + '\n') # Append new line with a newline character
43
+
44
+
45
+ def remove_line(filename, line_number):
46
+ with open(filename, 'r', encoding='utf-8') as file:
47
+ lines = file.readlines()
48
+
49
+ # Check if the line number is valid
50
+ if 0 <= line_number <= len(lines):
51
+ del lines[line_number]
52
+
53
+ # Write back to the file without leaving any blank spaces
54
+ with open(filename, 'w', encoding='utf-8') as file:
55
+ file.writelines(lines)
56
+
57
+
58
+ def read_file_to_array(file_path):
59
+ try:
60
+ with open(file_path, 'r', encoding='utf-8') as file: # Open the file in read mode
61
+ lines = file.readlines() # Read all lines into a list
62
+ # Strip newline characters from each line
63
+ return [line.strip() for line in lines]
64
+ except FileNotFoundError as e:
65
+ print(f"The file {file_path} was not found: {e}")
66
+ return None
67
+
68
+
69
+ def execute_command(option):
70
+ stdscr = curses.initscr()
71
+
72
+ # Example command execution based on the selected option.
73
+ stdscr.addstr(f"You selected: {option}\n")
74
+ commands = read_file_to_array(os.path.join(CATEGORY_DIR, f"{option}.txt"))
75
+ display_menu(stdscr, commands, run_command, None)
76
+ stdscr.refresh()
77
+ stdscr.getch() # Wait for a key press to allow the user to see the message
78
+
79
+
80
+ def display_output(stdscr, output):
81
+ """Display command output in the curses window."""
82
+ stdscr.clear() # Clear the screen
83
+ for line in output:
84
+ stdscr(line + '\n')
85
+ # stdscr.addstr(line + '\n') # Add each line followed by a newline
86
+ stdscr.refresh() # Refresh to show the updated content
87
+ stdscr.getch() # Wait for a key press
88
+
89
+
90
+ def display_menu1(stdscr, options, selected):
91
+ stdscr.clear() # Clear the screen
92
+ stdscr.addstr(
93
+ "Select a command category (Use arrow keys and press Enter):\n\n")
94
+
95
+ for idx, option in enumerate(options):
96
+ if idx == selected:
97
+ # Highlight selected option
98
+ stdscr.addstr(f"> {option}\n", curses.A_REVERSE)
99
+ else:
100
+ stdscr.addstr(f" {option}\n")
101
+
102
+ stdscr.refresh() # Refresh the screen to show changes
103
+
104
+
105
+ def display_menu(stdscr, options, execute_function, types):
106
+ """
107
+ Display a menu using curses, allowing the user to navigate with arrow keys
108
+ and execute a command based on the selected option.
109
+
110
+ :param stdscr: The window object from curses.
111
+ :param options: A list of options to display in the menu.
112
+ :param execute_function: A function to execute when an option is selected.
113
+ """
114
+ selected = 0 # Track the currently selected option
115
+ num_options = len(options)
116
+
117
+ while True:
118
+ stdscr.clear() # Clear the screen for redrawing the menu
119
+ stdscr.addstr(
120
+ "Select an option (Use arrow keys and press Enter): \n\n")
121
+ for idx, option in enumerate(options):
122
+ if idx == selected:
123
+ # Highlight selected option
124
+ stdscr.addstr(f"> {option}\n", curses.A_REVERSE)
125
+ else:
126
+ stdscr.addstr(f" {option}\n")
127
+
128
+ stdscr.refresh() # Refresh to show the updated menu
129
+
130
+ key = stdscr.getch() # Wait for user input
131
+
132
+ if key == curses.KEY_UP: # Move up in the menu
133
+ selected = (selected - 1) % num_options
134
+ elif key == curses.KEY_DOWN: # Move down in the menu
135
+ selected = (selected + 1) % num_options
136
+ elif key in [curses.KEY_ENTER, 10, 13]: # Enter key
137
+ if types[0] == 'remove':
138
+ # Capture the output of the command
139
+ output = execute_function(options[selected])
140
+ return output
141
+ elif types[0] == 'remove_command':
142
+ execute_function(types[1], selected)
143
+ stdscr.refresh()
144
+ elif types[0] == 'add_command':
145
+ execute_function(types[1], types[2])
146
+ stdscr.refresh()
147
+ elif types[0] == 'run_command':
148
+ if selected < len(options) - 3:
149
+ # Run the command and wait for it to complete
150
+ run_command(options[selected])
151
+ elif selected == len(options) - 3: # Add Category option
152
+ stdscr.addstr("\nEnter the command to add: ")
153
+ stdscr.refresh()
154
+ curses.echo() # Enable echoing of user input
155
+ new_command = stdscr.getstr().decode(
156
+ 'utf-8').strip() # Get the new command to add
157
+ if new_command:
158
+ add_line(types[1], new_command)
159
+ stdscr.addstr(f"\\Command added\n: '{new_command}'\n")
160
+ stdscr.refresh()
161
+ # Remove Category option (second last)
162
+ elif selected == len(options) - 2:
163
+ stdscr.addstr("\nSelect a command to remove:\n")
164
+ stdscr.refresh()
165
+ curses.noecho() # Disable echoing for the category selection
166
+ cat = display_menu(
167
+ stdscr, options[:-3], remove_line, ['remove_command', types[1]])
168
+ stdscr.addstr(f"\nCategory '{cat}' removed!\n")
169
+ selected = selected - 1
170
+ stdscr.refresh()
171
+ elif selected == len(options) - 1: # Exit option
172
+ stdscr.addstr("\nExiting...\n")
173
+ stdscr.refresh()
174
+ return
175
+
176
+
177
+ def run_command(command):
178
+ try:
179
+ curses.endwin()
180
+ print("\n")
181
+ os.system(command)
182
+ print("\n")
183
+ # Pause for user to see output
184
+ os.system("read -p 'Press Enter to exit.'")
185
+ sys.exit()
186
+ except subprocess.CalledProcessError as e:
187
+ print(f"Command '{command}' failed with exit code {e.returncode}")
188
+ print("Error Output:")
189
+ print(e.stderr)
190
+ #
191
+
192
+
193
+ def main(stdscr):
194
+ create_category_directory() # Ensure the category directory exists
195
+ menu_options = ["Add Category", "Remove Category", "Exit"] # Menu options
196
+ command_option = ["Add Command", "Remove Command", "Back"]
197
+ selected = 0
198
+
199
+ while True:
200
+ # Fetch categories to display in the menu
201
+ categories = get_categories()
202
+ options = categories + menu_options # Update menu options
203
+
204
+ display_menu1(stdscr, options, selected)
205
+
206
+ key = stdscr.getch() # Wait for user input
207
+
208
+ if key == curses.KEY_UP:
209
+ selected = (selected - 1) % len(options) # Move up in the menu
210
+ elif key == curses.KEY_DOWN:
211
+ selected = (selected + 1) % len(options) # Move down in the menu
212
+ elif key == curses.KEY_ENTER or key in [10, 13]: # Enter key
213
+ if selected < len(options) - 3:
214
+ option = options[selected]
215
+ path = os.path.join(CATEGORY_DIR, f"{option}.txt")
216
+ commands = read_file_to_array(path)
217
+ commands += command_option
218
+ display_menu(
219
+ stdscr, commands, run_command, [
220
+ 'run_command', path])
221
+ stdscr.refresh()
222
+ elif selected == len(options) - 3: # Add Category option
223
+ stdscr.addstr("\nEnter the name of the new category: ")
224
+ stdscr.refresh()
225
+ curses.echo() # Enable echoing of user input
226
+ category_name = stdscr.getstr().decode('utf-8').strip() # Get the category name
227
+ if category_name:
228
+ add_category(category_name) # Add the category
229
+ stdscr.addstr(f"\nCategory '{category_name}' added!\n")
230
+ stdscr.refresh()
231
+ # Remove Category option (second last)
232
+ elif selected == len(options) - 2:
233
+ stdscr.addstr("\nSelect a category to remove:\n")
234
+ stdscr.refresh()
235
+ curses.noecho() # Disable echoing for the category selection
236
+ cat = display_menu(
237
+ stdscr, options[:-3], remove_category, ['remove'])
238
+ stdscr.addstr(f"\nCategory '{cat}' removed!\n")
239
+ selected = selected - 1
240
+ stdscr.refresh()
241
+ elif selected == len(options) - 1: # Exit option
242
+ stdscr.addstr("\nExiting...\n")
243
+ stdscr.refresh() # Refresh to show the exit message
244
+ return # Exit the main function, terminating the program
245
+
246
+
247
+ def start():
248
+ curses.wrapper(main)