-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_ready.py
More file actions
980 lines (830 loc) · 30.2 KB
/
get_ready.py
File metadata and controls
980 lines (830 loc) · 30.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
#!/usr/bin/env python3
"""
get_ready.py -- installer / uninstaller for `get`.
Run this script to install `get` on your system. If `get` is already
installed, running the script again provides the option to uninstall.
Expected layout next to this script:
get_ready.py
get (Linux binary)
get.exe (Windows binary)
get.1 (Linux man page, optional)
bin/ (optional extra tools directory)
"""
from __future__ import annotations
import ctypes
import getpass
import os
import platform
import shutil
import subprocess
import sys
from pathlib import Path
from typing import Iterable
# ---------------------------------------------------------------------------
# Platform constants
# ---------------------------------------------------------------------------
IS_WINDOWS: bool = os.name == "nt"
IS_LINUX: bool = sys.platform.startswith("linux")
SCRIPT_DIR: Path = Path(__file__).resolve().parent
RC_MARK_BEGIN: str = "# >>> get installer >>>"
RC_MARK_END: str = "# <<< get installer <<<"
PROJECT_TAGLINE: str = "get -- get anything from your computer"
PROJECT_GITHUB: str = "https://github.com/Water-Run/get"
DEFAULT_SHELL: str = "powershell" if IS_WINDOWS else "bash"
DEFAULT_URL: str = "https://api.poe.com/v1"
DEFAULT_MODEL: str = "gpt-5.3-codex"
# ---------------------------------------------------------------------------
# ANSI colors
# ---------------------------------------------------------------------------
class Color:
RESET = "\033[0m"
BOLD = "\033[1m"
DIM = "\033[2m"
RED = "\033[31m"
GREEN = "\033[32m"
YELLOW = "\033[33m"
BLUE = "\033[34m"
MAGENTA = "\033[35m"
CYAN = "\033[36m"
def _disable_colors() -> None:
for name in list(vars(Color)):
if not name.startswith("_"):
setattr(Color, name, "")
def _enable_ansi() -> None:
if not sys.stdout.isatty():
_disable_colors()
return
if IS_WINDOWS:
try:
kernel32 = ctypes.windll.kernel32
handle = kernel32.GetStdHandle(-11)
mode = ctypes.c_ulong()
kernel32.GetConsoleMode(handle, ctypes.byref(mode))
kernel32.SetConsoleMode(handle, mode.value | 0x0004)
except Exception:
_disable_colors()
# ---------------------------------------------------------------------------
# Output helpers
# ---------------------------------------------------------------------------
def info(msg: str) -> None:
print(f" {Color.CYAN}{Color.BOLD}info:{Color.RESET} {msg}")
def warn(msg: str) -> None:
print(f" {Color.YELLOW}{Color.BOLD}warn:{Color.RESET} {msg}")
def fail(msg: str) -> None:
print(f" {Color.RED}{Color.BOLD}error:{Color.RESET} {msg}", file=sys.stderr)
def step(msg: str) -> None:
print(f" {Color.BLUE}{Color.BOLD}-->{Color.RESET} {msg}")
def good(msg: str) -> None:
print(f" {Color.GREEN}{Color.BOLD}[ok]{Color.RESET} {msg}")
def bad(msg: str) -> None:
print(f" {Color.RED}{Color.BOLD}[fail]{Color.RESET} {msg}")
def banner(title: str) -> None:
inner = 58
bar = "-" * inner
pad = inner - len(title) - 2
lp = max(pad // 2, 0)
rp = max(pad - lp, 0)
print()
print(f"{Color.CYAN}{Color.BOLD}+{bar}+{Color.RESET}")
print(
f"{Color.CYAN}{Color.BOLD}|{Color.RESET}"
f"{' ' * (lp + 1)}{Color.BOLD}{title}{Color.RESET}{' ' * (rp + 1)}"
f"{Color.CYAN}{Color.BOLD}|{Color.RESET}"
)
print(f"{Color.CYAN}{Color.BOLD}+{bar}+{Color.RESET}")
print()
def _print_github() -> None:
print()
print(f" {Color.DIM}{PROJECT_GITHUB}{Color.RESET}")
print()
# ---------------------------------------------------------------------------
# Input helpers
# ---------------------------------------------------------------------------
def ask_yes_no(prompt: str, default: str = "y") -> bool:
suffix = "[Y/n]" if default.lower() == "y" else "[y/N]"
while True:
try:
reply = input(
f" {Color.BOLD}?{Color.RESET} {prompt} "
f"{Color.DIM}{suffix}{Color.RESET} "
).strip().lower()
except EOFError:
reply = ""
if not reply:
reply = default.lower()
if reply in ("y", "yes"):
return True
if reply in ("n", "no"):
return False
def ask_input(prompt: str, hint: str = "") -> str:
hint_str = f" {Color.DIM}[{hint}]{Color.RESET}" if hint else ""
try:
reply = input(
f" {Color.BOLD}>{Color.RESET} {prompt}{hint_str}: "
).strip()
except EOFError:
reply = ""
return reply
def ask_secret(prompt: str, hint: str = "") -> str:
"""Prompt for sensitive text without echoing the input."""
hint_str = f" [{hint}]" if hint else ""
try:
reply = getpass.getpass(f" > {prompt}{hint_str}: ").strip()
except Exception:
reply = ask_input(prompt, hint=hint)
return reply
def ask_choice(prompt: str, options: list[tuple[str, str, str]]) -> str:
"""Present a numbered menu and return the key of the selected option."""
print()
print(f" {Color.BOLD}{prompt}{Color.RESET}")
for idx, (_, label, desc) in enumerate(options, 1):
print(f" {Color.BOLD}{idx}){Color.RESET} {label}")
if desc:
print(f" {Color.DIM}{desc}{Color.RESET}")
while True:
try:
reply = input(
f"\n {Color.BOLD}>{Color.RESET} "
f"Select [1-{len(options)}]: "
).strip()
except EOFError:
reply = "1"
if reply.isdigit() and 1 <= int(reply) <= len(options):
return options[int(reply) - 1][0]
# ---------------------------------------------------------------------------
# System check
# ---------------------------------------------------------------------------
def check_system() -> None:
step("Checking system compatibility")
if IS_WINDOWS:
v = sys.getwindowsversion()
if v.major < 10:
bad(f"Windows {v.major}.{v.minor} -- Windows 10 or later is required")
sys.exit(1)
good(f"Windows {v.major}.{v.minor} (build {v.build})")
elif IS_LINUX:
release = platform.release()
try:
major = int(release.split(".", 1)[0])
except ValueError:
major = 0
if major < 6:
bad(f"Linux kernel {release} -- kernel 6 or later is required")
sys.exit(1)
good(f"Linux kernel {release}")
else:
bad(f"Unsupported platform: {sys.platform}")
sys.exit(1)
# ---------------------------------------------------------------------------
# Install paths
# ---------------------------------------------------------------------------
def install_paths() -> dict:
if IS_WINDOWS:
localappdata = os.environ.get("LOCALAPPDATA") or str(
Path.home() / "AppData" / "Local"
)
base = Path(localappdata) / "Programs" / "get"
return {
"root": base,
"binary": base / "get.exe",
"extra_bin": base / "bin",
"man": None,
"path_dirs": [base, base / "bin"],
}
home = Path.home()
local = home / ".local"
return {
"root": local / "share" / "get",
"binary": local / "bin" / "get",
"extra_bin": local / "share" / "get" / "bin",
"man": local / "share" / "man" / "man1" / "get.1",
"path_dirs": [local / "bin", local / "share" / "get" / "bin"],
}
def find_installed() -> "Path | None":
paths = install_paths()
if paths["binary"].exists():
return paths["binary"]
found = shutil.which("get")
if found:
resolved = Path(found).resolve()
if resolved.parent != SCRIPT_DIR:
return resolved
return None
# ---------------------------------------------------------------------------
# File helpers
# ---------------------------------------------------------------------------
def copy_file(src: Path, dst: Path) -> None:
dst.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(src, dst)
if not IS_WINDOWS:
os.chmod(dst, 0o755)
def remove_file(p: Path) -> None:
if not p.exists():
return
step(f"Removing {p}")
try:
p.unlink()
good("Removed")
except OSError as e:
bad(f"Failed: {e}")
def prune_empty_parents(start: Path, stop_at: Path) -> None:
try:
stop_at = stop_at.resolve()
except OSError:
return
cur = start
while cur.exists() and cur.resolve() != stop_at:
try:
cur.rmdir()
except OSError:
break
cur = cur.parent
# ---------------------------------------------------------------------------
# PATH management
# ---------------------------------------------------------------------------
def _notify_env_change_windows() -> None:
try:
result = ctypes.c_long()
ctypes.windll.user32.SendMessageTimeoutW(
0xFFFF, 0x1A, 0, "Environment", 0x0002, 5000,
ctypes.byref(result),
)
except Exception:
pass
def path_add_windows(dirs: Iterable[Path]) -> bool:
import winreg
changed = False
with winreg.OpenKey(
winreg.HKEY_CURRENT_USER, "Environment",
0, winreg.KEY_READ | winreg.KEY_WRITE,
) as k:
try:
current, _ = winreg.QueryValueEx(k, "Path")
except FileNotFoundError:
current = ""
parts = [p for p in current.split(";") if p]
existing = {p.lower() for p in parts}
for d in dirs:
value = str(d)
if value.lower() not in existing:
parts.append(value)
existing.add(value.lower())
changed = True
if changed:
winreg.SetValueEx(
k, "Path", 0, winreg.REG_EXPAND_SZ, ";".join(parts))
_notify_env_change_windows()
return changed
def path_remove_windows(dirs: Iterable[Path]) -> bool:
import winreg
targets = {str(d).lower() for d in dirs}
with winreg.OpenKey(
winreg.HKEY_CURRENT_USER, "Environment",
0, winreg.KEY_READ | winreg.KEY_WRITE,
) as k:
try:
current, _ = winreg.QueryValueEx(k, "Path")
except FileNotFoundError:
return False
parts = [p for p in current.split(";") if p]
kept = [p for p in parts if p.lower() not in targets]
if len(kept) == len(parts):
return False
winreg.SetValueEx(k, "Path", 0, winreg.REG_EXPAND_SZ, ";".join(kept))
_notify_env_change_windows()
return True
def path_add_linux(dirs: Iterable[Path]) -> bool:
lines = [RC_MARK_BEGIN]
for d in dirs:
lines.append(
f'case ":$PATH:" in *":{d}:"*) ;; '
f'*) export PATH="{d}:$PATH" ;; esac'
)
lines.append(RC_MARK_END)
block = "\n" + "\n".join(lines) + "\n"
changed = False
home = Path.home()
for rc in (home / ".profile", home / ".bashrc", home / ".zshrc"):
if not rc.exists() and rc.name != ".profile":
continue
content = rc.read_text() if rc.exists() else ""
if RC_MARK_BEGIN in content:
continue
with rc.open("a") as f:
f.write(block)
changed = True
return changed
def path_remove_linux() -> bool:
changed = False
home = Path.home()
for rc in (home / ".profile", home / ".bashrc", home / ".zshrc"):
if not rc.exists():
continue
content = rc.read_text()
if RC_MARK_BEGIN not in content:
continue
kept: list[str] = []
skip = False
for line in content.splitlines(keepends=True):
if RC_MARK_BEGIN in line:
skip = True
continue
if RC_MARK_END in line:
skip = False
continue
if not skip:
kept.append(line)
rc.write_text("".join(kept).rstrip() + "\n")
changed = True
return changed
def add_to_path(dirs: list[Path]) -> bool:
return path_add_windows(dirs) if IS_WINDOWS else path_add_linux(dirs)
def remove_from_path(dirs: list[Path]) -> bool:
return path_remove_windows(dirs) if IS_WINDOWS else path_remove_linux()
# ---------------------------------------------------------------------------
# get binary invocation
# ---------------------------------------------------------------------------
def run_get(binary: Path, *args: str) -> bool:
"""
Invoke the installed get binary and return True on success.
The value following a 'key' argument is masked in diagnostic output.
"""
display_args: list[str] = []
for i, a in enumerate(args):
if i > 0 and args[i - 1] == "key":
display_args.append("<hidden>")
else:
display_args.append(a)
cmd_display = "get " + " ".join(display_args)
try:
result = subprocess.run(
[str(binary), *args],
capture_output=True,
text=True,
timeout=15,
)
if result.returncode == 0:
return True
raw = result.stderr.strip() or result.stdout.strip() or "(no output)"
bad(f"'{cmd_display}' returned non-zero: {raw}")
return False
except FileNotFoundError:
bad(f"Binary not found: {binary}")
return False
except subprocess.TimeoutExpired:
bad(f"'{cmd_display}' timed out")
return False
except Exception as exc:
bad(f"Unexpected error: {exc}")
return False
# ---------------------------------------------------------------------------
# Shell detection
# ---------------------------------------------------------------------------
# Only these shells are auto-detected. Anything else -> return None ->
# configure_shell() keeps the built-in default and makes no changes.
_LINUX_SHELLS = ("bash", "zsh", "fish")
_WINDOWS_SHELLS = ("powershell", "pwsh", "cmd")
def _normalize_name(raw: str, allowed: tuple) -> "str | None":
"""Map a raw process/executable name to an allowed shell identifier."""
if not raw:
return None
name = Path(raw.strip()).name.lower()
# Strip leading dash from login shells, e.g. "-bash"
name = name.lstrip("-")
# Strip Windows .exe suffix
if name.endswith(".exe"):
name = name[:-4]
# Handle version-suffixed names, e.g. "bash-5.2"
base = name.split("-", 1)[0].split(".", 1)[0]
for known in allowed:
if name == known or base == known:
return known
return None
def _linux_shell_from_parent() -> "str | None":
"""Read /proc/<ppid>/comm to identify the running interactive shell."""
try:
ppid = os.getppid()
comm = Path(f"/proc/{ppid}/comm")
if comm.exists():
name = _normalize_name(comm.read_text(), _LINUX_SHELLS)
if name:
return name
exe = Path(f"/proc/{ppid}/exe")
if exe.exists():
name = _normalize_name(os.readlink(exe), _LINUX_SHELLS)
if name:
return name
except Exception:
pass
return None
def _linux_shell_from_env() -> "str | None":
return _normalize_name(os.environ.get("SHELL", ""), _LINUX_SHELLS)
def _linux_shell_from_passwd() -> "str | None":
try:
import pwd
entry = pwd.getpwuid(os.getuid())
return _normalize_name(entry.pw_shell, _LINUX_SHELLS)
except Exception:
return None
def _windows_shell_from_parent() -> "str | None":
"""Identify the parent shell on Windows via WMI / tasklist."""
try:
ppid = os.getppid()
except Exception:
return None
# Try PowerShell's CIM query first -- accurate and usually available.
try:
result = subprocess.run(
[
"powershell", "-NoProfile", "-Command",
f"(Get-CimInstance Win32_Process -Filter 'ProcessId={ppid}')"
".Name",
],
capture_output=True, text=True, timeout=5,
)
if result.returncode == 0:
name = _normalize_name(result.stdout, _WINDOWS_SHELLS)
if name:
return name
except Exception:
pass
# Fallback: tasklist
try:
result = subprocess.run(
["tasklist", "/FI", f"PID eq {ppid}", "/FO", "CSV", "/NH"],
capture_output=True, text=True, timeout=5,
)
if result.returncode == 0 and result.stdout.strip():
# CSV: "image","pid",...
first = result.stdout.strip().splitlines()[0]
image = first.split(",", 1)[0].strip().strip('"')
name = _normalize_name(image, _WINDOWS_SHELLS)
if name:
return name
except Exception:
pass
return None
def _windows_shell_from_env() -> "str | None":
# PowerShell sets PSModulePath; pwsh 7+ also sets POSH_* vars in some setups.
if os.environ.get("PSModulePath"):
# Can't reliably distinguish powershell vs pwsh from env alone,
# assume Windows PowerShell (more common as default shell).
return "powershell"
# ComSpec typically points to cmd.exe when running inside cmd.
comspec = os.environ.get("ComSpec", "")
if comspec and _normalize_name(comspec, _WINDOWS_SHELLS) == "cmd":
return "cmd"
return None
def detect_current_shell() -> "str | None":
"""
Return one of the auto-detectable shells, or None if unknown.
Linux : bash, zsh, fish
Windows : powershell, pwsh, cmd
Any other shell (sh, dash, ksh, tcsh, nushell, xonsh, ...) returns None
so that the caller keeps the built-in default and makes no changes.
"""
if IS_LINUX:
# Parent process is the most reliable source -- correctly handles
# `exec fish` or stale $SHELL after `chsh` without re-login.
return (
_linux_shell_from_parent()
or _linux_shell_from_env()
or _linux_shell_from_passwd()
)
if IS_WINDOWS:
return (
_windows_shell_from_parent()
or _windows_shell_from_env()
)
return None
# ---------------------------------------------------------------------------
# Post-install configuration
# ---------------------------------------------------------------------------
def configure_shell(binary: Path) -> None:
detected = detect_current_shell()
if detected is None or detected == DEFAULT_SHELL:
return
print()
info(
f"Detected shell: {Color.BOLD}{detected}{Color.RESET} "
f"(configured default: {DEFAULT_SHELL})"
)
if not ask_yes_no(
f"Set '{detected}' as get's default shell?",
default="y",
):
return
step(f"Running: get set shell {detected}")
if run_get(binary, "set", "shell", detected):
good(f"Shell set to '{detected}'")
else:
warn(
f"Shell configuration failed. Run manually: get set shell {detected}")
def configure_model(binary: Path) -> None:
banner("LLM configuration")
info("Configure the LLM connection parameters.")
info("Leave a field empty to retain its built-in default or to skip.")
print()
url = ask_input(
"API endpoint URL",
hint=f"leave empty for default: {DEFAULT_URL}",
)
if url:
step(f"Running: get set url {url}")
if run_get(binary, "set", "url", url):
good(f"URL set to '{url}'")
print()
model = ask_input(
"Model name",
hint=f"leave empty for default: {DEFAULT_MODEL}",
)
if model:
step(f"Running: get set model {model}")
if run_get(binary, "set", "model", model):
good(f"Model set to '{model}'")
print()
key = ask_secret("API key", hint="leave empty to skip")
if key:
step("Running: get set key <hidden>")
if run_get(binary, "set", "key", key):
good("API key configured")
else:
info("API key not set. Configure later with: get set key <your-key>")
def configure_advanced(binary: Path) -> None:
banner("Advanced configuration")
info("Defaults are shown in brackets. Press Enter to accept the default.")
print()
# double-check (default: true)
info(
"double-check: Secondary LLM safety review of generated commands."
f" {Color.DIM}[default: true]{Color.RESET}"
)
double_check = ask_yes_no("Enable double-check?", default="y")
step(f"Running: get set double-check {str(double_check).lower()}")
if run_get(binary, "set", "double-check", str(double_check).lower()):
good(f"double-check = {str(double_check).lower()}")
print()
# manual-confirm (default: false)
info(
"manual-confirm: Require manual confirmation before executing each command."
f" {Color.DIM}[default: false]{Color.RESET}"
)
manual_confirm = ask_yes_no("Enable manual-confirm?", default="n")
step(f"Running: get set manual-confirm {str(manual_confirm).lower()}")
if run_get(binary, "set", "manual-confirm", str(manual_confirm).lower()):
good(f"manual-confirm = {str(manual_confirm).lower()}")
print()
# instance: only offered when both safety checks are disabled
if not double_check and not manual_confirm:
info(
"instance: Fast single-call mode; disables multi-round agent behavior."
f" {Color.DIM}[default: false]{Color.RESET}"
)
warn(
"In instance mode, performance and security will degrade."
)
instance = ask_yes_no("Enable instance?", default="n")
step(f"Running: get set instance {str(instance).lower()}")
if run_get(binary, "set", "instance", str(instance).lower()):
good(f"instance = {str(instance).lower()}")
print()
# system-prompt (default: empty)
info(
"system-prompt: Custom instruction prepended to every LLM request."
f" {Color.DIM}[default: empty]{Color.RESET}"
)
system_prompt = ask_input("System prompt", hint="leave empty to skip")
if system_prompt:
step("Running: get set system-prompt <value>")
if run_get(binary, "set", "system-prompt", system_prompt):
good("system-prompt configured")
print()
# cache (default: true)
info(
"cache: Enable the cache system for repeated queries."
f" {Color.DIM}[default: true]{Color.RESET}"
)
warn(
"After the first execution is recorded, repeating the same query may trigger "
"one extra LLM request to decide whether and how to cache it. "
"Cache may causes occasional issues."
)
info("Clear cache with: get cache --clean")
cache_enabled = ask_yes_no("Enable cache?", default="y")
step(f"Running: get set cache {str(cache_enabled).lower()}")
if run_get(binary, "set", "cache", str(cache_enabled).lower()):
good(f"cache = {str(cache_enabled).lower()}")
print()
# vivid (default: true)
info(
"vivid: Colored output and animations in terminal display."
f" {Color.DIM}[default: true]{Color.RESET}"
)
vivid = ask_yes_no("Enable vivid?", default="y")
step(f"Running: get set vivid {str(vivid).lower()}")
if run_get(binary, "set", "vivid", str(vivid).lower()):
good(f"vivid = {str(vivid).lower()}")
print()
if not vivid:
# hide-process (default: false)
info(
"hide-process: Suppress intermediate step output during execution."
f" {Color.DIM}[default: false]{Color.RESET}"
)
hide_process = ask_yes_no("Enable hide-process?", default="n")
step(f"Running: get set hide-process {str(hide_process).lower()}")
if run_get(binary, "set", "hide-process", str(hide_process).lower()):
good(f"hide-process = {str(hide_process).lower()}")
print()
# external-display (default: true)
info(
"external-display: Use external tools (bat, mdcat) for rendering output."
f" {Color.DIM}[default: true]{Color.RESET}"
)
external_display = ask_yes_no("Enable external-display?", default="y")
step(
f"Running: get set external-display {str(external_display).lower()}")
if run_get(binary, "set", "external-display", str(external_display).lower()):
good(f"external-display = {str(external_display).lower()}")
print()
# ---------------------------------------------------------------------------
# Uninstall
# ---------------------------------------------------------------------------
def do_uninstall(existing: Path) -> None:
paths = install_paths()
print()
remove_file(existing)
if paths["binary"].resolve() != existing.resolve():
remove_file(paths["binary"])
if paths["extra_bin"].exists():
step(f"Removing extra tools: {paths['extra_bin']}")
try:
shutil.rmtree(paths["extra_bin"])
good("Extra tools removed")
except OSError as e:
bad(f"Failed: {e}")
if paths["man"]:
remove_file(paths["man"])
prune_empty_parents(paths["man"].parent, stop_at=Path.home())
if paths["root"].exists():
try:
paths["root"].rmdir()
except OSError:
pass
step("Cleaning PATH entries")
if remove_from_path(paths["path_dirs"]):
good("PATH entries removed")
else:
good("PATH entries already absent")
print()
banner("uninstallation complete")
if IS_LINUX:
info("Restart your shell to refresh the environment.")
else:
info("Open a new terminal for PATH changes to take effect.")
# ---------------------------------------------------------------------------
# Entry point
# ---------------------------------------------------------------------------
def main() -> None:
_enable_ansi()
print()
print(f"{Color.BOLD}{Color.MAGENTA}{PROJECT_TAGLINE}{Color.RESET}")
print()
existing = find_installed()
# ------------------------------------------------------------------
# Uninstall branch
# ------------------------------------------------------------------
if existing:
banner("uninstaller")
info(
f"Existing installation found: {Color.BOLD}{existing}{Color.RESET}")
print()
if not ask_yes_no("Uninstall get?", default="n"):
_print_github()
sys.exit(0)
do_uninstall(existing)
print()
if not ask_yes_no("Reinstall get?", default="n"):
_print_github()
sys.exit(0)
# ------------------------------------------------------------------
# Install branch
# ------------------------------------------------------------------
banner("installer")
check_system()
print()
src_bin = SCRIPT_DIR / ("get.exe" if IS_WINDOWS else "get")
if not src_bin.exists():
fail(f"Source binary not found: {src_bin}")
_print_github()
sys.exit(1)
info(f"Source binary: {src_bin}")
print()
if not ask_yes_no("Install get?", default="y"):
info("Installation cancelled.")
_print_github()
sys.exit(0)
# Installation type selection
extra_src = SCRIPT_DIR / "bin"
has_extra = extra_src.is_dir() and any(extra_src.iterdir())
if has_extra:
mode = ask_choice(
"Select installation type:",
[
(
"full",
"Full installation",
"Install get, extra tools from bin/, and (Linux) man page.",
),
(
"minimal",
"Minimal installation",
"Install get and (Linux) man page only.",
),
],
)
else:
mode = "minimal"
info("No bin/ directory found -- performing minimal installation.")
paths = install_paths()
binary = paths["binary"]
path_dirs = paths["path_dirs"][:1] if mode == "minimal" else paths["path_dirs"]
# Confirm targets
print()
info("Installation targets:")
print(f" binary : {binary}")
if mode == "full":
print(f" extra bin : {paths['extra_bin']}")
if paths["man"]:
print(f" man page : {paths['man']}")
for d in path_dirs:
print(f" PATH += : {d}")
print()
if not ask_yes_no("Proceed with installation?", default="y"):
info("Installation cancelled.")
_print_github()
sys.exit(0)
print()
# Binary
step(f"Installing binary --> {binary}")
copy_file(src_bin, binary)
good("Binary installed")
# Man page
if paths["man"]:
man_src = SCRIPT_DIR / "get.1"
if man_src.exists():
step(f"Installing man page --> {paths['man']}")
copy_file(man_src, paths["man"])
good("Man page installed")
else:
warn("get.1 not found -- man page skipped")
# Extra tools
if mode == "full":
step(f"Installing extra tools --> {paths['extra_bin']}")
paths["extra_bin"].mkdir(parents=True, exist_ok=True)
count = 0
for item in extra_src.iterdir():
if item.is_file():
copy_file(item, paths["extra_bin"] / item.name)
count += 1
good(f"{count} extra tool(s) installed")
# PATH
step("Updating PATH")
if add_to_path(path_dirs):
good("PATH updated")
else:
good("PATH already configured")
# Shell
configure_shell(binary)
# LLM settings
print()
if ask_yes_no("Configure LLM connection settings now?", default="y"):
configure_model(binary)
# Advanced settings
print()
if ask_yes_no("Configure advanced settings now?", default="n"):
configure_advanced(binary)
# Completion
print()
banner("installation complete")
info("Open a new terminal and run the following to verify:")
print(f" {Color.BOLD}get version{Color.RESET}"
f" {Color.DIM}-- verify installation{Color.RESET}")
print(f" {Color.BOLD}get isok{Color.RESET}"
f" {Color.DIM}-- verify configuration{Color.RESET}")
print()
if IS_LINUX:
info(
"To reload PATH in the current session: "
f"{Color.BOLD}source ~/.profile{Color.RESET}"
)
else:
info("Open a new terminal for PATH changes to take effect.")
_print_github()
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print()
fail("Interrupted.")
sys.exit(130)