Skip to content

🐚 Shell Integration

A process cannot change the environment of the shell that started it. The proxy shell function bridges that gap: it calls the binary, then evaluates what the binary printed. Without it, proxy on cannot affect your session.

  1. Add the init script to Zsh (~/.zshrc):

    Terminal window
    eval "$(tspm init zsh)"
  2. Or to Bash (~/.bashrc):

    Terminal window
    eval "$(tspm init bash)"
  3. Restart your terminal or source the file. This also installs tab completion, so a separate completions step is unnecessary.

Compatible with Powerlevel10k instant prompt — nothing is printed at startup.

If you would rather not run a command at shell startup, copy shell/tspm.zsh or .bash and source it. Those files are generated from init, but the eval form can never go stale.


For proxy on, the shell function calls tspm env on. The binary reads the active profile and prints quoted export statements; the function evaluates that output in the current Zsh or Bash session:

sequenceDiagram
    accTitle: How proxy on updates the current shell
    accDescr: The user runs proxy on through the shell function. It calls env on in the Rust binary, which reads the active profile and returns quoted export statements. The shell evaluates them to update its own environment.
    participant User
    participant Shell as Zsh / Bash
    participant Binary as Rust binary
    User->>Shell: proxy on
    Shell->>Binary: env on
    Binary->>Binary: Read active profile
    Binary-->>Shell: Quoted export statements
    Shell->>Shell: eval applies variables

New commands inherit these variables. proxy off follows the same path with env off and evaluates unset statements instead.


The proxy function forwards anything it does not handle itself to the binary, so proxy <anything> works.

CommandDescription
proxy onEnable the proxy for this shell
proxy offDisable it
proxy use <key>Switch profile and re-apply if the proxy is on
proxy switchInteractive picker, then re-apply
proxy bestSwitch to the fastest profile, then re-apply
proxy <other>Anything else, passed through to the binary

For proxy use, proxy switch and proxy best, re-application happens only after successful selection and when ALL_PROXY is nonempty. The function first saves the selection through the binary, then calls env on and evaluates its output. If ALL_PROXY is empty, selection is saved for the next proxy on. proxy profile use <key> only saves the selection; use proxy on to apply it to your shell.

Plus these standalone functions:

FunctionDescription
proxy_on / proxy_offSame as proxy on / proxy off
proxy_toggleFlip the proxy on or off
proxy_statusNetwork status
proxy_pingLatency to configured endpoints
proxy_diagnoseSocket and endpoint diagnostics
proxy_benchmarkBenchmark every profile
proxy_bestSwitch to the fastest
proxy_switchInteractive picker
proxy_dashDashboard, applying the chosen profile on exit
proxy_run <cmd>Run one command through the proxy
prompt_proxy_statusPrompt indicator (Zsh only)

Note the underscore in proxy_toggle: it is a separate function, not a subcommand of proxy.


Show the active proxy in your prompt. Zsh:

Terminal window
setopt PROMPT_SUBST
RPROMPT='$(tspm prompt)'

Bash:

Terminal window
PS1='$(tspm prompt)'"$PS1"

It prints nothing when no proxy is set, so your prompt is unchanged while the proxy is off.


On the Profiles tab, Enter saves the selected profile, writes quoted export statements to ~/.tspm-eval, and exits the dashboard. The proxy or proxy_dash shell function then evaluates that file and deletes it:

sequenceDiagram
    accTitle: How the dashboard applies a profile on exit
    accDescr: The shell function starts the dashboard. Enter on the Profiles tab saves the selection and writes quoted exports to ~/.tspm-eval. After the dashboard exits, the shell reads, evaluates and deletes that file.
    participant Shell as Zsh / Bash
    participant Dash as Dashboard
    participant File as Export file
    Shell->>Dash: proxy dash
    Note over Dash: Enter on Profiles tab
    Dash->>Dash: Save selected profile
    Dash->>File: Write quoted exports
    Dash-->>Shell: Exit
    Shell->>File: Read exports
    File-->>Shell: Shell statements
    Shell->>Shell: eval applies variables
    Shell->>File: Delete file

Space saves the selected profile while keeping the dashboard open; it does not write exports for the shell. The environment is applied after exiting with Enter.

This only works through the shell function. Running the bare binary leaves the file in place and your session unchanged.

If it does not work, turn on logging:

Terminal window
proxy debug on
proxy dash
cat ~/.tspm-debug.log
proxy debug off

proxy: command not found — the init line is missing from your rc file, or you have not reloaded it. Check with type proxy.

tspm binary not found in PATH — the function is installed but the binary is not on PATH. See INSTALLATION.md.

proxy on runs but tools ignore the proxy — confirm with proxy diagnose, which prints the main proxy variables set in your session (env | grep -i proxy shows all of them). Note that variables are not inherited by shells that were already open.

Diagram

Drag to move. Pinch or scroll to zoom. Keyboard: arrows, +, −, 0.