index-shell 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- index_shell/__init__.py +0 -0
- index_shell/cli.py +35 -0
- index_shell/core.py +53 -0
- index_shell/shell.py +57 -0
- index_shell-0.1.0.dist-info/METADATA +5 -0
- index_shell-0.1.0.dist-info/RECORD +9 -0
- index_shell-0.1.0.dist-info/WHEEL +5 -0
- index_shell-0.1.0.dist-info/entry_points.txt +4 -0
- index_shell-0.1.0.dist-info/top_level.txt +1 -0
index_shell/__init__.py
ADDED
|
File without changes
|
index_shell/cli.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from index_shell.core import list_dir, change_dir, open_file
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
args = sys.argv[1:]
|
|
7
|
+
|
|
8
|
+
if not args:
|
|
9
|
+
print("Commands: ls | cd | nano")
|
|
10
|
+
|
|
11
|
+
command = args[0]
|
|
12
|
+
|
|
13
|
+
if command == "ls":
|
|
14
|
+
print(list_dir(args[1]))
|
|
15
|
+
|
|
16
|
+
elif command == "cd":
|
|
17
|
+
if len(args) < 2:
|
|
18
|
+
print("Usage: cd <index>")
|
|
19
|
+
|
|
20
|
+
result = change_dir(int(args[1]), args[2])
|
|
21
|
+
if result:
|
|
22
|
+
print(result)
|
|
23
|
+
|
|
24
|
+
elif command == "nano":
|
|
25
|
+
if len(args) < 2:
|
|
26
|
+
print("Usage: nano <index>")
|
|
27
|
+
|
|
28
|
+
result = open_file(int(args[1]), args[2])
|
|
29
|
+
if result:
|
|
30
|
+
print(result)
|
|
31
|
+
|
|
32
|
+
else:
|
|
33
|
+
print("Unknown command:", command)
|
|
34
|
+
|
|
35
|
+
|
index_shell/core.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
import subprocess
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def list_visible(directory: str) -> list[str]:
|
|
8
|
+
return sorted(path for path in os.listdir(directory) if not path.startswith("."))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
path = r"C:\Users\HAROON TRADERS"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def list_dir(current_dir):
|
|
15
|
+
paths = list_visible(current_dir)
|
|
16
|
+
|
|
17
|
+
for i, path in enumerate(paths):
|
|
18
|
+
full_path = os.path.join(current_dir, path)
|
|
19
|
+
symbol = "/" if os.path.isdir(full_path) else " "
|
|
20
|
+
print(f"[{i}] {symbol} {path}")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def change_dir(index: int, current_dir: str):
|
|
24
|
+
paths = list_visible(current_dir)
|
|
25
|
+
|
|
26
|
+
if index < 0 or index >= len(paths):
|
|
27
|
+
print("Invalid index")
|
|
28
|
+
return
|
|
29
|
+
target = paths[index]
|
|
30
|
+
full_path = os.path.join(current_dir, target)
|
|
31
|
+
|
|
32
|
+
if os.path.isdir(full_path):
|
|
33
|
+
return full_path
|
|
34
|
+
else:
|
|
35
|
+
print("Not a directory")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def open_file(index, current_dir):
|
|
39
|
+
paths = list_visible(current_dir)
|
|
40
|
+
|
|
41
|
+
if index < 0 or index >= len(paths):
|
|
42
|
+
print("Invalid index")
|
|
43
|
+
return
|
|
44
|
+
|
|
45
|
+
target = paths[index]
|
|
46
|
+
full_path = os.path.join(current_dir, target)
|
|
47
|
+
|
|
48
|
+
if os.path.isfile(full_path):
|
|
49
|
+
return full_path
|
|
50
|
+
else:
|
|
51
|
+
print("Not a file")
|
|
52
|
+
|
|
53
|
+
|
index_shell/shell.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import profile
|
|
3
|
+
import subprocess
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import index_shell
|
|
6
|
+
|
|
7
|
+
# Get the terminals installed on the device
|
|
8
|
+
# print(os.environ.get("SHELL"))
|
|
9
|
+
# print(os.environ.get("COMSPEC"))
|
|
10
|
+
|
|
11
|
+
package_dir = Path(index_shell.__file__).resolve().parent
|
|
12
|
+
script_path = package_dir / "cli.py"
|
|
13
|
+
is_Power_Shell = os.environ.get("PSModulePath")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
PWSH_SCRIPT = f"""
|
|
17
|
+
# Add this to your PowerShell profile ($PROFILE)
|
|
18
|
+
Remove-Alias cd -Force -ErrorAction SilentlyContinue
|
|
19
|
+
Remove-Alias ls -Force -ErrorAction SilentlyContinue
|
|
20
|
+
$scriptPath = '{script_path}' # <-- change this
|
|
21
|
+
function ls {{
|
|
22
|
+
python $scriptPath ls $PWD
|
|
23
|
+
}}
|
|
24
|
+
function cd {{
|
|
25
|
+
param([Parameter(ValueFromRemainingArguments)][string[]]$args)
|
|
26
|
+
|
|
27
|
+
if ($args.Count -eq 1 -and $args[0] -match '^\d+$') {{
|
|
28
|
+
$new_dir = python $scriptPath cd ([int]$args[0]) $PWD
|
|
29
|
+
if ($new_dir) {{
|
|
30
|
+
Set-Location $new_dir
|
|
31
|
+
}}
|
|
32
|
+
}} else {{
|
|
33
|
+
Set-Location @args
|
|
34
|
+
}}
|
|
35
|
+
}}
|
|
36
|
+
function nano {{
|
|
37
|
+
param([int]$index)
|
|
38
|
+
$filePath=python $scriptPath nano $index $PWD
|
|
39
|
+
if ($filePath) {{
|
|
40
|
+
notepad $filePath
|
|
41
|
+
}}
|
|
42
|
+
}}
|
|
43
|
+
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def setup_shell():
|
|
48
|
+
|
|
49
|
+
if is_Power_Shell:
|
|
50
|
+
result = subprocess.run(
|
|
51
|
+
["pwsh", "-Command", "$PROFILE"], capture_output=True, text=True
|
|
52
|
+
)
|
|
53
|
+
profile_path = result.stdout.strip()
|
|
54
|
+
|
|
55
|
+
profile_path = Path(profile_path)
|
|
56
|
+
with open(profile_path, "a", encoding="utf-8") as f:
|
|
57
|
+
f.write(f"\n{PWSH_SCRIPT}")
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
index_shell/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
index_shell/cli.py,sha256=sYf2DlLUjG8oYutYmvPMENekQd8CWXQNh16UbanzT2w,632
|
|
3
|
+
index_shell/core.py,sha256=BB8QmK7CVZ63ehOe1a7qtLvXiJJaWouAn7tr2_SYsYI,1235
|
|
4
|
+
index_shell/shell.py,sha256=PCGgKg8-dRwrwpShL4PwVxQfaQopeSvXboSdtTBxTvg,1516
|
|
5
|
+
index_shell-0.1.0.dist-info/METADATA,sha256=-IVrM9Enm8GjmkOLHH6Umgbcfhx7Lq-gtjruivmsI_M,121
|
|
6
|
+
index_shell-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
7
|
+
index_shell-0.1.0.dist-info/entry_points.txt,sha256=h438CVbhtczv_9BEXzB6O2GcwhZSFo9_9-rR--Vh0k8,161
|
|
8
|
+
index_shell-0.1.0.dist-info/top_level.txt,sha256=gFHuWv5D3B9-OX0SGGx482UvzeY2qNC_Ec-ek-E1Co4,12
|
|
9
|
+
index_shell-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
index_shell
|