Skip to content

Commit 96a1052

Browse files
authored
fix: editor var expansion (#603)
This handles cases where the git editor is set to `$EDITOR`. The steps for reproducing are as follows. 1. Set the EDITOR env var 2. Update your .gitconfig to include editor=$EDITOR 3. Run `av pr --edit` According to `man 1 git-var`, `GIT_EDITOR` is "meant to be interpreted by the shell when it is used". Hence, this variable needs to be interpreted. Credit to @tgandrews for spotting the issue
1 parent ea50a0b commit 96a1052

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

internal/editor/editor.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,12 @@ func Launch(ctx context.Context, repo *git.Repo, config Config) (string, error)
6969
}
7070

7171
// Launch the editor as a subprocess.
72-
// We interpret the command with shell syntax to allow users to specify
73-
// both flags and use editor executables with spaces.
72+
// We execute the command through a shell to properly handle environment
73+
// variable expansion and shell quoting rules, matching Git's behavior.
7474
// e.g., EDITOR="'/path/with spaces/editor'" or
75-
// EDITOR="code --wait" work.
76-
args, err := shellquote.Split(config.Command)
77-
if err != nil {
78-
return "", errors.Wrapf(err, "invalid editor command: %q", config.Command)
79-
}
80-
args = append(args, tmp.Name())
81-
cmd := exec.CommandContext(ctx, args[0], args[1:]...)
75+
// EDITOR="code --wait" or GIT_EDITOR="$EDITOR" work correctly.
76+
shellCmd := config.Command + " " + shellquote.Join(tmp.Name())
77+
cmd := exec.CommandContext(ctx, "sh", "-c", shellCmd)
8278
cmd.Stdin = os.Stdin
8379
cmd.Stdout = os.Stdout
8480
stderr := bytes.NewBuffer(nil)

0 commit comments

Comments
 (0)