codex-sw 0.3.0

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.
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ ROOT="$(cd "$(dirname "$0")/.." && pwd)"
5
+ SW="$ROOT/scripts/codex-sw"
6
+
7
+ bash -n "$SW"
8
+
9
+ TMPBASE="$(mktemp -d /tmp/codex-switcher-test.XXXXXX)"
10
+ STATE="$TMPBASE/state"
11
+ PROFILES="$TMPBASE/profiles"
12
+ BIN="$TMPBASE/bin"
13
+ mkdir -p "$BIN"
14
+
15
+ cleanup() {
16
+ pkill -f "$BIN/fake-codex-app" >/dev/null 2>&1 || true
17
+ rm -rf "$TMPBASE"
18
+ }
19
+ trap cleanup EXIT INT TERM
20
+
21
+ cat > "$BIN/codex" <<'FAKE'
22
+ #!/usr/bin/env bash
23
+ set -euo pipefail
24
+ if [[ "${1:-}" == "login" && "${2:-}" == "status" ]]; then
25
+ if [[ -f "${CODEX_HOME}/auth.json" ]]; then
26
+ echo "Logged in"
27
+ exit 0
28
+ fi
29
+ echo "Not logged in"
30
+ exit 1
31
+ fi
32
+ if [[ "${1:-}" == "login" ]]; then
33
+ mkdir -p "$CODEX_HOME"
34
+ echo '{"auth_mode":"api_key"}' > "$CODEX_HOME/auth.json"
35
+ exit 0
36
+ fi
37
+ if [[ "${1:-}" == "logout" ]]; then
38
+ rm -f "$CODEX_HOME/auth.json"
39
+ exit 0
40
+ fi
41
+ exit 0
42
+ FAKE
43
+ chmod +x "$BIN/codex"
44
+
45
+ cat > "$BIN/fake-codex-app" <<'APP'
46
+ #!/usr/bin/env bash
47
+ set -euo pipefail
48
+ sleep 30
49
+ APP
50
+ chmod +x "$BIN/fake-codex-app"
51
+
52
+ export PATH="$BIN:$PATH"
53
+ export CODEX_SWITCHER_STATE_DIR="$STATE"
54
+ export CODEX_SWITCHER_PROFILES_DIR="$PROFILES"
55
+ export CODEX_SWITCHER_APP_BIN="$BIN/fake-codex-app"
56
+ export CODEX_SWITCHER_LOCK_WAIT_SECONDS=2
57
+
58
+ check_out="$("$SW" check)"
59
+ echo "$check_out" | grep -q "check: ok"
60
+ init_out="$("$SW" init --dry-run)"
61
+ echo "$init_out" | grep -q "\[dry-run\]"
62
+
63
+ "$SW" add work
64
+ "$SW" add personal
65
+ "$SW" use personal
66
+ [[ "$("$SW" current cli)" == "personal" ]]
67
+
68
+ "$SW" login personal
69
+ "$SW" app use work
70
+ "$SW" login work
71
+ [[ "$("$SW" app current)" == "work" ]]
72
+
73
+ set +e
74
+ "$SW" status >/tmp/codex_sw_status_1
75
+ status_rc=$?
76
+ set -e
77
+ [[ "$status_rc" -eq 0 ]]
78
+ grep -q "cli(personal): logged-in" /tmp/codex_sw_status_1
79
+ grep -q "app(work): logged-in" /tmp/codex_sw_status_1
80
+
81
+ "$SW" logout personal
82
+ set +e
83
+ "$SW" status >/tmp/codex_sw_status_2
84
+ status_rc=$?
85
+ set -e
86
+ [[ "$status_rc" -eq 1 ]]
87
+ grep -q "cli(personal): not-logged-in" /tmp/codex_sw_status_2
88
+
89
+ "$SW" app status >/tmp/codex_sw_app_status_1
90
+ [[ "$?" -eq 0 ]]
91
+ grep -q "running" /tmp/codex_sw_app_status_1
92
+
93
+ "$SW" app stop
94
+ set +e
95
+ "$SW" app status >/tmp/codex_sw_app_status_2
96
+ app_status_rc=$?
97
+ set -e
98
+ [[ "$app_status_rc" -eq 1 ]]
99
+
100
+ printf '***bad***\n' > "$STATE/current_cli"
101
+ set +e
102
+ "$SW" status >/tmp/codex_sw_status_3
103
+ status_rc=$?
104
+ set -e
105
+ [[ "$status_rc" -eq 2 ]]
106
+
107
+ "$SW" recover
108
+ validate_cli="$("$SW" current cli)"
109
+ [[ -n "$validate_cli" ]]
110
+
111
+ doctor_out="$("$SW" doctor --fix)"
112
+ echo "$doctor_out" | grep -q "doctor --fix: completed"
113
+ check_out="$("$SW" check)"
114
+ echo "$check_out" | grep -q "check: ok"
115
+
116
+ "$SW" remove work --force
117
+ "$SW" list >/tmp/codex_sw_list
118
+ grep -q "personal" /tmp/codex_sw_list
119
+
120
+ echo "smoke-test: ok"
@@ -0,0 +1,3 @@
1
+ # Skills
2
+
3
+ Place plugin-specific skills here if needed.
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ ROOT="$(cd "$(dirname "$0")/.." && pwd)"
5
+ BIN="$ROOT/plugins/codex-switcher/scripts/codex-sw"
6
+
7
+ [[ -x "$BIN" ]] || { echo "codex-sw binary not executable: $BIN" >&2; exit 1; }
8
+
9
+ mkdir -p "$HOME/.local/bin"
10
+ ln -sf "$BIN" "$HOME/.local/bin/codex-sw"
11
+ ln -sf "$ROOT/plugins/codex-switcher/scripts/codex-switcher" "$HOME/.local/bin/codex-switcher"
12
+
13
+ "$BIN" init --shell "$(basename "${SHELL:-zsh}")"
14
+
15
+ echo "Installed codex-sw. Run: source ~/.zshrc (or your shell rc file)"
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ PURGE="false"
5
+ if [[ "${1:-}" == "--purge" ]]; then
6
+ PURGE="true"
7
+ elif [[ -n "${1:-}" ]]; then
8
+ echo "Usage: $0 [--purge]" >&2
9
+ exit 1
10
+ fi
11
+
12
+ remove_block() {
13
+ local file="$1"
14
+ local start="# >>> codex-sw init >>>"
15
+ local end="# <<< codex-sw init <<<"
16
+ [[ -f "$file" ]] || return 0
17
+
18
+ awk -v s="$start" -v e="$end" '
19
+ $0 == s {skip=1; next}
20
+ $0 == e {skip=0; next}
21
+ skip != 1 {print}
22
+ ' "$file" > "$file.tmp"
23
+ mv "$file.tmp" "$file"
24
+ }
25
+
26
+ rm -f "$HOME/.local/bin/codex-sw" "$HOME/.local/bin/codex-switcher"
27
+ remove_block "$HOME/.zshrc"
28
+ remove_block "$HOME/.bashrc"
29
+
30
+ if [[ "$PURGE" == "true" ]]; then
31
+ rm -rf "$HOME/.codex-switcher" "$HOME/.codex-profiles"
32
+ fi
33
+
34
+ echo "Uninstalled codex-sw."
35
+ if [[ "$PURGE" == "true" ]]; then
36
+ echo "State and profiles removed."
37
+ fi