An interactive Python script for switching between oh-my-opencode configuration files with a user-friendly terminal interface.
- Interactive Menu System: Colorized terminal UI with numbered selection
- Configuration Preview: View detailed contents of configuration files before applying (
d#command) - Safe Operations: Automatic backup creation before switching configurations
- UTF-8 Support: Smart box drawing characters with ASCII fallback for compatibility
- Keyboard Navigation: Intuitive controls with space/enter for navigation
- Current Config Indicator: Clear visual indication of the currently active configuration
- Backup Management: Automatic backup file management with restore capability
- Python 3.6+ (3.7+ recommended for best performance)
- oh-my-opencode installed with configuration directory at
~/.config/opencode/ - Unix-like system (Linux, macOS, or WSL)
- Clone or download this repository:
git clone <repository-url>
cd switcher-oh-my-opencode-configuration- Run the setup script:
./setup.shThe script will:
- Install the script to
~/.local/bin/ - Make it executable
- Check if the directory is in your PATH
- Verify the installation
- Ensure
~/.local/binis in your PATH:
# Add to your shell profile (choose one)
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
# or for zsh:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
# Then reload:
source ~/.bashrc # or source ~/.zshrc- Clone or copy this repository:
git clone <repository-url>
cd switcher-oh-my-opencode-configuration- Make the script executable:
chmod +x switch_oh-my-opencode_config.py- Copy to your local bin directory:
mkdir -p ~/.local/bin
cp switch_oh-my-opencode_config.py ~/.local/bin/- Ensure
~/.local/binis in your PATH (as shown above)
Run the script:
switch_oh-my-opencode_config.pyOr with explicit Python:
python3 ~/.local/bin/switch_oh-my-opencode_config.pyCheck the script version:
switch_oh-my-opencode_config.py --versionThe script provides an interactive menu with the following commands:
| Command | Description |
|---|---|
1-9 |
Select a configuration file by number |
d# |
View detailed file contents (e.g., d1, d2, d3) |
q |
Quit without making any changes |
Enter |
Apply the selected configuration |
Space |
Navigate through pages in detail view |
b |
Go to previous page in detail view |
Arrow Keys |
Navigate through pages in detail view |
- Configuration Discovery: The script scans
~/.config/opencode/for all JSON files matchingoh-my-opencode*.json - File Filtering: It excludes
oh-my-opencode.json(current active config) and.BAKfiles from the selection list - Safe Switching: When you select and apply a configuration:
- Current
oh-my-opencode.jsonis backed up tooh-my-opencode.json.BAK(overwrites existing backup) - Selected file is copied (not moved) to
oh-my-opencode.json - The new configuration becomes immediately active
- Current
~/.config/opencode/
├── oh-my-opencode.json # Current active configuration (DO NOT EDIT DIRECTLY)
├── oh-my-opencode.json.BAK # Backup of previous configuration
├── oh-my-opencode-default.json # Default configuration preset
├── oh-my-opencode_OpenAI-GLM4.7.json # OpenAI + GLM4.7 configuration
├── oh-my-opencode_OpenAI-Only.json # OpenAI-only configuration
├── oh-my-opencode_Custom.json # Your custom configuration
└── ... (other configuration files)
- Copy your current configuration to a new file:
cp ~/.config/opencode/oh-my-opencode.json ~/.config/opencode/oh-my-opencode-myconfig.json- Edit the new file with your desired settings:
nano ~/.config/opencode/oh-my-opencode-myconfig.json
# or use your preferred editor
vim ~/.config/opencode/oh-my-opencode-myconfig.json- Run the switcher to select your new configuration from the menu
- Copy a template configuration:
cp ~/.config/opencode/oh-my-opencode-default.json ~/.config/opencode/oh-my-opencode-mytemplate.json- Modify the template to create your custom configuration
If you need to restore the previous configuration:
# Check available backups
ls -la ~/.config/opencode/oh-my-opencode*.BAK
# Restore from backup
cp ~/.config/opencode/oh-my-opencode.json.BAK ~/.config/opencode/oh-my-opencode.json-
"Configuration directory not found"
- Ensure oh-my-opencode is installed
- Check the configuration directory exists:
ls -la ~/.config/opencode/
-
"No configuration files found"
- Verify you have configuration files in
~/.config/opencode/ - Files should match pattern:
oh-my-opencode*.json(excluding current and backup)
- Verify you have configuration files in
-
"Permission denied"
- Ensure the script is executable:
chmod +x switch_oh-my-opencode_config.py - Check write permissions on
~/.config/opencode/
- Ensure the script is executable:
-
Script not found in PATH
- Verify
~/.local/binis in your PATH - Try running with full path:
python3 ~/.local/bin/switch_oh-my-opencode_config.py
- Verify
For troubleshooting, you can add debug information by examining the script's environment:
# Check Python version
python3 --version
# Check if required modules are available
python3 -c "import json, shutil, sys; print('All modules available')"The script can be integrated into shell scripts for automation:
#!/bin/bash
# Example: Apply a specific configuration programmatically
CONFIG_FILE="oh-my-opencode-custom.json"
CONFIG_PATH="$HOME/.config/opencode/$CONFIG_FILE"
if [ -f "$CONFIG_PATH" ]; then
cp "$CONFIG_PATH" "$HOME/.config/opencode/oh-my-opencode.json"
echo "Configuration applied: $CONFIG_FILE"
else
echo "Configuration file not found: $CONFIG_PATH"
exit 1
fiCreate a management script for your configurations:
#!/bin/bash
# config-manager.sh
case "$1" in
"list")
echo "Available configurations:"
ls -la ~/.config/opencode/oh-my-opencode*.json | grep -v "\.BAK$"
;;
"backup")
cp ~/.config/opencode/oh-my-opencode.json ~/.config/opencode/oh-my-opencode-backup-$(date +%Y%m%d-%H%M%S).json
echo "Backup created"
;;
"clean")
find ~/.config/opencode/ -name "oh-my-opencode*.BAK" -delete
echo "Cleaned up backup files"
;;
*)
echo "Usage: $0 {list|backup|clean}"
exit 1
;;
esacThis project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please feel free to submit:
- Bug Reports: Report any issues with the script
- Feature Requests: Suggest new functionality
- Pull Requests: Submit code improvements
- Documentation: Help improve the documentation
To contribute to this project:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes
- Test thoroughly
- Commit your changes:
git commit -m 'feat: Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
-
v1.0.1 (Current):
- Added version variable and --version flag
- Improved version management
- Enhanced documentation
-
v1.0.0:
- Initial release
- Basic configuration switching functionality
- Interactive menu system
- Backup management
If you encounter any issues or have questions:
- Check the troubleshooting section above
- Review the oh-my-opencode documentation
- Open an issue in the project repository
This script is designed to work with the oh-my-opencode configuration management system. For more information about oh-my-opencode, please refer to the official documentation.