[开源] SwitchEnvs 一个管理、切换多个环境变量方案的工具

1 月 19 日
 junjian2016

SwitchEnvs 是一个管理、切换多个环境变量方案的工具,可视化对本机环境变量进行增删改查。(类似于 SwitchHosts )

Github 地址: https://github.com/dean2021/SwitchEnvs

README 如下:

SwitchEnvs

A desktop environment variable management tool built with Wails (Go + React/TypeScript). SwitchEnvs allows you to manage, save, and switch between multiple environment variable configurations with ease.

Screenshot

Features

Tech Stack

Getting Started

Prerequisites

Installation

# Install Wails CLI if not already installed
go install github.com/wailsapp/wails/v2/cmd/wails@latest

# Clone and setup
git clone https://github.com/dean2021/SwitchEnvs.git
cd SwitchEnvs

# Install frontend dependencies
cd frontend && npm install

# Return to project root
cd ..

Development

Run the application in development mode with hot reload:

wails dev

This will start both the Go backend and the React frontend with automatic rebuilding.

Building

Build the production version:

wails build

Build for specific platforms:

# macOS ARM64
wails build -platform darwin/arm64

# Windows AMD64
wails build -platform windows/amd64

# Linux
wails build -platform linux/amd64

Usage

Creating a Scheme

  1. Click "Add Scheme" to create a new environment scheme
  2. Add key-value pairs for your environment variables
  3. Click "Apply" to activate the scheme

Switching Schemes

Exporting/Importing

File Structure

SwitchEnvs/
├── app.go              # Main application logic (Go)
├── main.go             # Application entry point
├── wails.json          # Wails configuration
├── frontend/           # React frontend
│   ├── src/
│   │   ├── App.tsx     # Main React component
│   │   ├── main.tsx    # React entry point
│   │   ├── style.css   # Global styles
│   │   └── types/      # TypeScript type definitions
│   ├── package.json
│   └── vite.config.ts
└── build/              # Build configurations

Data Storage

Path Purpose
~/.switchenvs/schemes.json All saved schemes in JSON format
~/.switchenvs/applied_scheme.json Persisted applied scheme name
~/.switch_env Shell script with export KEY="value" entries

Architecture

Backend (Go)

The Go backend handles:

Frontend (React + TypeScript)

The frontend provides:

Shell Integration

SwitchEnvs writes environment variables to ~/.switch_env and automatically adds a source command to ~/.zshrc. To use the environment variables in your terminal:

source ~/.switch_env

Or restart your terminal session.

License

MIT License

1351 次点击
所在节点    分享创造
5 条回复
ZiLong
1 月 19 日
前几天再用 switchhosts 的时候还在想为啥没把环境管理做一起,因为本地启动多个微服务,很多配置项用环境管理更简单
junjian2016
1 月 20 日
@ZiLong 欢迎使用
efxy107
1 月 21 日
不知是我使用有误还是操作不当,怎么在 win10 下设置了个环境变量,测试获取不到值呢
junjian2016
1 月 22 日
@efxy107 目前仅支持 MACOS ,这两天可以把 Windows 支持也加上去
efxy107
1 月 22 日
@junjian2016 #4 好的,更新后可以通知下我在试试;我是想用来切换不同 aicoding 中转站对应的秘钥

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1186893

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX