V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
junjian2016
V2EX  ›  分享创造

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

  •  
  •   junjian2016 · 3 天前 · 816 次点击

    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  
       3 天前
    前几天再用 switchhosts 的时候还在想为啥没把环境管理做一起,因为本地启动多个微服务,很多配置项用环境管理更简单
    junjian2016
        2
    junjian2016  
    OP
       2 天前
    @ZiLong 欢迎使用
    efxy107
        3
    efxy107  
       1 天前
    不知是我使用有误还是操作不当,怎么在 win10 下设置了个环境变量,测试获取不到值呢
    junjian2016
        4
    junjian2016  
    OP
       1 天前
    @efxy107 目前仅支持 MACOS ,这两天可以把 Windows 支持也加上去
    efxy107
        5
    efxy107  
       18 小时 58 分钟前
    @junjian2016 #4 好的,更新后可以通知下我在试试;我是想用来切换不同 aicoding 中转站对应的秘钥
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   5660 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 02:18 · PVG 10:18 · LAX 18:18 · JFK 21:18
    ♥ Do have faith in what you're doing.