command-manager-util 0.1.1__tar.gz → 1.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,112 @@
1
+ Metadata-Version: 2.4
2
+ Name: command-manager-util
3
+ Version: 1.1.0
4
+ Summary: Manages useful commands in one place using fzf
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
+ Dynamic: author
15
+ Dynamic: classifier
16
+ Dynamic: description
17
+ Dynamic: description-content-type
18
+ Dynamic: home-page
19
+ Dynamic: license
20
+ Dynamic: license-file
21
+ Dynamic: requires-python
22
+ Dynamic: summary
23
+
24
+ [![Publish Python Package to PyPI](https://github.com/Sahaj001/Script-Manager/actions/workflows/publish.yml/badge.svg)](https://github.com/Sahaj001/Script-Manager/actions/workflows/publish.yml)
25
+
26
+ # Script-Command-Manager (SCM)
27
+ # 🚀 SCM Tool Guide
28
+
29
+ A streamlined command manager for your terminal workflows.
30
+
31
+ ## Overview
32
+
33
+ **SCM** is a high-performance CLI tool designed to catalog, manage, and execute complex shell commands through an intuitive fuzzy-finding interface. Built with Python and powered by `fzf`, it eliminates the need to remember arcane syntax or sift through endless history files.
34
+
35
+ ## Features
36
+ * **Fuzzy Search Navigation**: Instant filtering of categories and commands using `fzf`.
37
+ * **Hierarchical Management**: Organize commands into custom categories (e.g., Work, Dev, Personal).
38
+ * **In-App Administration**: Add or delete commands and entire categories directly from the interface.
39
+ * **Shell History Integration**: Commands executed via SCM can be injected into your shell history for easy access later.
40
+ * **Mac-Optimized Core**: Robust file I/O designed to handle macOS-specific shell environments and `sed/grep` variations.
41
+
42
+ ---
43
+
44
+ ## Installation
45
+
46
+ ### Prerequisites
47
+ 1. **Python**: 3.6 or higher.
48
+ 2. **fzf**: Must be installed on your system.
49
+ ```bash
50
+ brew install fzf
51
+ ```
52
+
53
+ ### Local Setup
54
+ 1. Clone the repository:
55
+ ```bash
56
+ git clone [https://github.com/Sahaj001/Script-Manager.git](https://github.com/Sahaj001/Script-Manager.git)
57
+ cd Script-Manager
58
+ ```
59
+ 2. Install in editable mode:
60
+ ```bash
61
+ pip install -e .
62
+ ```
63
+
64
+ ---
65
+
66
+ ## Configuration
67
+
68
+ To enable command execution and history injection, add the following wrapper to your `~/.zshrc` or `~/.bashrc`:
69
+ ```bash
70
+ ### SCM START ###
71
+ rscm() {
72
+ local result=$(scm)
73
+ if [[ -n "$result" ]]; then
74
+ eval " $result"
75
+ fi
76
+ }
77
+ alias s='rscm'
78
+ ### SCM END ###
79
+ ```
80
+
81
+
82
+ ---
83
+ ### 🚀 Usage
84
+ > **Note**
85
+ > Simply type `s` or `run_scm` in your terminal to launch the interactive menu.
86
+
87
+
88
+ ---
89
+
90
+ ## 🛠 Features & Navigation
91
+
92
+ * **Select a Category:** Use the **arrow keys** to navigate or **start typing** to filter through your existing groups.
93
+ * **Execute:** Choose a specific command and hit `Enter` to run it directly in your current shell.
94
+ * **Management:**
95
+ * `[+ Add New Category]` — Create a new group for your commands.
96
+ * `[+ Add Command to...]` — Expand your library within a specific category.
97
+ * `[-] Delete` — Prune old or unused commands and groups.
98
+
99
+ ---
100
+
101
+
102
+ ## 🤝 Contributing
103
+
104
+ Contributions make the terminal better for everyone!
105
+
106
+ 1. **Fork** the repository.
107
+ 2. **Submit** a pull request with your improvements.
108
+ 3. *For major changes:* Please **open an issue** first to discuss your ideas so we can stay aligned on the project goals.
109
+
110
+ License
111
+ Apache License 2.0
112
+
@@ -0,0 +1,89 @@
1
+ [![Publish Python Package to PyPI](https://github.com/Sahaj001/Script-Manager/actions/workflows/publish.yml/badge.svg)](https://github.com/Sahaj001/Script-Manager/actions/workflows/publish.yml)
2
+
3
+ # Script-Command-Manager (SCM)
4
+ # 🚀 SCM Tool Guide
5
+
6
+ A streamlined command manager for your terminal workflows.
7
+
8
+ ## Overview
9
+
10
+ **SCM** is a high-performance CLI tool designed to catalog, manage, and execute complex shell commands through an intuitive fuzzy-finding interface. Built with Python and powered by `fzf`, it eliminates the need to remember arcane syntax or sift through endless history files.
11
+
12
+ ## Features
13
+ * **Fuzzy Search Navigation**: Instant filtering of categories and commands using `fzf`.
14
+ * **Hierarchical Management**: Organize commands into custom categories (e.g., Work, Dev, Personal).
15
+ * **In-App Administration**: Add or delete commands and entire categories directly from the interface.
16
+ * **Shell History Integration**: Commands executed via SCM can be injected into your shell history for easy access later.
17
+ * **Mac-Optimized Core**: Robust file I/O designed to handle macOS-specific shell environments and `sed/grep` variations.
18
+
19
+ ---
20
+
21
+ ## Installation
22
+
23
+ ### Prerequisites
24
+ 1. **Python**: 3.6 or higher.
25
+ 2. **fzf**: Must be installed on your system.
26
+ ```bash
27
+ brew install fzf
28
+ ```
29
+
30
+ ### Local Setup
31
+ 1. Clone the repository:
32
+ ```bash
33
+ git clone [https://github.com/Sahaj001/Script-Manager.git](https://github.com/Sahaj001/Script-Manager.git)
34
+ cd Script-Manager
35
+ ```
36
+ 2. Install in editable mode:
37
+ ```bash
38
+ pip install -e .
39
+ ```
40
+
41
+ ---
42
+
43
+ ## Configuration
44
+
45
+ To enable command execution and history injection, add the following wrapper to your `~/.zshrc` or `~/.bashrc`:
46
+ ```bash
47
+ ### SCM START ###
48
+ rscm() {
49
+ local result=$(scm)
50
+ if [[ -n "$result" ]]; then
51
+ eval " $result"
52
+ fi
53
+ }
54
+ alias s='rscm'
55
+ ### SCM END ###
56
+ ```
57
+
58
+
59
+ ---
60
+ ### 🚀 Usage
61
+ > **Note**
62
+ > Simply type `s` or `run_scm` in your terminal to launch the interactive menu.
63
+
64
+
65
+ ---
66
+
67
+ ## 🛠 Features & Navigation
68
+
69
+ * **Select a Category:** Use the **arrow keys** to navigate or **start typing** to filter through your existing groups.
70
+ * **Execute:** Choose a specific command and hit `Enter` to run it directly in your current shell.
71
+ * **Management:**
72
+ * `[+ Add New Category]` — Create a new group for your commands.
73
+ * `[+ Add Command to...]` — Expand your library within a specific category.
74
+ * `[-] Delete` — Prune old or unused commands and groups.
75
+
76
+ ---
77
+
78
+
79
+ ## 🤝 Contributing
80
+
81
+ Contributions make the terminal better for everyone!
82
+
83
+ 1. **Fork** the repository.
84
+ 2. **Submit** a pull request with your improvements.
85
+ 3. *For major changes:* Please **open an issue** first to discuss your ideas so we can stay aligned on the project goals.
86
+
87
+ License
88
+ Apache License 2.0
89
+
@@ -0,0 +1,47 @@
1
+ """
2
+ Setup configuration for the S-Command-Manager (SCM) package.
3
+
4
+ This script uses setuptools to manage the installation, packaging, and
5
+ distribution of SCM. It defines the 'scm' entry point, allowing the
6
+ logic to be executed as a standalone CLI tool.
7
+
8
+ Key Features:
9
+ - Defines a console script entry point 'scm' mapping to main:start.
10
+ - Configured for local 'editable' installation for development.
11
+
12
+ Author: Sahaj Pratap Singh
13
+ License: Apache License 2.0
14
+ """
15
+ from setuptools import setup
16
+
17
+ def read_file():
18
+ """Read the README file."""
19
+ try:
20
+ with open("README.md", "r", encoding='utf-8') as f:
21
+ return f.read()
22
+ except FileNotFoundError:
23
+ return "Command manager using fzf"
24
+
25
+ setup(
26
+ name="command-manager-util",
27
+ version="1.1.0",
28
+ description="Manages useful commands in one place using fzf",
29
+ long_description=read_file(),
30
+ long_description_content_type="text/markdown",
31
+ author="Sahaj Pratap Singh",
32
+ url="https://github.com/Sahaj001/Script-Manager",
33
+ classifiers=[
34
+ "Programming Language :: Python :: 3",
35
+ "License :: OSI Approved :: Apache Software License",
36
+ "Operating System :: OS Independent",
37
+ ],
38
+ install_requires=[],
39
+ python_requires='>=3.6',
40
+ include_package_data=True,
41
+ entry_points={
42
+ 'console_scripts': [
43
+ 'scm=main:main',
44
+ ],
45
+ },
46
+ license="Apache 2.0",
47
+ )
@@ -0,0 +1,112 @@
1
+ Metadata-Version: 2.4
2
+ Name: command-manager-util
3
+ Version: 1.1.0
4
+ Summary: Manages useful commands in one place using fzf
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
+ Dynamic: author
15
+ Dynamic: classifier
16
+ Dynamic: description
17
+ Dynamic: description-content-type
18
+ Dynamic: home-page
19
+ Dynamic: license
20
+ Dynamic: license-file
21
+ Dynamic: requires-python
22
+ Dynamic: summary
23
+
24
+ [![Publish Python Package to PyPI](https://github.com/Sahaj001/Script-Manager/actions/workflows/publish.yml/badge.svg)](https://github.com/Sahaj001/Script-Manager/actions/workflows/publish.yml)
25
+
26
+ # Script-Command-Manager (SCM)
27
+ # 🚀 SCM Tool Guide
28
+
29
+ A streamlined command manager for your terminal workflows.
30
+
31
+ ## Overview
32
+
33
+ **SCM** is a high-performance CLI tool designed to catalog, manage, and execute complex shell commands through an intuitive fuzzy-finding interface. Built with Python and powered by `fzf`, it eliminates the need to remember arcane syntax or sift through endless history files.
34
+
35
+ ## Features
36
+ * **Fuzzy Search Navigation**: Instant filtering of categories and commands using `fzf`.
37
+ * **Hierarchical Management**: Organize commands into custom categories (e.g., Work, Dev, Personal).
38
+ * **In-App Administration**: Add or delete commands and entire categories directly from the interface.
39
+ * **Shell History Integration**: Commands executed via SCM can be injected into your shell history for easy access later.
40
+ * **Mac-Optimized Core**: Robust file I/O designed to handle macOS-specific shell environments and `sed/grep` variations.
41
+
42
+ ---
43
+
44
+ ## Installation
45
+
46
+ ### Prerequisites
47
+ 1. **Python**: 3.6 or higher.
48
+ 2. **fzf**: Must be installed on your system.
49
+ ```bash
50
+ brew install fzf
51
+ ```
52
+
53
+ ### Local Setup
54
+ 1. Clone the repository:
55
+ ```bash
56
+ git clone [https://github.com/Sahaj001/Script-Manager.git](https://github.com/Sahaj001/Script-Manager.git)
57
+ cd Script-Manager
58
+ ```
59
+ 2. Install in editable mode:
60
+ ```bash
61
+ pip install -e .
62
+ ```
63
+
64
+ ---
65
+
66
+ ## Configuration
67
+
68
+ To enable command execution and history injection, add the following wrapper to your `~/.zshrc` or `~/.bashrc`:
69
+ ```bash
70
+ ### SCM START ###
71
+ rscm() {
72
+ local result=$(scm)
73
+ if [[ -n "$result" ]]; then
74
+ eval " $result"
75
+ fi
76
+ }
77
+ alias s='rscm'
78
+ ### SCM END ###
79
+ ```
80
+
81
+
82
+ ---
83
+ ### 🚀 Usage
84
+ > **Note**
85
+ > Simply type `s` or `run_scm` in your terminal to launch the interactive menu.
86
+
87
+
88
+ ---
89
+
90
+ ## 🛠 Features & Navigation
91
+
92
+ * **Select a Category:** Use the **arrow keys** to navigate or **start typing** to filter through your existing groups.
93
+ * **Execute:** Choose a specific command and hit `Enter` to run it directly in your current shell.
94
+ * **Management:**
95
+ * `[+ Add New Category]` — Create a new group for your commands.
96
+ * `[+ Add Command to...]` — Expand your library within a specific category.
97
+ * `[-] Delete` — Prune old or unused commands and groups.
98
+
99
+ ---
100
+
101
+
102
+ ## 🤝 Contributing
103
+
104
+ Contributions make the terminal better for everyone!
105
+
106
+ 1. **Fork** the repository.
107
+ 2. **Submit** a pull request with your improvements.
108
+ 3. *For major changes:* Please **open an issue** first to discuss your ideas so we can stay aligned on the project goals.
109
+
110
+ License
111
+ Apache License 2.0
112
+
@@ -1,2 +1,2 @@
1
1
  [console_scripts]
2
- scm = main:start
2
+ scm = main:main
@@ -0,0 +1,145 @@
1
+ # main.py
2
+ import subprocess
3
+ import os
4
+ import sys
5
+
6
+ CONFIG_FILE = os.path.expanduser("~/.work_commands")
7
+
8
+
9
+ def load_commands():
10
+ """Loods commadns"""
11
+ if not os.path.exists(CONFIG_FILE):
12
+ return []
13
+ with open(CONFIG_FILE, "r", encoding="utf-8") as f:
14
+ # Filter out empty lines and ensure 3 parts per line
15
+ return [line.strip().split("|") for line in f if line.strip() and "|" in line]
16
+
17
+
18
+ def save_commands(commands):
19
+ """Save commands"""
20
+ with open(CONFIG_FILE, "w", encoding="utf-8") as f:
21
+ for cmd in commands:
22
+ f.write("|".join(cmd) + "\n")
23
+
24
+
25
+ def run_fzf(options, header):
26
+ """Run fuzzy finder"""
27
+ input_str = "\n".join(options)
28
+ try:
29
+ with subprocess.Popen(
30
+ ["fzf", "--height", "40%", "--reverse", "--header", header],
31
+ stdin=subprocess.PIPE,
32
+ stdout=subprocess.PIPE,
33
+ text=True,
34
+ ) as process:
35
+ stdout, _ = process.communicate(input=input_str)
36
+ return stdout.strip() if stdout else None
37
+ except FileNotFoundError:
38
+ print("Error: 'fzf' binary not found. Please install it via brew/apt.")
39
+ return None
40
+ except subprocess.SubprocessError:
41
+ return None
42
+
43
+
44
+ def prompt_user(msg):
45
+ """Prompt to user"""
46
+ sys.stderr.write(f"{msg}: ")
47
+ sys.stderr.flush()
48
+ return sys.stdin.readline().strip()
49
+
50
+
51
+ def add_new_command(commands, category=None):
52
+ """Handles the UI and logic for adding a new command."""
53
+ target_cat = category or prompt_user("Enter Category Name")
54
+ name = prompt_user("Enter Display Name")
55
+ cmd = prompt_user("Enter Bash Command")
56
+
57
+ if target_cat and name and cmd:
58
+ commands.append([target_cat, name, cmd])
59
+ save_commands(commands)
60
+ print(f"echo '✅ Added to {target_cat}'")
61
+
62
+
63
+ def delete_logic(commands, category=None):
64
+ """Handles deletion of an entire category or a single command."""
65
+ # 1. DELETE WHOLE CATEGORY (if no specific category is passed)
66
+ if category is None:
67
+ categories = sorted(list(set(c[0] for c in commands)))
68
+ if not categories:
69
+ print("echo 'No categories to delete!'")
70
+ return
71
+
72
+ cat_to_wipe = run_fzf(categories, "SELECT CATEGORY TO WIPE ENTIRELY")
73
+ if cat_to_wipe:
74
+ conf = prompt_user(f"Delete ALL commands in [{cat_to_wipe}]? (y/n)")
75
+ if conf and conf.lower() == "y":
76
+ updated_commands = [c for c in commands if c[0] != cat_to_wipe]
77
+ save_commands(updated_commands)
78
+ print(f"echo '❌ Category [{cat_to_wipe}] deleted!'")
79
+ return
80
+
81
+ # 2. DELETE SINGLE COMMAND (if category is provided)
82
+ sub_cmds = [c for c in commands if c[0] == category]
83
+ cat_raw = [f"{c[1]} | {c[2]}" for c in sub_cmds]
84
+
85
+ to_delete_display = run_fzf(cat_raw, f"SELECT COMMAND TO DELETE FROM {category}")
86
+
87
+ if to_delete_display:
88
+ parts = [x.strip() for x in to_delete_display.split("|")]
89
+ if len(parts) >= 2:
90
+ d_name, d_cmd = parts[0], parts[1]
91
+ updated_commands = [
92
+ c
93
+ for c in commands
94
+ if not (c[0] == category and c[1] == d_name and c[2] == d_cmd)
95
+ ]
96
+ save_commands(updated_commands)
97
+ print(f"echo '❌ Deleted [{d_name}] from {category}'")
98
+
99
+
100
+ def main():
101
+ """Main function - Orchestrates the menu navigation."""
102
+ while True:
103
+ commands = load_commands()
104
+ categories = sorted(list(set(c[0] for c in commands)))
105
+
106
+ # 1. CATEGORY LEVEL
107
+ cat_options = categories + ["[+ Add New Category]", "[- Delete Category]"]
108
+ category = run_fzf(cat_options, "Select Category (Esc to Exit)")
109
+
110
+ if not category:
111
+ sys.exit(0)
112
+
113
+ if category == "[+ Add New Category]":
114
+ add_new_command(commands)
115
+ return
116
+
117
+ if category == "[- Delete Category]":
118
+ delete_logic(commands)
119
+ return
120
+
121
+ # 2. COMMAND LEVEL
122
+ sub_cmds = [c for c in commands if c[0] == category]
123
+ cmd_options = [f"{c[1]}|{c[2]}" for c in sub_cmds]
124
+ cmd_options += [
125
+ f"[+ Add Command to {category}]",
126
+ f"[- Delete Command from {category}]",
127
+ ]
128
+
129
+ selection = run_fzf(cmd_options, f"Commands in {category}")
130
+
131
+ if not selection:
132
+ continue
133
+
134
+ if selection == f"[+ Add Command to {category}]":
135
+ add_new_command(commands, category)
136
+ return
137
+
138
+ # --- NEW LOGIC CALL ---
139
+ if selection == f"[- Delete Command from {category}]":
140
+ delete_logic(commands, category)
141
+ return
142
+
143
+ # 3. EXECUTE
144
+ print(selection.split("|", maxsplit=2)[-1])
145
+ break
@@ -1,58 +0,0 @@
1
- Metadata-Version: 2.2
2
- Name: command-manager-util
3
- Version: 0.1.1
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
- Dynamic: author
15
- Dynamic: classifier
16
- Dynamic: description
17
- Dynamic: description-content-type
18
- Dynamic: home-page
19
- Dynamic: license
20
- Dynamic: requires-python
21
- Dynamic: summary
22
-
23
- # Script Manager
24
-
25
- ## Overview
26
-
27
- 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.
28
-
29
- ## Features
30
-
31
- - **Category Management**: Create and remove categories to organize your commands.
32
- - **Command Management**: Add and remove commands within categories as needed.
33
- - **Command Execution**: Select and run commands directly from the tool.
34
- - **No External Storage**: All commands and categories are stored within the tool itself.
35
- - **Easy to Use**: A simple interface for easy command management.
36
-
37
- ## Installation
38
-
39
- Follow the installation steps in the repository to set up the Script Manager on your system.
40
-
41
- ## Usage
42
-
43
- Once installed, you can use the Script Manager to manage your commands.
44
-
45
- - Create and organize categories.
46
- - Add or remove commands within those categories.
47
- - Execute commands directly with a simple interface.
48
-
49
- ## Benefits
50
-
51
- - **Simplified Workflow**: Easily manage and execute commands without needing to remember them.
52
- - **No External Files Needed**: Everything stays within the tool, making it easy to maintain and backup.
53
- - **Time-Saving**: Run your commands with a few simple actions, eliminating the need for manual typing.
54
- - **Minimal Setup**: Get started quickly with no complex configurations.
55
-
56
- ## Contributing
57
-
58
- Feel free to fork the repository and contribute to the project.
@@ -1,36 +0,0 @@
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.
@@ -1,32 +0,0 @@
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.1",
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
- )
@@ -1,58 +0,0 @@
1
- Metadata-Version: 2.2
2
- Name: command-manager-util
3
- Version: 0.1.1
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
- Dynamic: author
15
- Dynamic: classifier
16
- Dynamic: description
17
- Dynamic: description-content-type
18
- Dynamic: home-page
19
- Dynamic: license
20
- Dynamic: requires-python
21
- Dynamic: summary
22
-
23
- # Script Manager
24
-
25
- ## Overview
26
-
27
- 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.
28
-
29
- ## Features
30
-
31
- - **Category Management**: Create and remove categories to organize your commands.
32
- - **Command Management**: Add and remove commands within categories as needed.
33
- - **Command Execution**: Select and run commands directly from the tool.
34
- - **No External Storage**: All commands and categories are stored within the tool itself.
35
- - **Easy to Use**: A simple interface for easy command management.
36
-
37
- ## Installation
38
-
39
- Follow the installation steps in the repository to set up the Script Manager on your system.
40
-
41
- ## Usage
42
-
43
- Once installed, you can use the Script Manager to manage your commands.
44
-
45
- - Create and organize categories.
46
- - Add or remove commands within those categories.
47
- - Execute commands directly with a simple interface.
48
-
49
- ## Benefits
50
-
51
- - **Simplified Workflow**: Easily manage and execute commands without needing to remember them.
52
- - **No External Files Needed**: Everything stays within the tool, making it easy to maintain and backup.
53
- - **Time-Saving**: Run your commands with a few simple actions, eliminating the need for manual typing.
54
- - **Minimal Setup**: Get started quickly with no complex configurations.
55
-
56
- ## Contributing
57
-
58
- Feel free to fork the repository and contribute to the project.
@@ -1,248 +0,0 @@
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)