-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·1009 lines (901 loc) · 33.3 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·1009 lines (901 loc) · 33.3 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
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# Lacy Shell Installation Script
# https://github.com/lacymorrow/lacy
#
# Install methods:
# curl -fsSL https://lacy.sh/install | bash
# npx lacy
# brew install lacymorrow/tap/lacy
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
BOLD='\033[1m'
DIM='\033[2m'
NC='\033[0m' # No Color
# Installation directory
INSTALL_DIR="${HOME}/.lacy"
REPO_URL="https://github.com/lacymorrow/lacy.git"
TARBALL_URL="https://github.com/lacymorrow/lacy/archive/refs/heads"
CONFIG_FILE="${INSTALL_DIR}/config.yaml"
# Release channel (set via --beta, --channel, or LACY_CHANNEL env var)
LACY_CHANNEL="${LACY_CHANNEL:-latest}"
# Analytics — lightweight, anonymous install tracking via Umami
# No PII collected. Respects DO_NOT_TRACK. See: https://umami.is
UMAMI_URL="${LACY_UMAMI_URL:-https://analytics.lacy.sh}"
UMAMI_WEBSITE_ID="${LACY_UMAMI_WEBSITE_ID:-577521d7-3db7-4a77-a45c-3c97f21b5322}"
track_event() {
[[ "${DO_NOT_TRACK:-}" == "1" ]] && return
[[ "${LACY_NO_TELEMETRY:-}" == "1" ]] && return
local event_name="${1:-install}"
local method="${2:-curl}"
local version
version=$(get_installed_version)
(curl -sf --connect-timeout 3 --max-time 5 -X POST "${UMAMI_URL}/api/send" \
-H "Content-Type: application/json" \
-H "User-Agent: lacy-install/${version:-unknown}" \
-d "{
\"type\": \"event\",
\"payload\": {
\"hostname\": \"lacy.sh\",
\"language\": \"\",
\"referrer\": \"\",
\"screen\": \"\",
\"title\": \"Install\",
\"url\": \"/install/${method}\",
\"website\": \"${UMAMI_WEBSITE_ID}\",
\"name\": \"${event_name}\",
\"data\": {
\"method\": \"${method}\",
\"os\": \"$(uname -s 2>/dev/null || echo unknown)\",
\"arch\": \"$(uname -m 2>/dev/null || echo unknown)\",
\"shell\": \"${DETECTED_SHELL:-unknown}\",
\"version\": \"${version:-unknown}\",
\"channel\": \"${LACY_CHANNEL}\"
}
}
}" >/dev/null 2>&1 &)
}
# Validate channel — alphanumeric, hyphens, dots only
if [[ ! "$LACY_CHANNEL" =~ ^[a-zA-Z0-9._-]+$ ]]; then
printf "${RED}Invalid channel: %s${NC}\n" "$LACY_CHANNEL" >&2
exit 1
fi
# Version — read from installed or repo package.json
get_installed_version() {
local pkg_file="${INSTALL_DIR}/package.json"
if [[ -f "$pkg_file" ]]; then
grep '"version"' "$pkg_file" 2>/dev/null | head -1 | sed 's/.*"version"[[:space:]]*:[[:space:]]*"//' | sed 's/".*//'
fi
}
# Selected tool (set during installation)
SELECTED_TOOL=""
CUSTOM_COMMAND=""
# Detected shell (set during installation)
DETECTED_SHELL=""
# Detect user's login shell
detect_user_shell() {
if [[ -n "$LACY_FORCE_SHELL" ]]; then
DETECTED_SHELL="$LACY_FORCE_SHELL"
return
fi
local login_shell
login_shell=$(basename "${SHELL:-}")
case "$login_shell" in
zsh) DETECTED_SHELL="zsh" ;;
bash) DETECTED_SHELL="bash" ;;
fish) DETECTED_SHELL="fish" ;;
*)
# Detect from running process or what's available
if [[ -n "${BASH_VERSION:-}" ]]; then
DETECTED_SHELL="bash"
elif [[ -n "${ZSH_VERSION:-}" ]]; then
DETECTED_SHELL="zsh"
elif command -v zsh >/dev/null 2>&1; then
DETECTED_SHELL="zsh"
elif command -v bash >/dev/null 2>&1; then
DETECTED_SHELL="bash"
else
DETECTED_SHELL="bash"
fi
;;
esac
}
# Get the RC file for the detected shell
get_rc_file() {
case "$DETECTED_SHELL" in
bash)
# macOS uses .bash_profile for login shells
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "${HOME}/.bash_profile"
else
echo "${HOME}/.bashrc"
fi
;;
fish) echo "${HOME}/.config/fish/conf.d/lacy.fish" ;;
*) echo "${HOME}/.zshrc" ;;
esac
}
# Get the plugin file for the detected shell
get_plugin_file() {
case "$DETECTED_SHELL" in
bash) echo "lacy.plugin.bash" ;;
fish) echo "lacy.plugin.fish" ;;
*) echo "lacy.plugin.zsh" ;;
esac
}
# Get the shell restart command
get_shell_restart_cmd() {
case "$DETECTED_SHELL" in
bash) echo "bash -l" ;;
fish) echo "fish" ;;
*) echo "zsh -l" ;;
esac
}
# Get the source command for the RC file
get_source_hint() {
local rc_file
rc_file=$(get_rc_file)
echo "source $rc_file"
}
# Check if we should use Node installer
use_node_installer() {
# Skip Node installer if --bash flag is passed
[[ "$LACY_FORCE_BASH" == "1" ]] && return 1
# Check if npx is available and we have an interactive terminal
# Note: when piped (curl | bash), -t 0 is false but /dev/tty is still available
if command -v npx >/dev/null 2>&1 && { [[ -t 0 ]] || [[ -c /dev/tty ]]; }; then
return 0
fi
return 1
}
# Run Node installer via npx
run_node_installer() {
local pkg="lacy@${LACY_CHANNEL}"
# Quietly check if package exists first
if ! npm view "$pkg" version >/dev/null 2>&1; then
return 1
fi
if [[ "$LACY_CHANNEL" != "latest" ]]; then
printf "${MAGENTA}Channel: ${LACY_CHANNEL}${NC}\n"
fi
printf "${BLUE}Using interactive installer...${NC}\n"
printf "\n"
# Redirect stdin from /dev/tty so the Node process gets an interactive TTY
# even when this script is piped (curl | bash)
if npx --yes "$pkg" < /dev/tty; then
# Restore terminal state — the Node process uses @clack/prompts which
# toggles raw mode on the tty. If Node exits without restoring it
# (crash, SIGINT, etc.), the parent shell's tty is left corrupted.
stty sane 2>/dev/null
exit 0
fi
# npx failed for some reason, fall back
# Restore terminal state in case Node corrupted it before failing
stty sane 2>/dev/null
printf "\n"
printf "${YELLOW}Falling back to standard installer...${NC}\n"
printf "\n"
return 1
}
print_banner() {
printf "\n"
printf "${MAGENTA}${BOLD}"
printf " _ \n"
printf " | | __ _ ___ _ _ \n"
printf " | | / _\` |/ __| | | | \n"
printf " | |__| (_| | (__| |_| | \n"
printf " |_____\__,_|\___|\__, | \n"
printf " |___/ \n"
printf "${NC}"
printf "${CYAN}Talk directly to your shell${NC}\n"
local version
version=$(get_installed_version)
if [[ -n "$version" ]]; then
printf "${DIM} v${version}${NC}\n"
fi
if [[ "$LACY_CHANNEL" != "latest" ]]; then
printf "${MAGENTA}${BOLD} [${LACY_CHANNEL}]${NC}\n"
fi
printf "\n"
}
# Check prerequisites
check_prerequisites() {
printf "${BLUE}Checking prerequisites...${NC}\n"
local missing=0
# Check for the target shell
case "$DETECTED_SHELL" in
zsh)
if command -v zsh >/dev/null 2>&1; then
printf " ${GREEN}✓${NC} zsh\n"
else
printf " ${RED}✗${NC} zsh (required)\n"
missing=1
fi
;;
bash)
if command -v bash >/dev/null 2>&1; then
local bash_version user_bash
# Use the user's $SHELL if it's bash — on macOS, plain `bash` resolves
# to /bin/bash (3.2) even when the user has a newer bash as their shell
case "${SHELL:-}" in
*/bash) user_bash="$SHELL" ;;
*) user_bash="bash" ;;
esac
bash_version=$("$user_bash" -c 'echo ${BASH_VERSINFO[0]}' 2>/dev/null || bash -c 'echo ${BASH_VERSINFO[0]}' 2>/dev/null || echo "0")
if [[ "$bash_version" -ge 4 ]]; then
printf " ${GREEN}✓${NC} bash ${bash_version}+\n"
else
printf " ${RED}✗${NC} bash 4+ required (found bash ${bash_version})\n"
printf " ${DIM}Install with: brew install bash${NC}\n"
missing=1
fi
else
printf " ${RED}✗${NC} bash (required)\n"
missing=1
fi
;;
esac
# Check for curl
if command -v curl >/dev/null 2>&1; then
printf " ${GREEN}✓${NC} curl\n"
else
printf " ${RED}✗${NC} curl (required)\n"
missing=1
fi
# Check for git (optional — curl fallback available)
if command -v git >/dev/null 2>&1; then
printf " ${GREEN}✓${NC} git\n"
else
printf " ${YELLOW}○${NC} git (not found, will use curl fallback)\n"
fi
printf "\n"
if [[ $missing -eq 1 ]]; then
printf "${RED}Please install missing prerequisites and try again.${NC}\n"
exit 1
fi
}
# Detect installed AI CLI tools
detect_tools() {
printf "${BLUE}Detecting AI CLI tools...${NC}\n"
local found=0
for tool in lash claude opencode gemini codex hermes copilot amp; do
if command -v "$tool" >/dev/null 2>&1; then
printf " ${GREEN}✓${NC} $tool\n"
found=1
fi
done
if [[ $found -eq 0 ]]; then
printf " ${YELLOW}○${NC} No AI CLI tools found\n"
printf "\n"
printf "${YELLOW}Lacy Shell requires an AI CLI tool to work.${NC}\n"
printf "Would you like to install ${GREEN}lash${NC}? (AI coding agent — lash.lacy.sh)\n"
printf "\n"
read -p "Install lash now? [Y/n]: " install_now < /dev/tty 2>/dev/null || install_now="n"
if [[ ! "$install_now" =~ ^[Nn]$ ]]; then
install_lash
printf "\n"
# Re-check if lash was installed successfully
if command -v lash >/dev/null 2>&1; then
printf " ${GREEN}✓${NC} lash\n"
fi
fi
fi
printf "\n"
}
# Interactive tool selection (bash fallback)
select_tool() {
printf "${BOLD}Which AI CLI tool do you want to use?${NC}\n"
printf "\n"
printf " 1) lash ${DIM}- AI coding agent (recommended) — lash.lacy.sh${NC}\n"
printf " 2) claude ${DIM}- Claude Code CLI${NC}\n"
printf " 3) opencode ${DIM}- OpenCode CLI${NC}\n"
printf " 4) gemini ${DIM}- Google Gemini CLI${NC}\n"
printf " 5) codex ${DIM}- OpenAI Codex CLI${NC}\n"
printf " 6) hermes ${DIM}- Hermes Agent CLI${NC}\n"
printf " 7) copilot ${DIM}- GitHub Copilot CLI${NC}\n"
printf " 8) amp ${DIM}- Sourcegraph Amp CLI${NC}\n"
printf " 9) Auto-detect ${DIM}(use first available)${NC}\n"
printf " 10) None ${DIM}- I'll install one later${NC}\n"
printf " 11) Custom ${DIM}- enter your own command${NC}\n"
printf "\n"
local choice
read -p "Select [1-11, default=9]: " choice < /dev/tty 2>/dev/null || choice="9"
case "$choice" in
1) SELECTED_TOOL="lash" ;;
2) SELECTED_TOOL="claude" ;;
3) SELECTED_TOOL="opencode" ;;
4) SELECTED_TOOL="gemini" ;;
5) SELECTED_TOOL="codex" ;;
6) SELECTED_TOOL="hermes" ;;
7) SELECTED_TOOL="copilot" ;;
8) SELECTED_TOOL="amp" ;;
9|"") SELECTED_TOOL="" ;;
10) SELECTED_TOOL="none" ;;
11)
SELECTED_TOOL="custom"
printf "\n"
read -p "Enter command (e.g. claude --dangerously-skip-permissions -p): " CUSTOM_COMMAND < /dev/tty 2>/dev/null || CUSTOM_COMMAND=""
if [[ -z "$CUSTOM_COMMAND" ]]; then
printf "${RED}No command entered. Falling back to auto-detect.${NC}\n"
SELECTED_TOOL=""
fi
;;
*) SELECTED_TOOL="" ;;
esac
if [[ -n "$SELECTED_TOOL" && "$SELECTED_TOOL" != "none" && "$SELECTED_TOOL" != "custom" ]]; then
printf "\n"
printf "Selected: ${GREEN}$SELECTED_TOOL${NC}\n"
# Check if selected tool is installed
if ! command -v "$SELECTED_TOOL" >/dev/null 2>&1; then
printf "${YELLOW}Note: $SELECTED_TOOL is not installed.${NC}\n"
if [[ "$SELECTED_TOOL" == "lash" ]]; then
printf "\n"
read -p "Would you like to install lash now? [y/N]: " do_install_lash < /dev/tty 2>/dev/null || do_install_lash="n"
if [[ "$do_install_lash" =~ ^[Yy]$ ]]; then
install_lash
fi
else
printf "You can install it later with:\n"
case "$SELECTED_TOOL" in
claude) printf " brew install claude\n" ;;
opencode) printf " brew install opencode\n" ;;
gemini) printf " brew install gemini\n" ;;
codex) printf " npm install -g @openai/codex\n" ;;
hermes) printf " curl -fsSL https://raw.githubusercontent.com/NousResearch/hermes-agent/main/scripts/install.sh | bash\n" ;;
copilot) printf " gh extension install github/gh-copilot\n" ;;
amp) printf " npm install -g @sourcegraph/amp\n" ;;
esac
fi
fi
elif [[ "$SELECTED_TOOL" == "custom" ]]; then
printf "\n"
printf "Selected: ${GREEN}custom${NC} (${CUSTOM_COMMAND})\n"
elif [[ "$SELECTED_TOOL" == "none" ]]; then
printf "\n"
printf "No tool selected. Lacy will prompt you to install one when needed.\n"
else
# Auto-detect: check if any tool is available
printf "\n"
local first_tool_found=""
for t in lash claude opencode gemini codex hermes copilot amp; do
if command -v "$t" >/dev/null 2>&1; then
first_tool_found="$t"
break
fi
done
if [[ -z "$first_tool_found" ]]; then
printf "${YELLOW}No AI CLI tools are installed.${NC}\n"
printf "Would you like to install ${GREEN}lash${NC}? (AI coding agent — lash.lacy.sh)\n"
printf "\n"
local do_install=""
read -p "Install lash now? [Y/n]: " do_install < /dev/tty 2>/dev/null || do_install="n"
if [[ ! "$do_install" =~ ^[Nn]$ ]]; then
install_lash
else
printf "\n"
printf "Using: ${GREEN}auto-detect${NC} (first available tool)\n"
printf "${YELLOW}Note: You'll need to install a tool before using Lacy.${NC}\n"
fi
else
printf "Using: ${GREEN}auto-detect${NC} (currently: ${GREEN}${first_tool_found}${NC})\n"
fi
fi
printf "\n"
}
# Install lash CLI
install_lash() {
printf "${BLUE}Installing lash...${NC}\n"
if command -v npm >/dev/null 2>&1; then
npm install -g lashcode
printf "${GREEN}✓ lash installed${NC}\n"
elif command -v brew >/dev/null 2>&1; then
brew tap lacymorrow/tap
brew install lash
printf "${GREEN}✓ lash installed${NC}\n"
else
printf "${RED}Could not install lash. Please install npm or homebrew first.${NC}\n"
fi
}
# Download and extract tarball (curl fallback when git is not available)
install_via_tarball() {
local branch="$1"
local tarball_file
tarball_file=$(mktemp "${TMPDIR:-/tmp}/lacy-XXXXXX.tar.gz")
curl -fsSL "${TARBALL_URL}/${branch}.tar.gz" -o "$tarball_file" 2>/dev/null || {
rm -f "$tarball_file"
return 1
}
mkdir -p "$INSTALL_DIR"
tar xzf "$tarball_file" --strip-components=1 -C "$INSTALL_DIR" 2>/dev/null || {
rm -f "$tarball_file"
return 1
}
rm -f "$tarball_file"
return 0
}
# Clone or update repository
install_plugin() {
printf "${BLUE}Installing Lacy...${NC}\n"
# Determine git branch: beta channel clones beta branch, otherwise main
local branch="main"
if [[ "$LACY_CHANNEL" != "latest" ]]; then
branch="$LACY_CHANNEL"
fi
local has_git=0
command -v git >/dev/null 2>&1 && has_git=1
if [[ -d "$INSTALL_DIR" ]]; then
printf "${YELLOW}Existing installation found. Updating...${NC}\n"
if [[ $has_git -eq 1 && -d "$INSTALL_DIR/.git" ]]; then
cd "$INSTALL_DIR" || exit 1
git pull origin "$branch" 2>/dev/null || git pull origin main 2>/dev/null || git pull 2>/dev/null || {
printf "${YELLOW}Could not update, using existing installation${NC}\n"
}
else
install_via_tarball "$branch" || install_via_tarball "main" || {
printf "${YELLOW}Could not update, using existing installation${NC}\n"
}
fi
else
if [[ $has_git -eq 1 ]]; then
git clone --depth 1 -b "$branch" "$REPO_URL" "$INSTALL_DIR" 2>/dev/null || \
git clone --depth 1 "$REPO_URL" "$INSTALL_DIR" 2>/dev/null || {
# Git failed, try curl fallback
install_via_tarball "$branch" || install_via_tarball "main" || {
printf "${RED}Failed to install repository${NC}\n"
exit 1
}
}
else
install_via_tarball "$branch" || install_via_tarball "main" || {
printf "${RED}Failed to download repository${NC}\n"
exit 1
}
fi
fi
local version
version=$(get_installed_version)
printf "${GREEN}✓ Lacy installed to $INSTALL_DIR${NC}"
[[ -n "$version" ]] && printf " ${DIM}(v${version})${NC}"
printf "\n\n"
track_event "install" "curl"
}
# Configure shell integration (multi-shell aware)
configure_shell() {
printf "${BLUE}Configuring ${DETECTED_SHELL} shell...${NC}\n"
local rc_file plugin_file plugin_line rc_name
rc_file=$(get_rc_file)
plugin_file=$(get_plugin_file)
rc_name=$(basename "$rc_file")
plugin_line="source ${INSTALL_DIR}/${plugin_file}"
# PATH line for the lacy CLI binary
local path_line="export PATH=\"${INSTALL_DIR}/bin:\$PATH\""
# Check if already configured
if [[ -f "$rc_file" ]] && grep -q "lacy.plugin" "$rc_file" 2>/dev/null; then
printf "${GREEN}✓ Already configured in ${rc_name}${NC}\n"
# Add PATH if missing (upgrade from older install)
if ! grep -q '\.lacy/bin' "$rc_file" 2>/dev/null; then
printf "%s\n" "$path_line" >> "$rc_file"
printf "${GREEN}✓ Added lacy CLI to PATH in ${rc_name}${NC}\n"
fi
else
# Ensure parent directory exists
mkdir -p "$(dirname "$rc_file")"
# Create RC file if it doesn't exist
[[ ! -f "$rc_file" ]] && touch "$rc_file"
# Add source line + PATH
{
printf "\n"
printf "# Lacy Shell\n"
printf "%s\n" "$plugin_line"
printf "%s\n" "$path_line"
} >> "$rc_file"
printf "${GREEN}✓ Added to ${rc_name}${NC}\n"
fi
# For Fish: also ensure the conf.d directory exists and use `source` syntax
if [[ "$DETECTED_SHELL" == "fish" ]]; then
mkdir -p "${HOME}/.config/fish/conf.d"
# Fish sources all *.fish files in conf.d automatically — create a loader
local fish_conf="${HOME}/.config/fish/conf.d/lacy.fish"
if [[ ! -f "$fish_conf" ]]; then
printf "source %s/lacy.plugin.fish\n" "${INSTALL_DIR}" > "$fish_conf"
printf "${GREEN}✓ Created %s${NC}\n" "$fish_conf"
fi
return
fi
# For Bash on macOS, also add to .bashrc if it exists (some terminals source it)
if [[ "$DETECTED_SHELL" == "bash" && "$OSTYPE" == "darwin"* ]]; then
local bashrc="${HOME}/.bashrc"
if [[ -f "$bashrc" ]] && ! grep -q "lacy.plugin" "$bashrc" 2>/dev/null; then
{
printf "\n"
printf "# Lacy Shell\n"
printf "%s\n" "$plugin_line"
printf "%s\n" "$path_line"
} >> "$bashrc"
printf "${GREEN}✓ Also added to .bashrc${NC}\n"
fi
fi
printf "\n"
}
# Backward compat alias
configure_zsh() { configure_shell; }
# Parse a simple YAML value (strips inline comments and quotes)
_yaml_value() {
local file="$1" key="$2"
grep "^[[:space:]]*${key}:" "$file" 2>/dev/null | head -1 | sed 's/^[^:]*:[[:space:]]*//' | sed 's/[[:space:]]*#.*//' | tr -d '"' | tr -d "'"
}
# Write a YAML value in-place
_yaml_write() {
local file="$1" key="$2" value="$3"
local escaped_value="${value//\\/\\\\}"
escaped_value="${escaped_value//|/\\|}"
escaped_value="${escaped_value//&/\\&}"
if grep -q "^[[:space:]]*${key}:" "$file" 2>/dev/null; then
sed -i.bak "s|^\\([[:space:]]*${key}:\\).*|\\1 ${escaped_value}|" "$file"
rm -f "${file}.bak"
fi
}
# Create configuration with selected tool (preserves existing config)
create_config() {
mkdir -p "$INSTALL_DIR"
# Determine active tool value for config
local active_tool_value=""
if [[ -n "$SELECTED_TOOL" && "$SELECTED_TOOL" != "none" ]]; then
active_tool_value="$SELECTED_TOOL"
fi
# If config already exists, update the tool selection only
if [[ -f "$CONFIG_FILE" ]]; then
printf "${BLUE}Updating configuration...${NC}\n"
if [[ -n "$active_tool_value" ]]; then
_yaml_write "$CONFIG_FILE" "active" "$active_tool_value"
if [[ "$SELECTED_TOOL" == "custom" && -n "$CUSTOM_COMMAND" ]]; then
_yaml_write "$CONFIG_FILE" "custom_command" "\"$CUSTOM_COMMAND\""
fi
fi
printf "${GREEN}✓ Configuration preserved at $CONFIG_FILE${NC}\n"
printf "\n"
return
fi
# Fresh config
printf "${BLUE}Creating configuration...${NC}\n"
# Build custom_command line
local custom_command_line=" # custom_command: \"your-command -flags\""
if [[ "$SELECTED_TOOL" == "custom" && -n "$CUSTOM_COMMAND" ]]; then
custom_command_line=" custom_command: \"$CUSTOM_COMMAND\""
fi
cat > "$CONFIG_FILE" << EOF
# Lacy Shell Configuration
# https://github.com/lacymorrow/lacy
# AI CLI tool selection
# Options: lash, claude, opencode, gemini, codex, custom, or empty for auto-detect
agent_tools:
active: $active_tool_value
$custom_command_line
# API Keys (optional - only needed if no CLI tool is installed)
api_keys:
# openai: "your-key-here"
# anthropic: "your-key-here"
# Operating modes
modes:
default: auto # Options: shell, agent, auto
# Smart auto-detection settings
auto_detection:
enabled: true
confidence_threshold: 0.7
EOF
printf "${GREEN}✓ Configuration created at $CONFIG_FILE${NC}\n"
printf "\n"
}
# Show success message
show_success() {
local version
version=$(get_installed_version)
printf "${GREEN}${BOLD}Installation complete!${NC}"
[[ -n "$version" ]] && printf " ${DIM}v${version}${NC}"
printf "\n"
printf "\n"
printf "${BOLD}Try it:${NC}\n"
printf " ${CYAN}what files are here${NC} ${DIM}→ AI answers${NC}\n"
printf " ${CYAN}ls -la${NC} ${DIM}→ runs in shell${NC}\n"
printf "\n"
printf "${BOLD}Commands:${NC}\n"
printf " ${CYAN}mode${NC} Show/change mode (shell/agent/auto)\n"
printf " ${CYAN}tool${NC} Show/change AI tool\n"
printf " ${CYAN}ask \"query\"${NC} Direct query to AI\n"
printf " ${CYAN}Ctrl+Space${NC} Toggle between modes\n"
printf "\n"
printf "${BOLD}Visual feedback:${NC}\n"
printf " ${GREEN}▌${NC} Green = will run in shell\n"
printf " ${MAGENTA}▌${NC} Magenta = will go to AI\n"
printf "\n"
if [[ "$SELECTED_TOOL" == "none" ]] || { [[ -z "$SELECTED_TOOL" ]] && ! command -v lash >/dev/null 2>&1 && ! command -v claude >/dev/null 2>&1; }; then
printf "${YELLOW}Remember to install an AI CLI tool:${NC}\n"
printf " npm install -g lashcode # or\n"
printf " brew install claude\n"
printf "\n"
fi
printf "${DIM}Learn more: https://github.com/lacymorrow/lacy${NC}\n"
printf "\n"
}
# Restart shell to apply changes
restart_shell() {
# Only prompt if /dev/tty is actually usable (not just that it exists)
local restart=""
if [[ -t 0 ]]; then
printf "\n"
read -p "Restart shell now to apply changes? [Y/n]: " restart
elif { true < /dev/tty; } 2>/dev/null; then
printf "\n"
read -p "Restart shell now to apply changes? [Y/n]: " restart < /dev/tty
else
printf "\nRestart your terminal to apply changes.\n"
return 0
fi
if [[ ! "$restart" =~ ^[Nn]$ ]]; then
printf "${BLUE}Restarting shell...${NC}\n"
local restart_cmd
restart_cmd=$(get_shell_restart_cmd)
exec $restart_cmd
else
printf "\n"
printf "Run ${CYAN}$(get_source_hint)${NC} or restart your terminal to apply changes.\n"
fi
}
# Remove lacy lines from an RC file
_remove_from_rc() {
local rc_file="$1"
local rc_name
rc_name=$(basename "$rc_file")
if [[ -f "$rc_file" ]]; then
if grep -q "lacy.plugin" "$rc_file" 2>/dev/null; then
printf "${BLUE}Removing from ${rc_name}...${NC}\n"
local tmp_file
tmp_file=$(mktemp)
grep -v "lacy.plugin" "$rc_file" | grep -v "# Lacy Shell" | grep -v '\.lacy/bin' > "$tmp_file" || true
mv "$tmp_file" "$rc_file"
printf " ${GREEN}✓${NC} Removed from ${rc_name}\n"
fi
fi
}
# Uninstall function
do_uninstall() {
printf "${BLUE}Uninstalling Lacy Shell...${NC}\n"
printf "\n"
# Check if installed (directory, symlink, or old install path)
if [[ ! -d "$INSTALL_DIR" ]] && [[ ! -L "$INSTALL_DIR" ]] && [[ ! -d "${HOME}/.lacy-shell" ]]; then
printf "${YELLOW}Lacy Shell is not installed${NC}\n"
exit 0
fi
# Remove from all possible RC files
_remove_from_rc "${HOME}/.zshrc"
_remove_from_rc "${HOME}/.bashrc"
_remove_from_rc "${HOME}/.bash_profile"
_remove_from_rc "${HOME}/.config/fish/conf.d/lacy.fish"
# Detect Homebrew-managed install (symlink to Homebrew prefix)
local is_brew=false
if [[ -L "$INSTALL_DIR" ]]; then
local link_target
link_target=$(readlink "$INSTALL_DIR" 2>/dev/null || true)
if [[ "$link_target" == *"/Cellar/"* || "$link_target" == *"/homebrew/"* ]]; then
is_brew=true
fi
fi
# Remove installation directories
if [[ -L "$INSTALL_DIR" ]]; then
printf "${BLUE}Removing $INSTALL_DIR symlink...${NC}\n"
rm -f "$INSTALL_DIR"
printf " ${GREEN}✓${NC} Removed\n"
elif [[ -d "$INSTALL_DIR" ]]; then
printf "${BLUE}Removing $INSTALL_DIR...${NC}\n"
rm -rf "$INSTALL_DIR"
printf " ${GREEN}✓${NC} Removed\n"
fi
if [[ -d "${HOME}/.lacy-shell" ]]; then
printf "${BLUE}Removing ${HOME}/.lacy-shell...${NC}\n"
rm -rf "${HOME}/.lacy-shell"
printf " ${GREEN}✓${NC} Removed\n"
fi
# If installed via Homebrew, uninstall the formula too
if [[ "$is_brew" == true ]] && command -v brew >/dev/null 2>&1; then
printf "${BLUE}Removing Homebrew formula...${NC}\n"
brew uninstall lacymorrow/tap/lacy 2>/dev/null && printf " ${GREEN}✓${NC} Homebrew formula removed\n" || true
fi
printf "\n"
printf "${GREEN}Lacy Shell uninstalled${NC}\n"
track_event "uninstall" "curl"
# Restart shell (reuse the safe TTY-aware function)
detect_user_shell
restart_shell
}
# Check if already installed and show menu
check_existing_installation() {
if [[ -d "$INSTALL_DIR" ]]; then
print_banner
printf "${YELLOW}Lacy Shell is already installed.${NC}\n"
printf "\n"
printf "What would you like to do?\n"
printf "\n"
printf " 1) Update ${DIM}- pull latest changes${NC}\n"
printf " 2) Reinstall ${DIM}- fresh installation${NC}\n"
printf " 3) Uninstall ${DIM}- remove Lacy Shell${NC}\n"
printf " 4) Cancel\n"
printf "\n"
local choice
read -p "Select [1-4]: " choice < /dev/tty 2>/dev/null || choice="4"
case "$choice" in
1)
printf "\n"
printf "${BLUE}Updating Lacy...${NC}\n"
cd "$INSTALL_DIR" 2>/dev/null || {
printf "${RED}Could not find installation directory${NC}\n"
exit 1
}
local update_ok=0
if command -v git >/dev/null 2>&1 && [[ -d "$INSTALL_DIR/.git" ]]; then
git pull origin main 2>/dev/null || git pull 2>/dev/null && update_ok=1
else
install_via_tarball "main" && update_ok=1
fi
if [[ $update_ok -eq 1 ]]; then
local updated_version
updated_version=$(get_installed_version)
printf "${GREEN}✓ Lacy updated${NC}"
[[ -n "$updated_version" ]] && printf " ${DIM}(v${updated_version})${NC}"
printf "\n"
track_event "update" "curl"
restart_shell
else
printf "${RED}Update failed. Try reinstalling.${NC}\n"
fi
exit 0
;;
2)
printf "\n"
printf "${BLUE}Removing existing installation...${NC}\n"
# Backup user config before removing
local config_backup=""
if [[ -f "$CONFIG_FILE" ]]; then
config_backup=$(mktemp)
cp "$CONFIG_FILE" "$config_backup"
fi
rm -rf "$INSTALL_DIR" 2>/dev/null
# Restore config so create_config() sees it and preserves it
if [[ -n "$config_backup" ]]; then
mkdir -p "$INSTALL_DIR"
cp "$config_backup" "$CONFIG_FILE"
rm -f "$config_backup"
fi
printf "${GREEN}✓ Removed${NC}\n"
printf "\n"
# Continue with fresh install
return 0
;;
3)
do_uninstall
exit 0
;;
4|*)
printf "\n"
printf "Cancelled.\n"
exit 0
;;
esac
fi
}
# Main installation flow (bash)
main_bash() {
print_banner
detect_user_shell
printf "${DIM}Detected shell: ${DETECTED_SHELL}${NC}\n\n"
check_prerequisites
detect_tools
select_tool
install_plugin
configure_shell
create_config
show_success
restart_shell
}
# Main entry point
main() {
# Try Node installer first (better UX) — it handles existing installations too
if use_node_installer && run_node_installer; then
return
fi
# Bash installer (fallback)
# Check for existing installation first (interactive menu)
if [[ -t 0 ]] || [[ -c /dev/tty ]]; then
check_existing_installation
fi
main_bash
}
# Parse flags that can appear anywhere (--beta, --channel)
_args=()
while [[ $# -gt 0 ]]; do
case "$1" in
--beta)
LACY_CHANNEL="beta"
shift
;;
--channel)
LACY_CHANNEL="${2:?--channel requires a value}"
shift 2
;;
*)
_args+=("$1")
shift
;;
esac
done
set -- "${_args[@]}"
# Handle command line arguments
case "${1:-}" in
"--help"|"-h")
printf "Lacy Shell Installation Script\n"
printf "\n"
printf "Usage: $0 [options]\n"
printf "\n"
printf "Options:\n"
printf " --help Show this help message\n"
printf " --uninstall Uninstall Lacy Shell\n"
printf " --bash Force bash installer (skip Node)\n"
printf " --shell X Force shell type (zsh, bash)\n"
printf " --tool X Pre-select tool (lash, claude, opencode, gemini, codex, custom, auto)\n"
printf " --beta Use beta release channel\n"
printf " --channel X Use a named release channel (beta, rc, etc.)\n"
printf "\n"
printf "Examples:\n"
printf " curl -fsSL https://lacy.sh/install | bash\n"
printf " curl -fsSL https://lacy.sh/install/beta | bash\n"
printf " curl -fsSL https://lacy.sh/install | bash -s -- --beta\n"
printf " curl -fsSL https://lacy.sh/install | bash -s -- --uninstall\n"
printf " curl -fsSL https://lacy.sh/install | bash -s -- --tool claude\n"
printf " curl -fsSL https://lacy.sh/install | bash -s -- --tool custom \"claude -p\"\n"
printf " npx lacy\n"
printf " npx lacy --uninstall\n"
exit 0
;;
"--uninstall"|"-u")
do_uninstall
;;
"--bash")
LACY_FORCE_BASH=1
shift
main "$@"
;;
"--shell")
LACY_FORCE_SHELL="$2"
shift 2
main "$@"
;;
"--tool")
SELECTED_TOOL="$2"
if [[ "$SELECTED_TOOL" == "custom" ]]; then
CUSTOM_COMMAND="$3"
if [[ -z "$CUSTOM_COMMAND" ]]; then
printf "${RED}Error: --tool custom requires a command string.${NC}\n"
printf "Usage: $0 --tool custom \"command -flags\"\n"
exit 1
fi
shift 3
else
shift 2
fi
print_banner
detect_user_shell
check_prerequisites
install_plugin