[开源] SwitchEnvs 一个管理、切换多个环境变量方案的工具 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
junjian2016
V2EX    分享创造

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

  •  
  •   junjian2016 1 月 19 日 1061 次点击

    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

    SwitchEnvs Screenshot

    Features

    • Multiple Environment Schemes: Create, edit, duplicate, and delete environment variable schemes
    • One-Click Switch: Quickly switch between different environment configurations
    • Persistent Storage: Schemes are saved locally and persist across sessions
    • Shell Integration: Automatically updates your shell environment (~/.switch_env)
    • Import/Export: Share your environment schemes with others
    • Custom Window: macOS-style frameless window with transparent background and rounded corners
    • Auto-Reload: Changes to the currently applied scheme are immediately reflected

    Tech Stack

    • Backend: Go with Wails v2
    • Frontend: React 18 + TypeScript + Tailwind CSS
    • Runtime: Native desktop application

    Getting Started

    Prerequisites

    • Go 1.23+
    • Node.js & npm
    • Wails CLI

    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

    • Select a scheme from the sidebar
    • Click "Apply" to switch to that environment configuration

    Exporting/Importing

    • Use the export button to save your schemes as JSON
    • Use the import button to load schemes from a JSON file

    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:

    • Scheme CRUD operations (Save, Get, Delete, Duplicate)
    • Applying schemes to the system
    • Writing environment variables to shell config
    • Import/Export functionality

    Frontend (React + TypeScript)

    The frontend provides:

    • Interactive UI for managing environment schemes
    • Real-time updates when switching schemes
    • Import/Export dialogs
    • Custom window controls (minimize, close)

    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

    5 条回复    2026-01-22 15:20:32 +08:00
    ZiLong
        1
    ZiLong  
       1 月 19 日
    前几天再用 switchhosts 的时候还在想为啥没把环境管理做一起,因为本地启动多个微服务,很多配置项用环境管理更简单
    junjian2016
        2
    junjian2016  
    OP
       1 月 20 日
    @ZiLong 欢迎使用
    efxy107
        3
    efxy107  
       1 月 21 日
    不知是我使用有误还是操作不当,怎么在 win10 下设置了个环境变量,测试获取不到值呢
    junjian2016
        4
    junjian2016  
    OP
       1 月 22 日
    @efxy107 目前仅支持 MACOS ,这两天可以把 Windows 支持也加上去
    efxy107
        5
    efxy107  
       1 月 22 日
    @junjian2016 #4 好的,更新后可以通知下我在试试;我是想用来切换不同 aicoding 中转站对应的秘钥
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     4504 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 22ms UTC 05:59 PVG 13:59 LAX 21:59 JFK 00:59
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86