-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-shell-integration.sh
More file actions
executable file
Β·185 lines (153 loc) Β· 5.57 KB
/
test-shell-integration.sh
File metadata and controls
executable file
Β·185 lines (153 loc) Β· 5.57 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
#!/bin/bash
# Simply Plural shell integration test launcher
set -e
echo "π§ͺ Simply Plural Shell Integration Tester"
echo "=========================================="
# Create test configs
TEST_DIR="/tmp/sp-shell-test"
mkdir -p "$TEST_DIR"
# Write the test bashrc
cat > "$TEST_DIR/.bashrc" << 'EOF'
#!/bin/bash
# Minimal test .bashrc for Simply Plural shell integration testing
# Simply Plural shell integration
_sp_prompt() {
local status_file="$HOME/.cache/sp_status"
# Always show current content (fast - ~1ms)
cat "$status_file" 2>/dev/null || echo ""
# Background check if refresh needed (slow stuff in background, no job control spam)
(_sp_background_check >/dev/null 2>&1 & disown)
}
_sp_background_check() {
local lock_file="$HOME/.cache/sp_refresh.lock"
local status_file="$HOME/.cache/sp_status"
local cache_ttl=900 # 15 minutes (updated TTL)
# Quick mutex check - only one background worker at a time
if [[ -f "$lock_file" ]]; then
local lock_age=$(($(date +%s) - $(stat -c %Y "$lock_file" 2>/dev/null || echo 0)))
if [[ $lock_age -lt 120 ]]; then
return # Another check is running
fi
fi
# Check if we need to refresh
if [[ -f "$status_file" ]]; then
local file_age=$(($(date +%s) - $(stat -c %Y "$status_file" 2>/dev/null || echo 0)))
if [[ $file_age -lt $cache_ttl ]]; then
return # Cache is still fresh
fi
fi
# Do the slow work - update cache and status file
# Note: Adjust path to your SP installation
cd /cygdrive/d/claude/simplyplural-cli
python sp.py --profile=default _internal_update_status >/dev/null 2>&1 || true
rm -f "$lock_file" 2>/dev/null || true
}
# Initial cache population (run once on shell startup)
_sp_background_check
# Simple colorful prompt with SP integration
export PS1="\[\033[32m\]\u@\h\[\033[0m\]:\[\033[34m\]\w\[\033[0m\] \[\033[35m\]\$(_sp_prompt)\[\033[0m\]$ "
# Basic shell settings
export PATH="$PATH:."
export EDITOR=nano
# Make it obvious this is the test environment
echo "π§ͺ Simply Plural test environment loaded (Bash)"
echo "π‘ Use 'exit' to return to your normal shell"
echo "π§ Test commands:"
echo " cd /cygdrive/d/claude/simplyplural-cli && python sp.py fronting"
echo " cd /cygdrive/d/claude/simplyplural-cli && python sp.py switch TestMember"
echo " cat ~/.cache/sp_status"
EOF
# Write the test zshrc
cat > "$TEST_DIR/.zshrc" << 'EOF'
#!/bin/zsh
# Minimal test .zshrc for Simply Plural shell integration testing
# Simply Plural shell integration
_sp_prompt() {
local status_file="$HOME/.cache/sp_status"
# Always show current content (fast - ~1ms)
cat "$status_file" 2>/dev/null || echo ""
# Background check if refresh needed (slow stuff in background, no job control spam)
(_sp_background_check >/dev/null 2>&1 & disown)
}
_sp_background_check() {
local lock_file="$HOME/.cache/sp_refresh.lock"
local status_file="$HOME/.cache/sp_status"
local cache_ttl=900 # 15 minutes (updated TTL)
# Quick mutex check - only one background worker at a time
if [[ -f "$lock_file" ]]; then
local lock_age=$(($(date +%s) - $(stat -c %Y "$lock_file" 2>/dev/null || echo 0)))
if [[ $lock_age -lt 120 ]]; then
return # Another check is running
fi
fi
# Check if we need to refresh
if [[ -f "$status_file" ]]; then
local file_age=$(($(date +%s) - $(stat -c %Y "$status_file" 2>/dev/null || echo 0)))
if [[ $file_age -lt $cache_ttl ]]; then
return # Cache is still fresh
fi
fi
# Do the slow work - update cache and status file
# Note: Adjust path to your SP installation
cd /cygdrive/d/claude/simplyplural-cli
python sp.py --profile=default _internal_update_status >/dev/null 2>&1 || true
rm -f "$lock_file" 2>/dev/null || true
}
# Initial cache population (run once on shell startup)
_sp_background_check
# Enable prompt substitution for zsh
setopt PROMPT_SUBST
# Simple colorful prompt with SP integration
export PROMPT='%F{green}%n@%m%f:%F{blue}%~%f %F{magenta}$(_sp_prompt)%f$ '
# Basic zsh settings
export PATH="$PATH:."
export EDITOR=nano
# Zsh completion system (minimal)
autoload -U compinit
compinit
# Make it obvious this is the test environment
echo "π§ͺ Simply Plural test environment loaded (Zsh)"
echo "π‘ Use 'exit' to return to your normal shell"
echo "π§ Test commands:"
echo " cd /cygdrive/d/claude/simplyplural-cli && python sp.py fronting"
echo " cd /cygdrive/d/claude/simplyplural-cli && python sp.py switch TestMember"
echo " cat ~/.cache/sp_status"
EOF
echo "β
Test configs created in $TEST_DIR"
echo ""
echo "Choose your test shell:"
echo "1) Bash (test .bashrc)"
echo "2) Zsh (test .zshrc)"
echo "3) Show config files only"
echo ""
read -p "Enter choice [1-3]: " choice
case $choice in
1)
echo "π Launching Bash test environment..."
bash --rcfile "$TEST_DIR/.bashrc" -i
;;
2)
echo "π Launching Zsh test environment..."
ZDOTDIR="$TEST_DIR" zsh -i
;;
3)
echo "π Test config files:"
echo "Bash: $TEST_DIR/.bashrc"
echo "Zsh: $TEST_DIR/.zshrc"
echo ""
echo "Manual usage:"
echo " bash --rcfile $TEST_DIR/.bashrc -i"
echo " ZDOTDIR=$TEST_DIR zsh -i"
;;
*)
echo "β Invalid choice"
exit 1
;;
esac
echo ""
echo "π§Ή Clean up test directory? (y/N)"
read -p "> " cleanup
if [[ "$cleanup" =~ ^[Yy] ]]; then
rm -rf "$TEST_DIR"
echo "β
Test directory cleaned up"
fi