A dynamic Bash
script that enhances your Git workflow by allowing you to seamlessly select and manage your preferred code editors. Whether you're working on commits, merges, rebases, or other Git operations that require an editor.
A documentation website is being developed at the moment : )
- Features
- Prerequisites
- Installation
- Configuration
- Usage
- Supported Editors
- Customization
- Troubleshooting
- Contributing
- License
- Multiple Editor Support: Choose from a variety of code editors like VS Code, Zed, Cursor, and more.
- Dynamic Editor Selection: Automatically detects running editors and allows you to select which one to use.
- Custom Aliases: Define short aliases for your favorite editors for quicker access.
- Seamless Integration: Wraps around Git commands to provide an enhanced and customizable Git experience.
- Easy Configuration: Simple setup process with interactive prompts to tailor the tool to your needs.
- Operating System:
- MacOS (
osascript
for detecting running applications). - Linux (
pgrep
for process detection).
- MacOS (
- Shell: Zsh
- Git: Installed and configured on your system.
- Supported Editors: Ensure your preferred editors are installed and accessible via command line (e.g.,
code
for VS Code,cursor
for Cursor).
Note: Don't forget to install the command-line
PATH
for each IDE to make the IDE accessible from the command line. Here’s how you can do it for some common editors: Visual Studio Code, Web Storm, Zed
-
Clone the Repository
git clone https://github.com/GrungeElFz/Git_Editor.Selector.git
-
Navigate to the Directory
cd Git_Editor.Selector
-
Add the Script to Your Zsh Configuration
You can add the script directly to your
.zshrc
or source it as a separate file.-
Option 1: Directly in
.zshrc
Open your .zshrc file:
nano ~/.zshrc
Paste the contents of the Git_Editor.Selector script into your
.zshrc
file.
-
Option 2: Source as a Separate File
Save the
Git_Editor.Selector
script to a file (e.g.,~/.zsh/git_editor_selector.zsh
)mkdir -p ~/.zsh nano ~/.zsh/git_editor_selector.zsh
Paste the script into this file and save.
Then, add the following line to your .zshrc to source the script:
source ~/.zsh/git_editor_selector.zsh
-
-
Reload Your
Zsh
Configurationsource ~/.zshrc
After installation, perform the initial setup to configure your preferred editors and aliases.
-
Run Initialization Command
g setup
-
Follow the Interactive Prompts
-
Select Editors: You'll be presented with a list of available editors. Choose the ones you want to configure.
-
Aliases Configuration: Decide whether to use default aliases or set custom ones for each editor.
-
Default Editor Selection: Choose which editor should be the default when you execute
code
commands.
-
Restart Your Shell
To apply the changes, restart the shell andterminal:
source ~/.zshrc
You can edit your editor aliases at any time using the g config
command.
g config
This will open the aliases.conf
file in your selected editor, allowing you to modify aliases as needed. After editing, reload your shell to apply the changes.
Git Editor Selector provides a wrapper function g
that replaces the standard git command, offering enhanced capabilities.
All standard Git commands are supported. Use g
in place of git
:
g add .
g commit -m "Message"
g push origin main
-
Initialization
g setup
Sets up the Git Editor Selector by configuring editors and aliases.
-
Configuration
g config
Opens the
aliases.conf
file for editing your editor aliases. -
Commit
g commit Checking for running editors 🏃️... Multiple editors are running. Please choose the editor for git commit: (1) VS Code (2) Zed (3) Cursor 👉 2 Using Zed as the git editor. hint: Waiting for your editor to close the file...
When multiple editors are active,
g commit
prompts you to select one. It then opens the commit message in the chosen editor and waits for you to close the file. -
Rebase
g rebase -i HEAD~5 Checking for running editors 🏃️... Multiple editors are running. Please choose the editor for git commit: (1) VS Code (2) Zed (3) Cursor 👉 3 Using Cursor as the git editor. hint: Waiting for your editor to close the file...
Similar to commit,
g rebase -i HEAD~<number>
prompts you to select an editor if multiple are running and initiates an interactive rebase in the chosen editor.
Note: If there's only one editor running, the script will automatically route to the running one.
By default, Git Editor Selector supports the following editors:
-
- Name: Cursor
- Process Pattern: Cursor
- Command:
cursor
- Alias:
cur
-
- Name: VS Code
- Process Pattern: Visual Studio Code
- Command:
code
- Alias:
vsc
-
- Name: Web Storm
- Process Pattern: Web Storm
- Command:
webstorm
- Alias:
web
-
- Name: Zed
- Process Pattern: Zed
- Command:
zed
- Alias:
zed
To add more editors:
-
Edit the Git_Editor.Selector Script
Locate the
EDITORS
array in the script and add your editor in the following format:"Editor Name:Process Pattern:Editor Command"
Example:
EDITORS=( "Cursor:Cursor:cursor" "VS Code:Visual Studio Code:code" "Web Storm:WebStorm:webstorm" "Zed:Zed:zed" )
-
Update Default Aliases
If you want to set a default alias for the new editor, add it to the
default_aliases
associative array:default_aliases=( ["Cursor"]="cur" ["VS Code"]="vsc" ["Web Storm"]="web" ["Zed"]="zed" )
-
Run Configuration Again
After making changes, run
g init
to reconfigure aliases.
-
Default Editor
Set your preferred default editor by modifying the
DEFAULT_EDITOR
variable in the script:DEFAULT_EDITOR="code" # Change 'code' to your preferred editor command
-
Aliases Configuration
Customize your editor aliases by editing the
~/.config/git_editor_selector/aliases.conf
file.[aliases] cur = Cursor vsc = VS Code web = Web Storm zed = Zed code = VS Code # Default 'code' alias
-
Aliases Configuration File Not Found
If you encounter an error about the aliases configuration file not being found, run:
g setup
-
Editor Not Opening
Ensure that the editor's command is correctly specified and that the editor is installed. You can test the command directly in the terminal:
code .
-
Environment Variable
$EDITOR
Not SetIf no editors are running and the
$EDITOR
environment variable is not set, Git Editor Selector defaults toDEFAULT_EDITOR
.To set
$EDITOR
, add the following to your.zshrc
:export EDITOR="code" # Replace 'code' with your preferred editor
Then, restart the shell and terminal.
source ~/.zshrc
-
Need more help?
Run
g
,g help
,g -h
, org --help
:g help
Contributions are extreamly welcome! If you have suggestions, improvements, or bug fixes, feel free to open an issue or submit a pull request.
-
Fork the Repository
-
Create a Feature Branch
git checkout -b feature/YourFeature
-
Commit Your Changes
git commit -m "Add your message here"
-
Push to the Branch
git push origin feature/YourFeature
-
Open a Pull Request
Made with contrib.rocks.