coolguy038_pysh 0.2.4__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.
Potentially problematic release.
This version of coolguy038_pysh might be problematic. Click here for more details.
- coolguy038_pysh-0.2.4/PKG-INFO +61 -0
- coolguy038_pysh-0.2.4/README.md +47 -0
- coolguy038_pysh-0.2.4/pyproject.toml +26 -0
- coolguy038_pysh-0.2.4/pyproject.toml.orig +24 -0
- coolguy038_pysh-0.2.4/src/coolguy038_pysh/__init__.py +0 -0
- coolguy038_pysh-0.2.4/src/coolguy038_pysh/cli.py +2 -0
- coolguy038_pysh-0.2.4/src/coolguy038_pysh/pysh.py +397 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: coolguy038_pysh
|
|
3
|
+
Version: 0.2.4
|
|
4
|
+
Summary: A custom python shell (pronounced like "fysh")
|
|
5
|
+
Author: Cade
|
|
6
|
+
Author-email: Cade <cadey.matignas@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Dist: termcolor>=2.4.0
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Project-URL: Homepage, https://github.com/cadeymatignas-source/pysh
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# Pysh (PYthon SHell)
|
|
16
|
+
|
|
17
|
+
## This is a shell coded entirely in Python
|
|
18
|
+
|
|
19
|
+
<div align="center">
|
|
20
|
+
<img src="logo.png" alt="alt text">
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
### Overview
|
|
24
|
+
|
|
25
|
+
Pysh is a shell made out of pure Python. It has tools for building and packaging Python projects and has an updater (if you download it via the bundle).
|
|
26
|
+
|
|
27
|
+
### Why?
|
|
28
|
+
|
|
29
|
+
Some reasons you would want to install this:
|
|
30
|
+
|
|
31
|
+
- Python tooling
|
|
32
|
+
- Easy but powerful configuration (~/.pysh.toml and ~/.pyshrc)
|
|
33
|
+
- Cross-platform
|
|
34
|
+
- Plugin support
|
|
35
|
+
|
|
36
|
+
## Pythoner
|
|
37
|
+
|
|
38
|
+
Pythoner is another related project. It is a custom Python REPL designed to combine Python and package handling in one tool.<br>
|
|
39
|
+
It was extracted from pysh.<br>
|
|
40
|
+
[More details here](https://pypi.org/project/Pythoner/)
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
[To install Pysh, click this link and find your OS's release](https://github.com/cadeymatignas-source/pysh/releases/latest).<br>
|
|
45
|
+
Or, you could run the `pyshupdate` CLI included in the bundle.
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pyshupdate
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
You can also install pysh via pypi:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pipx install coolguy038_pysh
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
To install pythoner:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install pythoner
|
|
61
|
+
```
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Pysh (PYthon SHell)
|
|
2
|
+
|
|
3
|
+
## This is a shell coded entirely in Python
|
|
4
|
+
|
|
5
|
+
<div align="center">
|
|
6
|
+
<img src="logo.png" alt="alt text">
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
### Overview
|
|
10
|
+
|
|
11
|
+
Pysh is a shell made out of pure Python. It has tools for building and packaging Python projects and has an updater (if you download it via the bundle).
|
|
12
|
+
|
|
13
|
+
### Why?
|
|
14
|
+
|
|
15
|
+
Some reasons you would want to install this:
|
|
16
|
+
|
|
17
|
+
- Python tooling
|
|
18
|
+
- Easy but powerful configuration (~/.pysh.toml and ~/.pyshrc)
|
|
19
|
+
- Cross-platform
|
|
20
|
+
- Plugin support
|
|
21
|
+
|
|
22
|
+
## Pythoner
|
|
23
|
+
|
|
24
|
+
Pythoner is another related project. It is a custom Python REPL designed to combine Python and package handling in one tool.<br>
|
|
25
|
+
It was extracted from pysh.<br>
|
|
26
|
+
[More details here](https://pypi.org/project/Pythoner/)
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
[To install Pysh, click this link and find your OS's release](https://github.com/cadeymatignas-source/pysh/releases/latest).<br>
|
|
31
|
+
Or, you could run the `pyshupdate` CLI included in the bundle.
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pyshupdate
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
You can also install pysh via pypi:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pipx install coolguy038_pysh
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
To install pythoner:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install pythoner
|
|
47
|
+
```
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["uv_build>=0.12.21,<0.14"]
|
|
3
|
+
build-backend = "uv_build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "coolguy038_pysh"
|
|
7
|
+
version = "0.2.4"
|
|
8
|
+
description = 'A custom python shell (pronounced like "fysh")'
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"Operating System :: OS Independent",
|
|
15
|
+
]
|
|
16
|
+
dependencies = ["termcolor>=2.4.0"]
|
|
17
|
+
|
|
18
|
+
[[project.authors]]
|
|
19
|
+
name = "Cade"
|
|
20
|
+
email = "cadey.matignas@gmail.com"
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Homepage = "https://github.com/cadeymatignas-source/pysh"
|
|
24
|
+
|
|
25
|
+
[project.scripts]
|
|
26
|
+
pysh = "coolguy038_pysh.cli:main"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["uv_build>=0.12.21,<0.14"]
|
|
3
|
+
build-backend = "uv_build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "coolguy038_pysh"
|
|
7
|
+
version = "0.2.4"
|
|
8
|
+
authors = [{ name = "Cade", email = "cadey.matignas@gmail.com" }]
|
|
9
|
+
description = 'A custom python shell (pronounced like "fysh")'
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
requires-python = ">=3.8"
|
|
12
|
+
license = "MIT"
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Operating System :: OS Independent",
|
|
16
|
+
]
|
|
17
|
+
dependencies = ["termcolor>=2.4.0"]
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Homepage = "https://github.com/cadeymatignas-source/pysh"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
[project.scripts]
|
|
24
|
+
pysh = "coolguy038_pysh.cli:main"
|
|
File without changes
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
__lazy_modules__ = ["os", "re", "sys", "shlex", "subprocess", "time", "tomllib", "pathlib", "termcolor"]
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import re
|
|
5
|
+
import shlex
|
|
6
|
+
import subprocess
|
|
7
|
+
import sys
|
|
8
|
+
import time
|
|
9
|
+
import tomllib
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from termcolor import colored
|
|
13
|
+
|
|
14
|
+
platform = os.name
|
|
15
|
+
system = sys.platform
|
|
16
|
+
config_path = Path.home() / ".pysh.toml"
|
|
17
|
+
config_py_path = Path.home() / ".pyshrc"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
if not config_path.exists():
|
|
21
|
+
print("Hello new user!")
|
|
22
|
+
if system == "linux":
|
|
23
|
+
linux_pack = input("What package manager is compatible with your distro? Type here: ")
|
|
24
|
+
|
|
25
|
+
watprompt_color = input("What color do you want your prompt to be? (red, green, yellow, blue, magenta, cyan, white): ")
|
|
26
|
+
use_uv = input("Do you use uv? (y/N): ")
|
|
27
|
+
if use_uv.lower() == "y":
|
|
28
|
+
use_uv = True
|
|
29
|
+
use_uv_publish = input("Do you use uv-publish? (y/N): ")
|
|
30
|
+
use_uv_publish = use_uv_publish.lower() == "y"
|
|
31
|
+
else:
|
|
32
|
+
use_uv = False
|
|
33
|
+
use_uv_publish = False
|
|
34
|
+
autocdyes = input("Do you want to enable AUTOCD? (y/N): ")
|
|
35
|
+
autocdyes = autocdyes.lower() == "y"
|
|
36
|
+
whichentrymessage = input("Do you want to enable the entry message? (on/off/legacy): ")
|
|
37
|
+
whichentrymessage = whichentrymessage.lower()
|
|
38
|
+
|
|
39
|
+
config_path.parent.mkdir(parents=True, exist_ok=True)
|
|
40
|
+
|
|
41
|
+
if system == "win32":
|
|
42
|
+
config_path.write_text(
|
|
43
|
+
f"""package_manager = "winget"
|
|
44
|
+
User = "root"
|
|
45
|
+
prompt_color = "{watprompt_color}"
|
|
46
|
+
use_uv = {str(use_uv).lower()}
|
|
47
|
+
use_uv-publish = {str(use_uv_publish).lower()}
|
|
48
|
+
AUTOCD = {str(autocdyes).lower()}
|
|
49
|
+
entry_message = "{whichentrymessage}"
|
|
50
|
+
[danger_zone]
|
|
51
|
+
dont_start = false
|
|
52
|
+
dont_read_pyshrc = false
|
|
53
|
+
"""
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
elif system == "linux":
|
|
57
|
+
config_path.write_text(
|
|
58
|
+
f"""package_manager = "{linux_pack}"
|
|
59
|
+
User = "root"
|
|
60
|
+
prompt_color = "{watprompt_color}"
|
|
61
|
+
use_uv = {str(use_uv).lower()}
|
|
62
|
+
use_uv-publish = {str(use_uv_publish).lower()}
|
|
63
|
+
AUTOCD = {str(autocdyes).lower()}
|
|
64
|
+
entry_message = "{whichentrymessage}"
|
|
65
|
+
[danger_zone]
|
|
66
|
+
dont_start = false
|
|
67
|
+
dont_read_pyshrc = false
|
|
68
|
+
"""
|
|
69
|
+
)
|
|
70
|
+
elif system == "darwin":
|
|
71
|
+
config_path.write_text(
|
|
72
|
+
f"""package_manager = "brew"
|
|
73
|
+
User = "root"
|
|
74
|
+
prompt_color = "{watprompt_color}"
|
|
75
|
+
use_uv = {str(use_uv).lower()}
|
|
76
|
+
use_uv-publish = {str(use_uv_publish).lower()}
|
|
77
|
+
AUTOCD = {str(autocdyes).lower()}
|
|
78
|
+
entry_message = "{whichentrymessage}"
|
|
79
|
+
[danger_zone]
|
|
80
|
+
dont_start = false
|
|
81
|
+
dont_read_pyshrc = false
|
|
82
|
+
"""
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
if not config_py_path.exists():
|
|
86
|
+
print("Generating .pyshrc")
|
|
87
|
+
|
|
88
|
+
config_py_path.parent.mkdir(parents=True, exist_ok=True)
|
|
89
|
+
|
|
90
|
+
config_py_path.write_text("# Put code here, to run once before the main code.")
|
|
91
|
+
|
|
92
|
+
with config_path.open("rb") as f:
|
|
93
|
+
global config
|
|
94
|
+
config = tomllib.load(f)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
variables = {"$USERPROFILE": Path.home(), "$USER": config["User"], "$SHELL": sys.executable, "$HOME": Path.home(), "~": Path.home()}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def expand_vars(text):
|
|
101
|
+
|
|
102
|
+
for name, value in variables.items():
|
|
103
|
+
text = text.replace(f"{name}", str(value))
|
|
104
|
+
return text
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
if config["danger_zone"]["dont_start"]:
|
|
108
|
+
sys.exit()
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def main(argv="noargs"):
|
|
112
|
+
global config
|
|
113
|
+
change = False
|
|
114
|
+
while True:
|
|
115
|
+
try:
|
|
116
|
+
if not change:
|
|
117
|
+
temp = colored(f"PT -> {Path.cwd()}> ", config["prompt_color"])
|
|
118
|
+
prompter = temp
|
|
119
|
+
|
|
120
|
+
cmd = argv if argv != "noargs" else input(prompter).strip()
|
|
121
|
+
commands = argv if isinstance(cmd, list) else [c.strip() for c in re.split(r"&&|;|&", cmd) if c.strip()]
|
|
122
|
+
has_and = "&&" in commands
|
|
123
|
+
success = True
|
|
124
|
+
for command in commands:
|
|
125
|
+
if command == "exit":
|
|
126
|
+
print("Goodbye!")
|
|
127
|
+
sys.exit()
|
|
128
|
+
elif command == "coolguy38 is sigma":
|
|
129
|
+
print("Yes, im sigma B)")
|
|
130
|
+
elif command == "cd" or command == "pwd":
|
|
131
|
+
print(Path.cwd())
|
|
132
|
+
|
|
133
|
+
elif command.startswith("cd "):
|
|
134
|
+
path = command[3:].strip().strip("'\"")
|
|
135
|
+
|
|
136
|
+
try:
|
|
137
|
+
os.chdir(expand_vars(path))
|
|
138
|
+
|
|
139
|
+
except Exception as e:
|
|
140
|
+
print(colored(f"Pysh: cd Error: {e}", "red"))
|
|
141
|
+
success = False
|
|
142
|
+
|
|
143
|
+
elif command.startswith("prompt "):
|
|
144
|
+
temp = command[7:] + " "
|
|
145
|
+
change = True
|
|
146
|
+
elif command.lower() == "reset prompt" or command.lower() == "prompt":
|
|
147
|
+
change = False
|
|
148
|
+
|
|
149
|
+
elif command.lower() == "help":
|
|
150
|
+
print(
|
|
151
|
+
"""- help: explains every command
|
|
152
|
+
- coolguy38 is sigma: responds
|
|
153
|
+
- reset prompt: Resets the prompt
|
|
154
|
+
- prompt: Also resets the prompt
|
|
155
|
+
- pwd: Prints the current working directory
|
|
156
|
+
- pyexe <text>: Runs pyinstaller --onefile for you. If it reaches an error it asks you if you want to download pyinstaller
|
|
157
|
+
- pypub <text>: Builds and publishes your library to pypi. If it reaches an error it asks you if you want to download twine and build
|
|
158
|
+
- pack get: use this like the package manager you chose. (like pack get install Git.git if using winget)
|
|
159
|
+
- os: prints your os
|
|
160
|
+
- view <path>: Its basically cat but with syntax highlighting
|
|
161
|
+
- prompt <text>: Changes the prompt to <text>
|
|
162
|
+
- echo <text>: Prints <text>
|
|
163
|
+
- ls/dir: Lists the current directory
|
|
164
|
+
- ls <path>/dir <path>: Lists the directory at <path>
|
|
165
|
+
- md/mkdir <dir>: Makes a directory called <dir>
|
|
166
|
+
- time: Prints the current time
|
|
167
|
+
- cls/clear: Clears the terminal
|
|
168
|
+
- cd <path>: Changes the current directory to <path>
|
|
169
|
+
- cat <file>: Prints the contents of <file>
|
|
170
|
+
- <file>.pysh: Runs the .pysh file"""
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
elif command.startswith("pyexe "):
|
|
174
|
+
pyn = command[6:].strip()
|
|
175
|
+
pynn = subprocess.run(f"pyinstaller {pyn}", shell=True, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr)
|
|
176
|
+
if pynn.returncode != 0:
|
|
177
|
+
down = input("Oh no! Pyinstaller failed. Download? (y/N)")
|
|
178
|
+
match down.lower():
|
|
179
|
+
case "y":
|
|
180
|
+
subprocess.run("pip install pyinstaller", stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, shell=True)
|
|
181
|
+
case "n":
|
|
182
|
+
print("Ok")
|
|
183
|
+
success = False
|
|
184
|
+
elif command.startswith("pypub "):
|
|
185
|
+
if config["use_uv"]:
|
|
186
|
+
pyb = command[6:].strip()
|
|
187
|
+
if config["use_uv-publish"]:
|
|
188
|
+
pybb = subprocess.run(
|
|
189
|
+
f"uv build && uv-publish && uv pip install --upgrade --system {pyb}",
|
|
190
|
+
stdin=sys.stdin,
|
|
191
|
+
stdout=sys.stdout,
|
|
192
|
+
stderr=sys.stderr,
|
|
193
|
+
shell=True,
|
|
194
|
+
)
|
|
195
|
+
else:
|
|
196
|
+
pybb = subprocess.run(
|
|
197
|
+
f"uv build && uv publish && uv pip install --upgrade --system {pyb}",
|
|
198
|
+
stdin=sys.stdin,
|
|
199
|
+
stdout=sys.stdout,
|
|
200
|
+
stderr=sys.stderr,
|
|
201
|
+
shell=True,
|
|
202
|
+
)
|
|
203
|
+
else:
|
|
204
|
+
pyb = command[6:].strip()
|
|
205
|
+
pybb = subprocess.run(
|
|
206
|
+
f"python -m build && python -m twine check dist/* && python -m twine upload dist/* && pip install --upgrade {pyb}",
|
|
207
|
+
stdin=sys.stdin,
|
|
208
|
+
stdout=sys.stdout,
|
|
209
|
+
stderr=sys.stderr,
|
|
210
|
+
shell=True,
|
|
211
|
+
)
|
|
212
|
+
if pybb.returncode != 0:
|
|
213
|
+
if config["use_uv"]:
|
|
214
|
+
downl = input("Oh no! Something failed! Download uv and uv-publish? (y/N)")
|
|
215
|
+
match downl.lower():
|
|
216
|
+
case "y":
|
|
217
|
+
subprocess.run(
|
|
218
|
+
"pipx install uv && uv tool install uv-publish",
|
|
219
|
+
stdin=sys.stdin,
|
|
220
|
+
stdout=sys.stdout,
|
|
221
|
+
stderr=sys.stderr,
|
|
222
|
+
shell=True,
|
|
223
|
+
)
|
|
224
|
+
case "n":
|
|
225
|
+
print("Ok")
|
|
226
|
+
|
|
227
|
+
else:
|
|
228
|
+
downl = input("Oh no! Something failed! Download build and twine? (y/N)")
|
|
229
|
+
match downl.lower():
|
|
230
|
+
case "y":
|
|
231
|
+
subprocess.run("pipx install build twine", stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, shell=True)
|
|
232
|
+
case "n":
|
|
233
|
+
print("Ok")
|
|
234
|
+
success = False
|
|
235
|
+
elif command.startswith("pack_get "):
|
|
236
|
+
getd = command[9:].strip()
|
|
237
|
+
subprocess.run(f"{config['package_manager']} {getd}", stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, shell=True)
|
|
238
|
+
elif command == "whoami":
|
|
239
|
+
print(f"You are {config['User']}")
|
|
240
|
+
|
|
241
|
+
elif command.endswith(")"):
|
|
242
|
+
try:
|
|
243
|
+
exec(command)
|
|
244
|
+
except NameError:
|
|
245
|
+
print(colored(f"Pysh: Error: Python command {command} doesnt exist", "red"))
|
|
246
|
+
success = False
|
|
247
|
+
elif command == "os":
|
|
248
|
+
print(system)
|
|
249
|
+
|
|
250
|
+
elif command.startswith("view "):
|
|
251
|
+
viewed = command[5:].strip()
|
|
252
|
+
|
|
253
|
+
viewer = subprocess.run(
|
|
254
|
+
f"pygmentize {expand_vars(viewed)}", stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, shell=True, text=True
|
|
255
|
+
)
|
|
256
|
+
if viewer.returncode != 0:
|
|
257
|
+
print(colored("Pysh: view Error: Failed to view file", "red"))
|
|
258
|
+
success = False
|
|
259
|
+
elif command.startswith("cat "):
|
|
260
|
+
file = command[4:].strip()
|
|
261
|
+
|
|
262
|
+
try:
|
|
263
|
+
print(expand_vars(Path(file).read_text()))
|
|
264
|
+
except FileNotFoundError:
|
|
265
|
+
print(colored(f"Pysh: cat Error: File {file} not found", "red"))
|
|
266
|
+
success = False
|
|
267
|
+
elif command.startswith("echo "):
|
|
268
|
+
echoed = command[5:].strip()
|
|
269
|
+
print(expand_vars(echoed))
|
|
270
|
+
elif command in ["ls", "dir"]:
|
|
271
|
+
path = "."
|
|
272
|
+
try:
|
|
273
|
+
for entry in os.listdir(path):
|
|
274
|
+
print(entry)
|
|
275
|
+
except FileNotFoundError:
|
|
276
|
+
print(colored(f"Pysh: {command} Error: Directory {path} not found", "red"))
|
|
277
|
+
success = False
|
|
278
|
+
except PermissionError:
|
|
279
|
+
print(
|
|
280
|
+
colored(
|
|
281
|
+
f"Pysh: {command} Error: Permission denied to access {path}. Make sure you have permissions to view this directory.",
|
|
282
|
+
"red",
|
|
283
|
+
)
|
|
284
|
+
)
|
|
285
|
+
success = False
|
|
286
|
+
elif command.lower().startswith("ls "):
|
|
287
|
+
pather = command[3:].strip()
|
|
288
|
+
path = expand_vars(pather.strip("'\""))
|
|
289
|
+
try:
|
|
290
|
+
for entry in os.listdir(path):
|
|
291
|
+
print(entry)
|
|
292
|
+
except FileNotFoundError:
|
|
293
|
+
print(colored(f"Pysh: ls Error: Directory {path} not found", "red"))
|
|
294
|
+
success = False
|
|
295
|
+
except PermissionError:
|
|
296
|
+
print(
|
|
297
|
+
colored(
|
|
298
|
+
f"Pysh: ls Error: Permission denied to access {path}. Make sure you have permissions to view this directory.", "red"
|
|
299
|
+
)
|
|
300
|
+
)
|
|
301
|
+
success = False
|
|
302
|
+
|
|
303
|
+
elif command.endswith(".pysh") or command.endswith(".py") and not command.startswith("python"):
|
|
304
|
+
try:
|
|
305
|
+
exec(Path(command).read_text())
|
|
306
|
+
except FileNotFoundError:
|
|
307
|
+
print(colored(f"Pysh: Error: File {command} not found", "red"))
|
|
308
|
+
success = False
|
|
309
|
+
|
|
310
|
+
elif command.startswith("md "):
|
|
311
|
+
makedir = command[3:].strip().strip("'\"")
|
|
312
|
+
try:
|
|
313
|
+
Path(makedir).mkdir(exist_ok=True, parents=True)
|
|
314
|
+
except PermissionError:
|
|
315
|
+
print(colored(f"Pysh: md Error: You can't make a directory in {Path.cwd()}", "red"))
|
|
316
|
+
success = False
|
|
317
|
+
elif command.startswith("mkdir "):
|
|
318
|
+
makedir = command[6:].strip().strip("'\"")
|
|
319
|
+
try:
|
|
320
|
+
Path(makedir).mkdir(exist_ok=True, parents=True)
|
|
321
|
+
except PermissionError:
|
|
322
|
+
print(colored(f"Pysh: mkdir Error: You can't make a directory in {Path.cwd()}", "red"))
|
|
323
|
+
success = False
|
|
324
|
+
elif command == "time":
|
|
325
|
+
print(time.strftime("%I:%M %p"))
|
|
326
|
+
elif command in ["cls", "clear"]:
|
|
327
|
+
subprocess.run("cls" if platform == "nt" else "clear", stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, shell=True)
|
|
328
|
+
|
|
329
|
+
else:
|
|
330
|
+
plugins = config.get("plugins", {})
|
|
331
|
+
|
|
332
|
+
for plugin_name, plugin_code in plugins.items():
|
|
333
|
+
try:
|
|
334
|
+
exec(plugin_code)
|
|
335
|
+
except Exception as e:
|
|
336
|
+
print(colored(f"Pysh: Error: Error while executing plugin {plugin_name}: {e}", "red"))
|
|
337
|
+
if config["AUTOCD"]:
|
|
338
|
+
try:
|
|
339
|
+
os.chdir(expand_vars(command))
|
|
340
|
+
except Exception:
|
|
341
|
+
args = shlex.split(command)
|
|
342
|
+
subprocess.run(args, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr)
|
|
343
|
+
else:
|
|
344
|
+
args = shlex.split(command)
|
|
345
|
+
subprocess.run(args, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr)
|
|
346
|
+
if not success and has_and:
|
|
347
|
+
break
|
|
348
|
+
argv = "noargs"
|
|
349
|
+
|
|
350
|
+
except KeyboardInterrupt:
|
|
351
|
+
print("^C")
|
|
352
|
+
continue
|
|
353
|
+
except EOFError:
|
|
354
|
+
print("^D")
|
|
355
|
+
print("Goodbye!")
|
|
356
|
+
sys.exit()
|
|
357
|
+
except Exception as e:
|
|
358
|
+
print(colored(f"Pysh: Error: {e}", "red"))
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
if len(sys.argv) > 1:
|
|
362
|
+
if sys.argv[1] == "-c":
|
|
363
|
+
if config["entry_message"] == "legacy":
|
|
364
|
+
print(colored(f"Welcome to the python terminal, {config['User']}!", config["prompt_color"]))
|
|
365
|
+
elif config["entry_message"] == "on":
|
|
366
|
+
print(colored(f"Welcome to Pysh, {config['User']}!", config["prompt_color"]))
|
|
367
|
+
if not config["danger_zone"]["dont_read_pyshrc"]:
|
|
368
|
+
try:
|
|
369
|
+
exec(config_py_path.read_text())
|
|
370
|
+
except Exception as e:
|
|
371
|
+
print(colored(f"Pysh: Error: Error when executing pyshrc: {e}", "red"))
|
|
372
|
+
tempargs = sys.argv[2:]
|
|
373
|
+
main(tempargs)
|
|
374
|
+
|
|
375
|
+
elif sys.argv[1] == "-h":
|
|
376
|
+
main(["help"])
|
|
377
|
+
else:
|
|
378
|
+
if sys.argv[1].startswith("-"):
|
|
379
|
+
print(f"Pysh: Error: Unknown arg {sys.argv[1]}.")
|
|
380
|
+
else:
|
|
381
|
+
try:
|
|
382
|
+
exec(Path(sys.argv[1]).read_text())
|
|
383
|
+
except Exception as e:
|
|
384
|
+
print(colored(f"Pysh: Error: Error while executing file {sys.argv[1]}: {e}", "red"))
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
else:
|
|
388
|
+
if config["entry_message"] == "legacy":
|
|
389
|
+
print(colored(f"Welcome to the python terminal, {config['User']}!", config["prompt_color"]))
|
|
390
|
+
elif config["entry_message"] == "on":
|
|
391
|
+
print(colored(f"Welcome to Pysh, {config['User']}!", config["prompt_color"]))
|
|
392
|
+
if not config["danger_zone"]["dont_read_pyshrc"]:
|
|
393
|
+
try:
|
|
394
|
+
exec(config_py_path.read_text())
|
|
395
|
+
except Exception as e:
|
|
396
|
+
print(colored(f"Pysh: Error: Error when executing pyshrc: {e}", "red"))
|
|
397
|
+
main()
|