machineconfig 1.7__py3-none-any.whl → 1.9__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.
Potentially problematic release.
This version of machineconfig might be problematic. Click here for more details.
- machineconfig/__init__.py +4 -2
- machineconfig/jobs/python/check_installations.py +38 -32
- machineconfig/jobs/python/create_bootable_media.py +4 -4
- machineconfig/jobs/python/create_zellij_template.py +3 -2
- machineconfig/jobs/python/python_cargo_build_share.py +14 -9
- machineconfig/jobs/python/python_ve_symlink.py +6 -6
- machineconfig/jobs/python_custom_installers/azuredatastudio.py +36 -0
- machineconfig/jobs/python_custom_installers/bypass_paywall.py +30 -0
- machineconfig/jobs/{python_linux_installers/dev → python_custom_installers}/docker_desktop.py +15 -4
- machineconfig/jobs/python_custom_installers/gh.py +53 -0
- machineconfig/jobs/python_custom_installers/goes.py +35 -0
- machineconfig/jobs/python_custom_installers/helix.py +43 -0
- machineconfig/jobs/python_custom_installers/lvim.py +48 -0
- machineconfig/jobs/python_custom_installers/ngrok.py +39 -0
- machineconfig/jobs/python_custom_installers/nvim.py +48 -0
- machineconfig/jobs/python_custom_installers/vscode.py +45 -0
- machineconfig/jobs/python_custom_installers/wezterm.py +41 -0
- machineconfig/profile/create.py +12 -7
- machineconfig/profile/shell.py +15 -13
- machineconfig/scripts/python/choose_wezterm_theme.py +96 -0
- machineconfig/scripts/python/cloud_copy.py +18 -13
- machineconfig/scripts/python/cloud_mount.py +41 -15
- machineconfig/scripts/python/cloud_repo_sync.py +57 -31
- machineconfig/scripts/python/cloud_sync.py +13 -15
- machineconfig/scripts/python/croshell.py +19 -10
- machineconfig/scripts/python/devops.py +22 -6
- machineconfig/scripts/python/devops_add_identity.py +7 -6
- machineconfig/scripts/python/devops_add_ssh_key.py +10 -9
- machineconfig/scripts/python/devops_backup_retrieve.py +5 -5
- machineconfig/scripts/python/devops_devapps_install.py +24 -19
- machineconfig/scripts/python/devops_update_repos.py +5 -4
- machineconfig/scripts/python/dotfile.py +8 -4
- machineconfig/scripts/python/fire_jobs.py +165 -55
- machineconfig/scripts/python/ftpx.py +18 -8
- machineconfig/scripts/python/mount_nfs.py +13 -10
- machineconfig/scripts/python/mount_nw_drive.py +4 -3
- machineconfig/scripts/python/mount_ssh.py +8 -5
- machineconfig/scripts/python/repos.py +26 -21
- machineconfig/scripts/python/snapshot.py +2 -2
- machineconfig/scripts/python/start_slidev.py +104 -0
- machineconfig/scripts/python/start_terminals.py +1 -1
- machineconfig/setup_windows/wt_and_pwsh/set_pwsh_theme.py +20 -34
- machineconfig/setup_windows/wt_and_pwsh/set_wt_settings.py +11 -12
- machineconfig/utils/installer.py +177 -217
- machineconfig/utils/scheduling.py +1 -1
- machineconfig/utils/utils.py +107 -54
- machineconfig/utils/ve.py +120 -16
- machineconfig-1.9.dist-info/LICENSE +201 -0
- {machineconfig-1.7.dist-info → machineconfig-1.9.dist-info}/METADATA +155 -140
- machineconfig-1.9.dist-info/RECORD +76 -0
- {machineconfig-1.7.dist-info → machineconfig-1.9.dist-info}/WHEEL +1 -1
- machineconfig/jobs/python_generic_installers/archive/gopass.py +0 -18
- machineconfig/jobs/python_generic_installers/archive/nvim.py +0 -20
- machineconfig/jobs/python_generic_installers/archive/opencommit.py +0 -25
- machineconfig/jobs/python_generic_installers/archive/strongbox.py +0 -33
- machineconfig/jobs/python_generic_installers/dev/__init__.py +0 -0
- machineconfig/jobs/python_linux_installers/archive/__init__.py +0 -0
- machineconfig/jobs/python_linux_installers/archive/bandwhich.py +0 -14
- machineconfig/jobs/python_linux_installers/archive/ranger.py +0 -19
- machineconfig/jobs/python_linux_installers/dev/azure_data_studio.py +0 -21
- machineconfig/jobs/python_linux_installers/dev/bytehound.py +0 -20
- machineconfig/jobs/python_linux_installers/dev/nnn.py +0 -22
- machineconfig/jobs/python_windows_installers/archive/ntop.py +0 -21
- machineconfig/jobs/python_windows_installers/dev/bypass_paywall.py +0 -22
- machineconfig/jobs/python_windows_installers/dev/obs_background_removal_plugin.py +0 -22
- machineconfig/scripts/python/choose_ohmybash_theme.py +0 -31
- machineconfig/scripts/python/choose_ohmyposh_theme.py +0 -57
- machineconfig/utils/pandas_type.py +0 -37
- machineconfig/utils/to_exe.py +0 -7
- machineconfig-1.7.dist-info/RECORD +0 -81
- /machineconfig/jobs/{python_generic_installers/archive → python_custom_installers}/__init__.py +0 -0
- {machineconfig-1.7.dist-info → machineconfig-1.9.dist-info}/top_level.txt +0 -0
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
|
|
2
2
|
"""Repos
|
|
3
|
+
|
|
4
|
+
# TODO use gh api user --jq '.login' to get the username and use it to clone the repos.
|
|
5
|
+
in the event that username@github.com is not mentioned in the remote url.
|
|
6
|
+
|
|
3
7
|
"""
|
|
4
8
|
|
|
5
|
-
import crocodile.toolbox as tb
|
|
6
|
-
import argparse
|
|
7
|
-
from machineconfig.utils.utils import write_shell_script, CONFIG_PATH, DEFAULTS_PATH
|
|
8
9
|
from rich import print as pprint
|
|
10
|
+
from machineconfig.utils.utils import write_shell_script, CONFIG_PATH, DEFAULTS_PATH
|
|
11
|
+
from crocodile.file_management import P, install_n_import, Read, Save
|
|
12
|
+
from crocodile.core import randstr
|
|
13
|
+
import argparse
|
|
9
14
|
from dataclasses import dataclass
|
|
10
15
|
from enum import Enum
|
|
11
16
|
from typing import Optional, Any
|
|
12
|
-
# tm =
|
|
17
|
+
# tm = Terminal()
|
|
13
18
|
|
|
14
19
|
|
|
15
20
|
class GitAction(Enum):
|
|
@@ -26,7 +31,7 @@ class RepoRecord:
|
|
|
26
31
|
version: dict[str, str]
|
|
27
32
|
|
|
28
33
|
|
|
29
|
-
def git_action(path:
|
|
34
|
+
def git_action(path: P, action: GitAction, mess: Optional[str] = None, r: bool = False) -> str:
|
|
30
35
|
from git.exc import InvalidGitRepositoryError
|
|
31
36
|
from git.repo import Repo
|
|
32
37
|
try:
|
|
@@ -43,7 +48,7 @@ echo '>>>>>>>>> {action}'
|
|
|
43
48
|
cd '{path}'
|
|
44
49
|
'''
|
|
45
50
|
if action == GitAction.commit:
|
|
46
|
-
if mess is None: mess = "auto_commit_" +
|
|
51
|
+
if mess is None: mess = "auto_commit_" + randstr()
|
|
47
52
|
program += f'''
|
|
48
53
|
git add .; git commit -am "{mess}"
|
|
49
54
|
'''
|
|
@@ -76,19 +81,19 @@ def main():
|
|
|
76
81
|
parser.add_argument("--cloud", "-c", help=f"cloud", default=None)
|
|
77
82
|
args = parser.parse_args()
|
|
78
83
|
|
|
79
|
-
if args.directory == "": repos_root =
|
|
80
|
-
else: repos_root =
|
|
81
|
-
_ =
|
|
84
|
+
if args.directory == "": repos_root = P.home().joinpath("code") # it is a positional argument, can never be empty.
|
|
85
|
+
else: repos_root = P(args.directory).expanduser().absolute()
|
|
86
|
+
_ = install_n_import("git", "gitpython")
|
|
82
87
|
|
|
83
88
|
program = ""
|
|
84
89
|
if args.record:
|
|
85
90
|
res = record_repos(repos_root=str(repos_root))
|
|
86
91
|
pprint(f"Recorded repositories:\n", res)
|
|
87
92
|
save_path = CONFIG_PATH.joinpath("repos").joinpath(repos_root.rel2home()).joinpath("repos.json")
|
|
88
|
-
#
|
|
89
|
-
|
|
90
|
-
pprint(f"Result pickled at {
|
|
91
|
-
if args.cloud is not None:
|
|
93
|
+
# Save.pickle(obj=res, path=save_path)
|
|
94
|
+
Save.json(obj=res, path=save_path)
|
|
95
|
+
pprint(f"Result pickled at {P(save_path)}")
|
|
96
|
+
if args.cloud is not None: P(save_path).to_cloud(rel2home=True, cloud=args.cloud)
|
|
92
97
|
program += f"""\necho '>>>>>>>>> Finished Recording'\n"""
|
|
93
98
|
elif args.clone or args.checkout or args.checkout_to_branch:
|
|
94
99
|
# preferred_remote = input("Enter preferred remote to use (default: None): ") or ""
|
|
@@ -97,7 +102,7 @@ def main():
|
|
|
97
102
|
repos_root = CONFIG_PATH.joinpath("repos").joinpath(repos_root.rel2home()).joinpath("repos.json")
|
|
98
103
|
if not repos_root.exists():
|
|
99
104
|
if args.cloud is None:
|
|
100
|
-
cloud: str =
|
|
105
|
+
cloud: str = Read.ini(DEFAULTS_PATH)['general']['rclone_config_name']
|
|
101
106
|
print(f"⚠️ Using default cloud: {cloud}")
|
|
102
107
|
else:
|
|
103
108
|
cloud = args.cloud
|
|
@@ -118,7 +123,7 @@ def main():
|
|
|
118
123
|
|
|
119
124
|
|
|
120
125
|
def record_repos(repos_root: str, r: bool = True) -> list[dict[str, Any]]:
|
|
121
|
-
path_obj =
|
|
126
|
+
path_obj = P(repos_root).expanduser().absolute()
|
|
122
127
|
if path_obj.is_file(): return []
|
|
123
128
|
search_res = path_obj.search("*", files=False)
|
|
124
129
|
res: list[dict[str, Any]] = []
|
|
@@ -130,10 +135,10 @@ def record_repos(repos_root: str, r: bool = True) -> list[dict[str, Any]]:
|
|
|
130
135
|
return res
|
|
131
136
|
|
|
132
137
|
|
|
133
|
-
def record_a_repo(path:
|
|
138
|
+
def record_a_repo(path: P, search_parent_directories: bool = False, preferred_remote: Optional[str] = None):
|
|
134
139
|
from git.repo import Repo
|
|
135
140
|
repo = Repo(path, search_parent_directories=search_parent_directories) # get list of remotes using git python
|
|
136
|
-
repo_root =
|
|
141
|
+
repo_root = P(repo.working_dir).absolute()
|
|
137
142
|
remotes = {remote.name: remote.url for remote in repo.remotes}
|
|
138
143
|
if preferred_remote is not None:
|
|
139
144
|
if preferred_remote in remotes: remotes = {preferred_remote: remotes[preferred_remote]}
|
|
@@ -157,17 +162,17 @@ def record_a_repo(path: tb.P, search_parent_directories: bool = False, preferred
|
|
|
157
162
|
|
|
158
163
|
def install_repos(specs_path: str, clone: bool = True, checkout_to_recorded_commit: bool = False, checkout_to_branch: bool = False, editable_install: bool = False, preferred_remote: Optional[str] = None):
|
|
159
164
|
program = ""
|
|
160
|
-
path_obj =
|
|
161
|
-
repos: list[dict[str, Any]] =
|
|
165
|
+
path_obj = P(specs_path).expanduser().absolute()
|
|
166
|
+
repos: list[dict[str, Any]] = Read.json(path_obj)
|
|
162
167
|
for repo in repos:
|
|
163
|
-
parent_dir =
|
|
168
|
+
parent_dir = P(repo["parent_dir"]).expanduser().absolute().create()
|
|
164
169
|
for idx, (remote_name, remote_url) in enumerate(repo["remotes"].items()):
|
|
165
170
|
if clone:
|
|
166
171
|
if idx == 0: # clone
|
|
167
172
|
if preferred_remote is not None:
|
|
168
173
|
if preferred_remote in repo["remotes"]:
|
|
169
174
|
remote_name = preferred_remote
|
|
170
|
-
remote_url
|
|
175
|
+
remote_url = repo["remotes"][preferred_remote]
|
|
171
176
|
else:
|
|
172
177
|
print(f"⚠️ `{preferred_remote=}` not found in {repo['remotes']}.")
|
|
173
178
|
# preferred_remote = None
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
from crocodile.msc.odds import capture_from_webcam
|
|
3
|
-
|
|
3
|
+
from crocodile.meta import Terminal
|
|
4
4
|
import argparse
|
|
5
5
|
|
|
6
6
|
|
|
@@ -11,7 +11,7 @@ def main():
|
|
|
11
11
|
|
|
12
12
|
img_path = capture_from_webcam(show=False, wait=False, save=True)
|
|
13
13
|
if args.to_text:
|
|
14
|
-
q =
|
|
14
|
+
q = Terminal().run(f"cd ~/AppData/Local/Tesseract-OCR; pytesseract '{img_path}'", shell="pwsh").capture().op
|
|
15
15
|
print(q)
|
|
16
16
|
else:
|
|
17
17
|
print(img_path)
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
|
|
2
|
+
"""
|
|
3
|
+
slidev
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from machineconfig.utils.utils import CONFIG_PATH, PROGRAM_PATH, print_code
|
|
7
|
+
from crocodile.meta import Terminal, P
|
|
8
|
+
# from crocodile.environment import get_network_addresses
|
|
9
|
+
import subprocess
|
|
10
|
+
import platform
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
PORT_DEFAULT = 3030
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
SLIDEV_REPO = CONFIG_PATH.joinpath(".cache/slidev")
|
|
17
|
+
if not SLIDEV_REPO.joinpath("components").exists():
|
|
18
|
+
# assert slidev is installed first
|
|
19
|
+
Terminal(stderr=subprocess.PIPE, stdin=subprocess.PIPE, stdout=subprocess.PIPE).run(f"cd {SLIDEV_REPO.parent};npm init slidev")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def jupyter_to_markdown(file: P):
|
|
23
|
+
op_dir = file.parent.joinpath("presentation")
|
|
24
|
+
|
|
25
|
+
# https://nbconvert.readthedocs.io/en/latest/nbconvert_library.html
|
|
26
|
+
# from nbconvert.exporters.markdown import MarkdownExporter
|
|
27
|
+
# import nbformat
|
|
28
|
+
# nb = nbformat.read(file, as_version=4)
|
|
29
|
+
# assert isinstance(nb, nbformat.notebooknode.NotebookNode), f"{file} is not a notebook"
|
|
30
|
+
# e = MarkdownExporter(exclude_input=True, exclude_input_prompt=True, exclude_output_prompt=True)
|
|
31
|
+
# body, resources = e.from_notebook_node(nb=nb)
|
|
32
|
+
# op_dir.joinpath("slides_raw.md").write_text(body)
|
|
33
|
+
# for key, value in resources['outputs'].items():
|
|
34
|
+
|
|
35
|
+
cmd = f"jupyter nbconvert --to markdown --no-prompt --no-input --output-dir {op_dir} --output slides_raw.md {file}"
|
|
36
|
+
Terminal().run(cmd, shell="powershell").print()
|
|
37
|
+
cmd = f"jupyter nbconvert --to html --no-prompt --no-input --output-dir {op_dir} {file}"
|
|
38
|
+
Terminal().run(cmd, shell="powershell").print()
|
|
39
|
+
# cmd = f"jupyter nbconvert --to pdf --no-prompt --no-input --output-dir {op_dir} {file}"
|
|
40
|
+
# Terminal().run(cmd, shell="powershell").print()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
op_file = op_dir.joinpath("slides_raw.md")
|
|
44
|
+
slide_separator = '\n\n---\n\n'
|
|
45
|
+
md = op_file.read_text().replace('\n\n\n\n', slide_separator)
|
|
46
|
+
md = slide_separator.join([item for item in md.split(slide_separator) if bool(item.strip())]) # remove empty slides.
|
|
47
|
+
op_file.with_name("slides.md").write_text(md)
|
|
48
|
+
return op_dir
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def main() -> None:
|
|
52
|
+
import argparse
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
parser = argparse.ArgumentParser()
|
|
56
|
+
parser.add_argument("-d", "--directory", default=None, help="Directory of the report")
|
|
57
|
+
parser.add_argument("-j", "--jupyter-file", default=None, help="Jupyter notebook file to convert to slides. If not provided, slides.md is used.")
|
|
58
|
+
parser.add_argument("--port", default=PORT_DEFAULT, help=f"Port to serve the report, default to {PORT_DEFAULT}")
|
|
59
|
+
args = parser.parse_args()
|
|
60
|
+
|
|
61
|
+
port = args.port
|
|
62
|
+
|
|
63
|
+
if args.jupyter_file is not None:
|
|
64
|
+
report_dir = jupyter_to_markdown(P(args.jupyter_file))
|
|
65
|
+
else:
|
|
66
|
+
if args.directory is None:
|
|
67
|
+
report_dir = P.cwd()
|
|
68
|
+
else:
|
|
69
|
+
report_dir = P(args.directory)
|
|
70
|
+
|
|
71
|
+
assert report_dir.exists(), f"{report_dir} does not exist"
|
|
72
|
+
assert report_dir.is_dir(), f"{report_dir} is not a directory"
|
|
73
|
+
|
|
74
|
+
md_file = report_dir.joinpath("slides.md")
|
|
75
|
+
if not md_file.exists():
|
|
76
|
+
res = report_dir.search("*.md")
|
|
77
|
+
if len(res) == 1:
|
|
78
|
+
md_file = res.list[0]
|
|
79
|
+
else:
|
|
80
|
+
raise FileNotFoundError(f"slides.md not found in {report_dir}")
|
|
81
|
+
|
|
82
|
+
report_dir.search().apply(lambda x: x.copy(folder=SLIDEV_REPO, overwrite=True))
|
|
83
|
+
if md_file.name != "slides.md":
|
|
84
|
+
SLIDEV_REPO.joinpath(md_file.name).with_name(name="slides.md", inplace=True, overwrite=True)
|
|
85
|
+
|
|
86
|
+
# from machineconfig.utils.utils import check_tool_exists
|
|
87
|
+
# check_tool_exists(tool_name="slidev", install_script="npm i -g @slidev/cli")
|
|
88
|
+
|
|
89
|
+
import socket
|
|
90
|
+
try: local_ip_v4 = socket.gethostbyname(socket.gethostname() + ".local") # without .local, in linux machines, '/etc/hosts' file content, you have an IP address mapping with '127.0.1.1' to your hostname
|
|
91
|
+
except Exception:
|
|
92
|
+
print(f"Warning: Could not get local_ip_v4. This is probably because you are running a WSL instance") # TODO find a way to get the local_ip_v4 in WSL
|
|
93
|
+
local_ip_v4 = socket.gethostbyname(socket.gethostname())
|
|
94
|
+
|
|
95
|
+
print(f"Presentation is served at http://{platform.node()}:{port}")
|
|
96
|
+
print(f"Presentation is served at http://localhost:{port}")
|
|
97
|
+
print(f"Presentation is served at http://{local_ip_v4}:{port}")
|
|
98
|
+
program: str = f"cd {SLIDEV_REPO}; slidev --port {port} --remote 0.0.0.0; cd {P.cwd()}"
|
|
99
|
+
PROGRAM_PATH.write_text(program)
|
|
100
|
+
print_code(program, lexer="bash")
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
if __name__ == '__main__':
|
|
104
|
+
main()
|
|
@@ -9,7 +9,7 @@ from typing import Literal
|
|
|
9
9
|
|
|
10
10
|
COLOR_SCHEMES = ["Campbell", "Campbell Powershell", "Solarized Dark", "Ubuntu-ColorScheme", "Retro"]
|
|
11
11
|
THEMES_ITER = cycle(COLOR_SCHEMES)
|
|
12
|
-
INIT_COMMANDS = ["ls", "lf", "cpufetch", "
|
|
12
|
+
INIT_COMMANDS = ["ls", "lf", "cpufetch", "fastfetch", "btm"]
|
|
13
13
|
INIT_COMMANDS_ITER = cycle(INIT_COMMANDS)
|
|
14
14
|
SIZE_ITER = cycle([0.6, 0.4, 0.3])
|
|
15
15
|
ORIENTATION = ["vertical", "horizontal"]
|
|
@@ -5,53 +5,39 @@ https://glitchbone.github.io/vscode-base16-term/#/3024
|
|
|
5
5
|
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
# import crocodile.environment as env
|
|
8
|
+
|
|
9
|
+
# # import crocodile.environment as env
|
|
10
|
+
from crocodile.file_management import P
|
|
11
|
+
# from crocodile.meta import Terminal
|
|
10
12
|
from machineconfig.utils.utils import LIBRARY_ROOT
|
|
11
|
-
from machineconfig.utils.installer import
|
|
12
|
-
import os
|
|
13
|
+
from machineconfig.utils.installer import Installer
|
|
14
|
+
# import os
|
|
15
|
+
import subprocess
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
nerd_fonts = {
|
|
19
|
+
"repo_url": "https://github.com/ryanoasis/nerd-fonts",
|
|
20
|
+
"doc": "Nerd Fonts is a project that patches developer targeted fonts with a high number of glyphs (icons)",
|
|
21
|
+
"filename_template_windows_amd_64": "CascadiaCode.zip",
|
|
22
|
+
"filename_template_linux_amd_64": "CascadiaCode.zip",
|
|
23
|
+
"strip_v": False,
|
|
24
|
+
"exe_name": "nerd_fonts"
|
|
25
|
+
}
|
|
13
26
|
|
|
14
27
|
|
|
15
28
|
def install_nerd_fonts():
|
|
16
29
|
# Step 1: download the required fonts that has all the glyphs and install them.
|
|
17
|
-
folder =
|
|
18
|
-
if not isinstance(folder, tb.P): raise ValueError(f"Failed to get latest release. Expected a Path object, got {folder}")
|
|
19
|
-
folder = folder.joinpath("CascadiaCode.zip").download().unzip(inplace=True)
|
|
30
|
+
folder, _version_to_be_installed = Installer.from_dict(d=nerd_fonts, name="nerd_fonts").download(version=None)
|
|
20
31
|
folder.search("*Windows*").apply(lambda p: p.delete(sure=True))
|
|
21
32
|
folder.search("*readme*").apply(lambda p: p.delete(sure=True))
|
|
22
33
|
folder.search("*LICENSE*").apply(lambda p: p.delete(sure=True))
|
|
23
|
-
file =
|
|
24
|
-
|
|
34
|
+
file = P.tmpfile(suffix=".ps1").write_text(LIBRARY_ROOT.joinpath("setup_windows/wt_and_pwsh/install_fonts.ps1").read_text().replace(r".\fonts-to-be-installed", str(folder)))
|
|
35
|
+
subprocess.run(rf"powershell.exe -executionpolicy Bypass -nologo -noninteractive -File {file.str}", check=True)
|
|
25
36
|
folder.delete(sure=True)
|
|
26
37
|
|
|
27
38
|
|
|
28
|
-
def change_shell_profile():
|
|
29
|
-
# Customize powershell profile such that it loads oh-my-posh and the terminal icons automatically.
|
|
30
|
-
# Add arrow keys history functionality to the terminal.
|
|
31
|
-
shell = "pwsh"
|
|
32
|
-
profile_path = tb.Terminal().run("$profile", shell=shell).op2path()
|
|
33
|
-
assert isinstance(profile_path, tb.P), f"Could not find profile path for {shell}."
|
|
34
|
-
local_app_data = os.getenv("LOCALAPPDATA")
|
|
35
|
-
if not isinstance(local_app_data, str):
|
|
36
|
-
raise ValueError("Could not find LOCALAPPDATA environment variable.")
|
|
37
|
-
theme_path = tb.P(local_app_data).joinpath(r"Programs\oh-my-posh\themes").collapseuser().as_posix().replace("~", "$env:USERPROFILE") # organization machine with homeshare confuse H: with ~.
|
|
38
|
-
txt = f"""
|
|
39
|
-
oh-my-posh --init --shell pwsh --config {theme_path}/jandedobbeleer.omp.json | Invoke-Expression
|
|
40
|
-
Import-Module -Name Terminal-Icons
|
|
41
|
-
|
|
42
|
-
# Shows navigable menu of all options when hitting Tab
|
|
43
|
-
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
|
|
44
|
-
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
|
|
45
|
-
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
|
|
46
|
-
Set-PSReadlineOption -PredictionViewStyle History
|
|
47
|
-
# see dynamic help with prerelease.
|
|
48
|
-
"""
|
|
49
|
-
profile_path.modify_text(txt_search=txt, txt_alt=txt, replace_line=True, notfound_append=True)
|
|
50
|
-
|
|
51
|
-
|
|
52
39
|
def main():
|
|
53
40
|
install_nerd_fonts()
|
|
54
|
-
change_shell_profile()
|
|
55
41
|
|
|
56
42
|
|
|
57
43
|
if __name__ == '__main__':
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
"""Set Windows Terminal Settings
|
|
3
3
|
"""
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
from crocodile.core import randstr, List as L
|
|
6
|
+
from crocodile.file_management import P, Read, Save
|
|
5
7
|
import crocodile.environment as env
|
|
8
|
+
from machineconfig.utils.utils import LIBRARY_ROOT
|
|
6
9
|
from uuid import uuid4
|
|
7
10
|
import os
|
|
8
11
|
from typing import Any
|
|
@@ -27,14 +30,14 @@ class TerminalSettings(object):
|
|
|
27
30
|
tmp = os.getenv("LOCALAPPDATA")
|
|
28
31
|
if not isinstance(tmp, str):
|
|
29
32
|
raise ValueError("Could not find LOCALAPPDATA environment variable.")
|
|
30
|
-
self.path =
|
|
31
|
-
self.path.copy(append=".orig_" +
|
|
32
|
-
self.dat = self.path
|
|
33
|
-
self.profs =
|
|
33
|
+
self.path = P(tmp).joinpath(r"Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json")
|
|
34
|
+
self.path.copy(append=".orig_" + randstr())
|
|
35
|
+
self.dat: dict[str, Any] = Read.json(self.path)
|
|
36
|
+
self.profs = L(self.dat["profiles"]["list"])
|
|
34
37
|
|
|
35
38
|
def save_terminal_settings(self):
|
|
36
39
|
self.dat["profiles"]["list"] = list(self.profs)
|
|
37
|
-
self.dat
|
|
40
|
+
Save.json(obj=self.dat, path=self.path, indent=5)
|
|
38
41
|
|
|
39
42
|
# ========================= Terminal Settings =========================================
|
|
40
43
|
def update_default_settings(self):
|
|
@@ -73,14 +76,10 @@ class TerminalSettings(object):
|
|
|
73
76
|
else: print("Powershell profile was not found in the list of profile and therefore was not made the deafult.")
|
|
74
77
|
|
|
75
78
|
def add_croshell(self):
|
|
76
|
-
# Adding croshell if it is not there.
|
|
77
|
-
# py_pr = tb.copy.deepcopy(pr) # use it as a template for the new profile.
|
|
78
|
-
import machineconfig
|
|
79
|
-
lib_root = tb.P(machineconfig.__file__).parent.collapseuser().as_posix()
|
|
80
79
|
croshell = dict(name="croshell",
|
|
81
80
|
guid="{" + str(uuid4()) + "}",
|
|
82
81
|
# commandline=f"powershell.exe -Command \"{activate} ipython -i -c 'from crocodile.toolbox import *'\"",
|
|
83
|
-
commandline=f'powershell.exe -Command "{
|
|
82
|
+
commandline=f'powershell.exe -Command "{LIBRARY_ROOT.as_posix()}/scripts/windows/croshell.ps1"',
|
|
84
83
|
startingDirectory="%USERPROFILE%", # "%USERPROFILE%", # None: inherent from parent process.
|
|
85
84
|
)
|
|
86
85
|
# startingDirectory = None means: inheret from parent process, which will is the default, which point to /System32
|
|
@@ -114,7 +113,7 @@ class TerminalSettings(object):
|
|
|
114
113
|
elif name == "Command Prompt": cmd = profile
|
|
115
114
|
elif name == "Azure Cloud Shell": azure = profile
|
|
116
115
|
else: others.append(profile)
|
|
117
|
-
self.profs =
|
|
116
|
+
self.profs = L([item for item in [pwsh, croshell, ubuntu, wpwsh, cmd, azure] + others if item is not None])
|
|
118
117
|
|
|
119
118
|
|
|
120
119
|
def main():
|