Created
April 11, 2025 19:04
-
-
Save coreyward/6131e6ec5a35ef226abc5463ea63d334 to your computer and use it in GitHub Desktop.
Dynamically configure your git editor based on the IDE you invoke it from
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# Instructions: | |
# 1. Put this file in your user folder (~/git-editor) | |
# 2. Enable execution by running `chmod +x ~/git-editor` | |
# 3. Run `git config --global core.editor "~/git-editor" | |
# 4. Now when you run a git command that launches your interactive editor, it'll use the current IDE | |
# Function to get the process name by PID | |
get_process_name() { | |
ps -p $1 -o comm= 2>/dev/null | |
} | |
# Start with the parent process ID | |
current_pid=$PPID | |
# Traverse up the process tree to find the terminal application | |
while [[ $current_pid -ne 1 ]]; do | |
process_name=$(get_process_name $current_pid) | |
case "$process_name" in | |
*"Windsurf Helper"*) | |
exec windsurf -w "$@" | |
;; | |
*"Code Helper"*) | |
exec code --wait "$@" | |
;; | |
*"Cursor Helper"*) | |
exec cursor --wait "$@" | |
;; | |
esac | |
# Get the parent PID of the current process | |
current_pid=$(ps -p $current_pid -o ppid= | tr -d ' ') | |
done | |
# Fallback to default editor | |
exec nano "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment