diff options
| author | Jan Tuomi <jan@jantuomi.fi> | 2026-01-01 17:36:39 +0200 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2026-01-02 16:21:05 +0200 |
| commit | c1856d1f3edbc4b32be5860233dede88db16a7bb (patch) | |
| tree | b3a5e2f600c0079bd04d7ab2bb459b4664ba66a1 /content/posts/macos-opening-git-commit-prompt-in-active-gui-editor.md | |
| parent | 6d7e34af89ef1038d213ff8ea325bb84d4a00d4a (diff) | |
Start migrating content
Diffstat (limited to 'content/posts/macos-opening-git-commit-prompt-in-active-gui-editor.md')
| -rw-r--r-- | content/posts/macos-opening-git-commit-prompt-in-active-gui-editor.md | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/content/posts/macos-opening-git-commit-prompt-in-active-gui-editor.md b/content/posts/macos-opening-git-commit-prompt-in-active-gui-editor.md new file mode 100644 index 0000000..2d71dd4 --- /dev/null +++ b/content/posts/macos-opening-git-commit-prompt-in-active-gui-editor.md @@ -0,0 +1,38 @@ +--- +title: "MacOS: Opening Git commit prompt in active GUI editor" +date: 2025-01-29 +extra: + kind: note +--- + +This is a quick, neat thing I happened to find on accident. As a result of the application bundle system that MacOS uses ubiquitously, you can figure out the currently open application with the `__CFBundleIdentifier` environment variable. + +```bash +$ echo $__CFBundleIdentifier +dev.zed.Zed +``` + +This bundle identifier uniquely identifies an installed application. + +Many editors or IDEs (Zed in my example) allow you to open an integrated terminal. It can be convenient to use that same graphical editor as the `$EDITOR` for commands like `git commit` or `git rebase -i` instead of using `vim` or `nano` or some other TUI editor inside the integrated terminal. + +Use it like this: + +```bash +# $HOME/.zshrc + +if [ "$__CFBundleIdentifier" = "dev.zed.Zed" ]; then + export EDITOR="zed -w" +elif [ "$__CFBundleIdentifier" = "com.jetbrains.intellij" ]; then + export EDITOR="idea --wait" +fi +``` + +Alternatively, if your editor supports setting custom environment variables for the integrated terminal, you can do that and avoid having the if-else in your shell rc. I prefer to have all my environment shenanigans in one place so I chose not to follow that route. + +Note that your editor must support a flag like `-w` or `--wait` that blocks the editor command from exiting before you close the file. If you don't do that, you will see stuff like: + +```bash +$ git commit +Aborting commit due to empty commit message +``` |
