Skip to content

Commit 4825473

Browse files
committed
chore: add default editor handling
1 parent 642f9b4 commit 4825473

File tree

1 file changed

+25
-36
lines changed

1 file changed

+25
-36
lines changed

utils.go

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -126,55 +126,44 @@ func moveFile(src, dest string) {
126126
}
127127

128128
func openFile(filename string) error {
129-
if err := verifyCodeCommand(); err != nil {
130-
return err
131-
}
132-
133129
var cmd *exec.Cmd
134130

135131
if runtime.GOOS == "windows" {
136132
// On Windows, use "code.cmd"
137133
cmd = exec.Command("code.cmd", filename)
138-
} else {
139-
cmd = exec.Command("code", filename)
140-
}
141-
142-
err := cmd.Start()
143-
if err != nil {
144-
return err
145-
}
146-
147-
return nil
148-
}
134+
cmd.Stdin = os.Stdin
135+
cmd.Stdout = os.Stdout
136+
cmd.Stderr = os.Stderr
137+
err := cmd.Run()
149138

150-
func verifyCodeCommand() error {
151-
_, err := exec.LookPath("code")
152-
if err != nil {
153-
fmt.Println("code command not found. Attempting to install...")
154-
err = installCodeCommand()
155139
if err != nil {
156-
return fmt.Errorf("failed to verify and install code command: %s", err)
140+
cmd = exec.Command("notepad", filename)
141+
cmd.Stdin = os.Stdin
142+
cmd.Stdout = os.Stdout
143+
cmd.Stderr = os.Stderr
144+
runErr := cmd.Run()
145+
146+
if runErr != nil {
147+
fmt.Println(runErr)
148+
}
157149
}
158-
fmt.Println("code command installed successfully.")
159-
}
160-
return nil
161-
}
162150

163-
func installCodeCommand() error {
164-
var command string
165-
var args []string
166-
if runtime.GOOS == "windows" {
167-
command = "powershell"
168-
args = []string{"-Command", "& { Invoke-WebRequest -Uri 'https://go.microsoft.com/fwlink/?LinkID=760868' -OutFile 'vscode.zip' }"}
169151
} else {
170-
command = "bash"
171-
args = []string{"-c", "curl -o vscode.zip -L https://go.microsoft.com/fwlink/?LinkID=760868 && unzip vscode.zip && sudo mv 'VSCode.app' '/usr/local/bin/code'"}
152+
// implement such that the default editor is opened
153+
cmd = exec.Command("editor", filename)
154+
cmd.Stdin = os.Stdin
155+
cmd.Stdout = os.Stdout
156+
cmd.Stderr = os.Stderr
157+
runErr := cmd.Run()
158+
159+
if runErr != nil {
160+
fmt.Println(runErr)
161+
}
172162
}
173163

174-
cmd := exec.Command(command, args...)
175-
err := cmd.Run()
164+
err := cmd.Start()
176165
if err != nil {
177-
return fmt.Errorf("failed to install code command: %s", err)
166+
return err
178167
}
179168

180169
return nil

0 commit comments

Comments
 (0)