The best way to control Claude Code, Codex and more from any computer or phone
| 1 | #!/bin/sh |
| 2 | # Installs the T3 Code CLI from a GitHub Release archive. Needs only sh, tar, |
| 3 | # sha256sum or shasum, and curl or wget; no Node, npm, or compiler. |
| 4 | # |
| 5 | # curl -fsSL https://t3.codes/install.sh | sh |
| 6 | # |
| 7 | # Environment: |
| 8 | # T3CODE_CHANNEL release train to follow: stable, nightly, or preview |
| 9 | # (default: stable; preview is a maintainers' test train) |
| 10 | # T3CODE_VERSION exact version to install (overrides T3CODE_CHANNEL) |
| 11 | # T3CODE_HOME T3 home directory (default: ~/.t3) |
| 12 | # T3CODE_INSTALL_BIN_DIR where the `t3` command goes (default: ~/.local/bin) |
| 13 | # T3CODE_RELEASE_BASE_URL mirror for releases/download (default: GitHub) |
| 14 | # |
| 15 | # The archive is unpacked into $T3CODE_HOME/runtime/versions/<version>, the |
| 16 | # same layout `t3 service install` uses, so the service reuses this download |
| 17 | # instead of fetching the release again. |
| 18 | set -eu |
| 19 | |
| 20 | repo="pingdotgg/t3code" |
| 21 | base_url="${T3CODE_RELEASE_BASE_URL:-https://github.com/${repo}/releases/download}" |
| 22 | t3_home="${T3CODE_HOME:-$HOME/.t3}" |
| 23 | case "$t3_home" in |
| 24 | /*) ;; |
| 25 | *) |
| 26 | # Preserve cwd's trailing newlines; trim only pwd's newline and the sentinel. |
| 27 | t3_cwd="$(pwd -P && printf .)" |
| 28 | t3_home="${t3_cwd%??}/$t3_home" |
| 29 | ;; |
| 30 | esac |
| 31 | bin_dir="${T3CODE_INSTALL_BIN_DIR:-$HOME/.local/bin}" |
| 32 | # Trailing slashes would put `//` in the paths the t3 command guard compares. |
| 33 | while [ "${t3_home%/}" != "$t3_home" ] && [ "$t3_home" != / ]; do t3_home="${t3_home%/}"; done |
| 34 | while [ "${bin_dir%/}" != "$bin_dir" ] && [ "$bin_dir" != / ]; do bin_dir="${bin_dir%/}"; done |
| 35 | # Absolute, so the PATH hint never adds a folder that changes with the working directory. |
| 36 | case "$bin_dir" in /*) ;; *) bin_dir="$PWD/$bin_dir" ;; esac |
| 37 | |
| 38 | fail() { |
| 39 | printf '\nt3 install: %s\n' "$1" >&2 |
| 40 | exit 1 |
| 41 | } |
| 42 | |
| 43 | # ANSI stays on stderr, so `curl ... | sh` still gets progress. |
| 44 | interactive=false |
| 45 | if [ -t 2 ] && [ "${TERM:-}" != dumb ]; then interactive=true; fi |
| 46 | reset= bold= muted= accent= green= |
| 47 | if "$interactive" && [ -z "${NO_COLOR:-}" ]; then |
| 48 | reset="$(printf '\033[0m')"; bold="$(printf '\033[1m')" |
| 49 | muted="$(printf '\033[2m')"; accent="$(printf '\033[94m')"; green="$(printf '\033[32m')" |
| 50 | fi |
| 51 | step() { |
| 52 | if "$interactive"; then printf '\r\033[2K %s%s%s' "$muted" "$1" "$reset" >&2 |
| 53 | else printf ' %s\n' "$1" >&2; fi |
| 54 | } |
| 55 | if "$interactive"; then |
| 56 | printf '\n%s' "$bold" >&2 |
| 57 | printf ' %s\n' '██████████ ████████ ' >&2 |
| 58 | printf ' %s\n' ' ███ ▄██▀ T3 Code' >&2 |
| 59 | printf ' %s%s %sCLI installer%s\n' ' ███ ████▄ ' "$reset" "$muted" "$reset$bold" >&2 |
| 60 | printf ' %s\n' ' ███ ▄ ███' >&2 |
| 61 | printf ' %s\n' ' ███ ███████▀ ' >&2 |
| 62 | printf '%s\n' "$reset" >&2 |
| 63 | fi |
| 64 | step "Finding your release..." |
| 65 | |
| 66 | # Sleeps 1, 2, then 4 s before retrying a 408, 429, 5xx, or network error. Not curl |
| 67 | # --retry: older curl waits out any Retry-After, however long. |
| 68 | backoff() { |
| 69 | case "$1" in 408 | 429) ;; 4??) return 1 ;; esac |
| 70 | [ "$2" -lt 4 ] && sleep "$((1 << ($2 - 1)))" |
| 71 | } |
| 72 | |
| 73 | # Exit 44 on a 404 so callers can tell "no such asset" from a network failure. |
| 74 | fetch() { |
| 75 | if command -v curl >/dev/null 2>&1; then |
| 76 | attempt=1 |
| 77 | while :; do |
| 78 | code=0; status="$(curl -sSL -H "Accept: ${3:-*/*}" -w '%{http_code}' "$1" -o "$2")" || code=$? |
| 79 | case "$code:$status" in 0:2??) break ;; esac |
| 80 | backoff "$status" "$attempt" || break |
| 81 | attempt=$((attempt + 1)) |
| 82 | done |
| 83 | [ "$code" -eq 0 ] || return 1 |
| 84 | case "$status" in |
| 85 | 2??) return 0 ;; |
| 86 | 404) return 44 ;; |
| 87 | *) printf 'GET %s returned HTTP %s\n' "$1" "$status" >&2; return 1 ;; |
| 88 | esac |
| 89 | elif command -v wget >/dev/null 2>&1; then |
| 90 | wget -q --server-response --header="Accept: ${3:-*/*}" "$1" -O "$2" 2>"$2.headers" && rm -f "$2.headers" && return 0 |
| 91 | if grep -q ' 404 ' "$2.headers" 2>/dev/null; then rm -f "$2.headers"; return 44; fi |
| 92 | cat "$2.headers" >&2; rm -f "$2.headers"; return 1 |
| 93 | else |
| 94 | fail "curl or wget is required" |
| 95 | fi |
| 96 | } |
| 97 | |
| 98 | mb() { |
| 99 | tenths=$((($1 * 10 + 524288) / 1048576)) |
| 100 | printf '%s.%s' "$((tenths / 10))" "$((tenths % 10))" |
| 101 | } |
| 102 | download_start() { |
| 103 | if command -v curl >/dev/null 2>&1; then |
| 104 | curl -fsSL -w '%{http_code}' -D "$2.headers" "$1" -o "$2" >"$2.status" 2>"$2.errors" & |
| 105 | else |
| 106 | wget -q --server-response "$1" -O "$2" 2>"$2.headers" & |
| 107 | fi |
| 108 | download_pid=$! |
| 109 | } |
| 110 | # Reaps the finished download, then restarts it if curl hit a transient error. |
| 111 | download_retry() { |
| 112 | result=0; wait "$download_pid" || result=$? |
| 113 | download_pid= |
| 114 | [ "$result" -ne 0 ] && [ -f "$2.status" ] && backoff "$(cat "$2.status")" "$attempt" || return 1 |
| 115 | attempt=$((attempt + 1)) |
| 116 | download_start "$1" "$2" |
| 117 | } |
| 118 | # Poll the file written by the downloader; no progress-output parsing or extra request. |
| 119 | download() { |
| 120 | if ! "$interactive"; then fetch "$1" "$2"; return; fi |
| 121 | attempt=1 |
| 122 | download_start "$1" "$2" |
| 123 | previous=-1 |
| 124 | cr="$(printf '\r')" |
| 125 | while kill -0 "$download_pid" 2>/dev/null || download_retry "$1" "$2"; do |
| 126 | bytes=0; total=0 |
| 127 | if [ -f "$2" ]; then bytes="$(wc -c < "$2")"; fi |
| 128 | if [ -f "$2.headers" ]; then |
| 129 | while read -r key value; do |
| 130 | case "$key" in |
| 131 | HTTP/*) total=0 ;; |
| 132 | [Cc]ontent-[Ll]ength:) total="${value%"$cr"}" ;; |
| 133 | esac |
| 134 | done < "$2.headers" |
| 135 | fi |
| 136 | case "$total" in ''|*[!0-9]*) total=0 ;; esac |
| 137 | if [ "$bytes" -ne "$previous" ]; then |
| 138 | if [ "$total" -gt 0 ]; then |
| 139 | percent=$((bytes * 100 / total)); [ "$percent" -le 100 ] || percent=100 |
| 140 | filled=$((percent * 32 / 100)); bar=; rest=; n=0 |
| 141 | while [ "$n" -lt 32 ]; do |
| 142 | if [ "$n" -lt "$filled" ]; then bar="${bar}■"; else rest="${rest}·"; fi |
| 143 | n=$((n + 1)) |
| 144 | done |
| 145 | printf '\r\033[2K %s%s%s%s%s %3d%% %s%s / %s MB%s' "$accent" "$bar" "$reset$muted" "$rest" "$reset" "$percent" "$muted" "$(mb "$bytes")" "$(mb "$total")" "$reset" >&2 |
| 146 | else |
| 147 | printf '\r\033[2K %sDownloading%s %s MB' "$muted" "$reset" "$(mb "$bytes")" >&2 |
| 148 | fi |
| 149 | previous="$bytes" |
| 150 | fi |
| 151 | sleep 0.1 |
| 152 | done |
| 153 | if [ "$result" -ne 0 ]; then |
| 154 | printf '\n' >&2 |
| 155 | if [ -f "$2.errors" ]; then cat "$2.errors" >&2; else cat "$2.headers" >&2; fi |
| 156 | return "$result" |
| 157 | fi |
| 158 | size="$(mb "$(wc -c < "$2")")" |
| 159 | printf '\r\033[2K %s■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■%s 100%% %s%s / %s MB%s\n' "$accent" "$reset" "$muted" "$size" "$size" "$reset" >&2 |
| 160 | rm -f "$2.headers" "$2.errors" "$2.status" |
| 161 | } |
| 162 | |
| 163 | case "$(uname -s)" in |
| 164 | Darwin) platform="darwin" ;; |
| 165 | Linux) platform="linux" ;; |
| 166 | *) fail "unsupported operating system $(uname -s); use the desktop app or npm" ;; |
| 167 | esac |
| 168 | case "$(uname -m)" in |
| 169 | arm64 | aarch64) arch="arm64" ;; |
| 170 | x86_64 | amd64) arch="x64" ;; |
| 171 | *) fail "unsupported architecture $(uname -m)" ;; |
| 172 | esac |
| 173 | if [ "${platform}-${arch}" = darwin-x64 ]; then |
| 174 | fail "there is no t3 CLI for Intel Macs. Install the desktop app from https://t3.codes/download, or run a server from source: https://github.com/${repo}/blob/main/docs/user/install.md#intel-macs" |
| 175 | fi |
| 176 | command -v tar >/dev/null 2>&1 || fail "tar is required" |
| 177 | if command -v sha256sum >/dev/null 2>&1; then |
| 178 | checksum() { sha256sum < "$1" | cut -d' ' -f1; } |
| 179 | elif command -v shasum >/dev/null 2>&1; then |
| 180 | checksum() { shasum -a 256 < "$1" | cut -d' ' -f1; } |
| 181 | else |
| 182 | fail "sha256sum or shasum is required" |
| 183 | fi |
| 184 | |
| 185 | channel="${T3CODE_CHANNEL:-stable}" |
| 186 | version="${T3CODE_VERSION:-}" |
| 187 | if [ -z "$version" ]; then |
| 188 | case "$channel" in |
| 189 | stable) tag_pattern='v\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)' ;; |
| 190 | nightly | preview) tag_pattern="v\([0-9][^\"]*-${channel}\.[0-9]*\.[0-9]*\)" ;; |
| 191 | *) fail "T3CODE_CHANNEL must be stable, nightly, or preview" ;; |
| 192 | esac |
| 193 | tmp_index="$(mktemp)" |
| 194 | if [ "$channel" = stable ]; then |
| 195 | # release.yml marks only plain stable releases latest. This is a github.com |
| 196 | # page, so it is not cut off by a page of newer nightlies or the API quota. |
| 197 | fetch "https://github.com/${repo}/releases/latest" "$tmp_index" application/json |
| 198 | version="$(sed -n "s/.*\"tag_name\": *\"${tag_pattern}\".*/\1/p" "$tmp_index" | head -n 1)" |
| 199 | else |
| 200 | page=1 |
| 201 | while [ -z "$version" ] && [ "$page" -le 10 ]; do |
| 202 | fetch "https://api.github.com/repos/${repo}/releases?per_page=100&page=${page}" "$tmp_index" |
| 203 | version="$(sed -n "s/.*\"tag_name\": *\"${tag_pattern}\".*/\1/p" "$tmp_index" | head -n 1)" |
| 204 | grep -q '"tag_name"' "$tmp_index" || break |
| 205 | page=$((page + 1)) |
| 206 | done |
| 207 | fi |
| 208 | rm -f "$tmp_index" |
| 209 | [ -n "$version" ] || fail "could not find a ${channel} release; set T3CODE_VERSION" |
| 210 | fi |
| 211 | case "$version" in |
| 212 | *-preview.*) |
| 213 | printf '%s\n' \ |
| 214 | "t3 ${version} is a preview build." \ |
| 215 | " Preview builds are cut by maintainers from unreleased branches to exercise the release" \ |
| 216 | " pipeline. They can be broken, receive no fixes, and are never offered as updates." \ |
| 217 | " Set T3CODE_CHANNEL=stable (the default) for a supported build." >&2 |
| 218 | if [ "$channel" != "preview" ] && [ -z "${T3CODE_VERSION:-}" ]; then |
| 219 | fail "refusing a preview build that was not explicitly requested" |
| 220 | fi |
| 221 | ;; |
| 222 | esac |
| 223 | |
| 224 | stem="t3-${version}-${platform}-${arch}" |
| 225 | archive="${stem}.tar.gz" |
| 226 | versions_dir="${t3_home}/runtime/versions" |
| 227 | target_dir="${versions_dir}/${version}" |
| 228 | |
| 229 | if [ -f "${target_dir}/.install-complete" ] && [ "$(cat "${target_dir}/.install-complete")" = "$version" ]; then |
| 230 | step "Version ${version} is already downloaded." |
| 231 | else |
| 232 | mkdir -p "$versions_dir" |
| 233 | staging="$(mktemp -d "${versions_dir}/.staging-XXXXXX")" |
| 234 | download_pid= |
| 235 | trap '[ -z "$download_pid" ] || { kill "$download_pid" 2>/dev/null || true; wait "$download_pid" 2>/dev/null || true; }; rm -rf "$staging"' EXIT |
| 236 | trap 'printf "\n" >&2; exit 130' INT |
| 237 | trap 'printf "\n" >&2; exit 143' TERM |
| 238 | |
| 239 | if "$interactive"; then printf '\r\033[2K' >&2; fi |
| 240 | printf ' %sInstalling%s T3 Code %s%s%s\n\n' "$muted" "$reset" "$bold" "$version" "$reset" >&2 |
| 241 | step "Downloading..." |
| 242 | fetch_status=0 |
| 243 | fetch "${base_url}/v${version}/SHA256SUMS" "${staging}/SHA256SUMS" || fetch_status=$? |
| 244 | if [ "$fetch_status" -eq 44 ]; then |
| 245 | fail "t3 ${version} has no release archive for ${platform}-${arch}; releases before the self-contained CLI can only be installed with \`npm install -g t3@${version}\`" |
| 246 | elif [ "$fetch_status" -ne 0 ]; then |
| 247 | fail "could not download the release checksums" |
| 248 | fi |
| 249 | expected="$(grep " \*\{0,1\}${archive}\$" "${staging}/SHA256SUMS" | cut -d' ' -f1)" |
| 250 | [ -n "$expected" ] || fail "t3 ${version} has no release archive for ${platform}-${arch}" |
| 251 | download "${base_url}/v${version}/${archive}" "${staging}/${archive}" || fail "could not download ${archive}" |
| 252 | |
| 253 | step "Verifying the download..." |
| 254 | actual="$(checksum "${staging}/${archive}")" |
| 255 | [ "$actual" = "$expected" ] || fail "checksum mismatch for ${archive}" |
| 256 | |
| 257 | step "Extracting T3 Code..." |
| 258 | tar -xzf "${staging}/${archive}" -C "$staging" --strip-components=1 |
| 259 | rm -f "${staging}/${archive}" "${staging}/SHA256SUMS" |
| 260 | "${staging}/t3" --version >/dev/null || fail "the downloaded executable does not run" |
| 261 | printf '%s\n' "$version" > "${staging}/.install-complete" |
| 262 | |
| 263 | rm -rf "$target_dir" |
| 264 | mv "$staging" "$target_dir" |
| 265 | # When a concurrent install published first, mv moved this copy inside it; keep only theirs. |
| 266 | rm -rf "${target_dir}/${staging##*/}" |
| 267 | trap - EXIT |
| 268 | fi |
| 269 | |
| 270 | step "Setting up the t3 command..." |
| 271 | mkdir -p "$bin_dir" |
| 272 | # Exec by absolute path: through a symlink, argv0 is the link, and the Cursor SDK looks for its |
| 273 | # helpers beside it. t3 update and t3 install write the same script. |
| 274 | nl=' |
| 275 | ' |
| 276 | launcher_head="#!/bin/sh${nl}exec '" |
| 277 | launcher_tail="' \"\$@\"${nl}" |
| 278 | # The x keeps a trailing newline in the path through command substitution. |
| 279 | launcher_script() { |
| 280 | quoted="$(printf '%sx' "$1" | sed "s/'/'\\\\''/g")" |
| 281 | printf '%s%s%s' "$launcher_head" "${quoted%x}" "$launcher_tail" |
| 282 | } |
| 283 | # The executable an unedited launcher script at $1 runs; a user's own wrapper prints nothing. |
| 284 | script_t3() { |
| 285 | [ -f "$1" ] && [ ! -L "$1" ] && [ "$(wc -c < "$1")" -le 4096 ] || return 0 |
| 286 | contents="$(cat "$1"; printf x)" |
| 287 | contents="${contents%x}" |
| 288 | case "$contents" in "$launcher_head"*"$launcher_tail") ;; *) return 0 ;; esac |
| 289 | quoted="${contents#"$launcher_head"}" |
| 290 | unquoted="$(printf '%sx' "${quoted%"$launcher_tail"}" | sed "s/'\\\\''/'/g")" |
| 291 | unquoted="${unquoted%x}" |
| 292 | [ -n "$unquoted" ] && [ "$(launcher_script "$unquoted"; printf x)" = "${contents}x" ] && printf '%s' "$unquoted" |
| 293 | return 0 |
| 294 | } |
| 295 | # Replace only this home's own t3 launchers: into its versions, or the desktop app's launcher. |
| 296 | # Anything else (a user's script, a copied binary) belongs to someone else. |
| 297 | # Exactly <versions>/<version>/t3 ($1 under $2), never another program inside a version. |
| 298 | version_t3() { |
| 299 | case "$1" in "$2"/*) ;; *) return 1 ;; esac |
| 300 | case "${1#"$2"/}" in */*/*) return 1 ;; */t3) return 0 ;; *) return 1 ;; esac |
| 301 | } |
| 302 | slot_empty=true |
| 303 | if [ -e "${bin_dir}/t3" ] || [ -L "${bin_dir}/t3" ]; then |
| 304 | slot_empty=false |
| 305 | owned=false |
| 306 | real_versions_dir="$(CDPATH='' cd -P -- "$versions_dir" && pwd)" |
| 307 | if [ -L "${bin_dir}/t3" ]; then |
| 308 | existing="$(readlink "${bin_dir}/t3" 2>/dev/null || true)" |
| 309 | case "$existing" in /*) ;; *) existing="${bin_dir}/${existing}" ;; esac |
| 310 | else |
| 311 | existing="$(script_t3 "${bin_dir}/t3")" |
| 312 | fi |
| 313 | if [ -n "$existing" ]; then |
| 314 | # Through a symlinked T3 home the path names the alias; resolve its folder to compare. |
| 315 | existing_dir="$(CDPATH='' cd -P -- "$(dirname -- "$existing")" 2>/dev/null && pwd || true)" |
| 316 | # The text alone counts only without . or .. segments (a pruned version leaves a dangling path). |
| 317 | case "$existing" in |
| 318 | */./* | */../* | */. | */..) ;; |
| 319 | *) |
| 320 | if version_t3 "$existing" "$versions_dir" || version_t3 "$existing" "$real_versions_dir" || |
| 321 | [ "$existing" = "${t3_home}/bin/t3" ]; then owned=true; fi |
| 322 | ;; |
| 323 | esac |
| 324 | if [ -n "$existing_dir" ] && version_t3 "${existing_dir}/${existing##*/}" "$real_versions_dir"; then |
| 325 | owned=true |
| 326 | fi |
| 327 | fi |
| 328 | "$owned" || fail "another t3 is already at ${bin_dir}/t3. Remove it and run this again, or run ${target_dir}/t3 directly." |
| 329 | fi |
| 330 | launcher_tmp="$(mktemp "${bin_dir}/.t3.XXXXXX")" |
| 331 | trap 'rm -f "$launcher_tmp"' EXIT |
| 332 | trap 'exit 130' INT |
| 333 | trap 'exit 143' TERM |
| 334 | launcher_script "${target_dir}/t3" > "$launcher_tmp" |
| 335 | chmod 755 "$launcher_tmp" |
| 336 | # An empty spot is hard-linked without -f, so a file that appears after the check above is kept. |
| 337 | if "$slot_empty"; then |
| 338 | ln "$launcher_tmp" "${bin_dir}/t3" || fail "could not write ${bin_dir}/t3; something else was created there." |
| 339 | else |
| 340 | # Known race, accepted: a file written here after the ownership check above is overwritten. |
| 341 | # mv replaces a legacy symlink rather than writing through it. |
| 342 | mv -f "$launcher_tmp" "${bin_dir}/t3" |
| 343 | fi |
| 344 | rm -f "$launcher_tmp" |
| 345 | trap - EXIT |
| 346 | # Pruning keeps what this launcher points at; a background service cannot see bin_dir otherwise. |
| 347 | launcher="$(CDPATH='' cd -P -- "$bin_dir" && pwd)/t3" |
| 348 | launchers="${t3_home}/runtime/launchers" |
| 349 | grep -qxF "$launcher" "$launchers" 2>/dev/null || printf '%s\n' "$launcher" >> "$launchers" |
| 350 | if "$interactive"; then printf '\r\033[2K' >&2; fi |
| 351 | printf ' %sInstalled T3 Code %s%s\n\n' "$green" "$version" "$reset" >&2 |
| 352 | # The folder a shell reads its startup file from: $1 when set and safe to paste, else $2 when |
| 353 | # unset. A set but unsafe folder prints nothing, since the default would never be read. |
| 354 | read_from() { |
| 355 | case "$1" in |
| 356 | "") printf '%s' "$2" ;; |
| 357 | /*) case "$1" in *[!A-Za-z0-9_./-]*) ;; *) printf '%s' "$1" ;; esac ;; |
| 358 | esac |
| 359 | } |
| 360 | # A command to paste for zsh, Linux bash, or fish, like `t3 install` prints. macOS bash reads only |
| 361 | # one of several startup files, so no single file is safe to change there. |
| 362 | path_command= |
| 363 | path_rest="$bin_dir" |
| 364 | path_prefix= |
| 365 | case "$bin_dir" in "$HOME"/*) path_rest="${bin_dir#"$HOME"}" path_prefix='$HOME' ;; esac |
| 366 | case "$path_rest" in *[!A-Za-z0-9_./-]*) path_rest= ;; esac |
| 367 | if [ -n "$path_rest" ]; then |
| 368 | # Last on PATH, so it never shadows another t3. |
| 369 | path_line="export PATH=\"\$PATH:${path_prefix}${path_rest}\"" |
| 370 | shell_name="${SHELL:-}" |
| 371 | case "${shell_name##*/}" in |
| 372 | zsh) |
| 373 | # zsh reads .zshrc from ZDOTDIR when it is set; ~/.zshrc would never be read then. |
| 374 | zsh_dir="$(read_from "${ZDOTDIR:-}" '~')" |
| 375 | [ -z "$zsh_dir" ] || path_command="printf '\\n%s\\n' '${path_line}' >> ${zsh_dir}/.zshrc" ;; |
| 376 | bash) [ "$platform" = darwin ] || path_command="printf '\\n%s\\n' '${path_line}' >> ~/.bashrc" ;; |
| 377 | fish) |
| 378 | # --path changes $PATH itself; fish_user_paths would go ahead of the system folders. |
| 379 | config_dir="$(read_from "${XDG_CONFIG_HOME:-}" '~/.config')" |
| 380 | fish_dir="${config_dir}/fish" |
| 381 | [ -z "$config_dir" ] || path_command="mkdir -p ${fish_dir} && printf '\\n%s\\n' 'fish_add_path --append --path ${path_prefix}${path_rest}' >> ${fish_dir}/config.fish" ;; |
| 382 | esac |
| 383 | fi |
| 384 | # A t3 earlier on PATH runs instead; the PATH command adds this folder last. |
| 385 | # A PATH entry with a trailing slash gives `dir//t3`. |
| 386 | first_t3="$(command -v t3 2>/dev/null | tr -s / || true)" |
| 387 | case "$first_t3" in "" | "${bin_dir}/t3") first_t3= ;; esac |
| 388 | if [ -n "$first_t3" ]; then |
| 389 | printf ' Another t3 at %s runs first, so run %s%s/t3%s to use this one.\n\n' "$first_t3" "$bold" "$bin_dir" "$reset" |
| 390 | else |
| 391 | case ":${PATH}:" in |
| 392 | *":${bin_dir}:"* | *":${bin_dir}/:"*) printf ' Run %st3%s to use T3 Code here, or %st3 up%s to use it from your other devices.\n\n' "$bold" "$reset" "$bold" "$reset" ;; |
| 393 | *) |
| 394 | if [ -n "$path_command" ]; then |
| 395 | printf ' %s is not on your PATH yet. Add it with:\n\n %s\n\n Then open a new terminal and run %st3%s.\n\n' "$bin_dir" "$path_command" "$bold" "$reset" |
| 396 | else |
| 397 | printf ' Add %s to your PATH, then run %st3%s.\n\n' "$bin_dir" "$bold" "$reset" |
| 398 | fi |
| 399 | ;; |
| 400 | esac |
| 401 | fi |