Skip to content

Commit c5e817b

Browse files
authored
Merge pull request #1 from vicradon/main
chore: add default editor handling
2 parents 642f9b4 + 2e37aee commit c5e817b

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,56 +126,45 @@ 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+
handleCmdOs(cmd)
135+
err := cmd.Run()
149136

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()
155137
if err != nil {
156-
return fmt.Errorf("failed to verify and install code command: %s", err)
138+
cmd = exec.Command("notepad", filename)
139+
handleCmdOs(cmd)
140+
runErr := cmd.Run()
141+
142+
if runErr != nil {
143+
fmt.Println(runErr)
144+
}
157145
}
158-
fmt.Println("code command installed successfully.")
159-
}
160-
return nil
161-
}
162146

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' }"}
169147
} 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'"}
148+
// implement such that the default editor is opened
149+
cmd = exec.Command("editor", filename)
150+
handleCmdOs(cmd)
151+
runErr := cmd.Run()
152+
153+
if runErr != nil {
154+
fmt.Println(runErr)
155+
}
172156
}
173157

174-
cmd := exec.Command(command, args...)
175-
err := cmd.Run()
158+
err := cmd.Start()
176159
if err != nil {
177-
return fmt.Errorf("failed to install code command: %s", err)
160+
return err
178161
}
179162

180163
return nil
181164
}
165+
166+
func handleCmdOs(cmd *exec.Cmd) {
167+
cmd.Stdin = os.Stdin
168+
cmd.Stdout = os.Stdout
169+
cmd.Stderr = os.Stderr
170+
}

0 commit comments

Comments
 (0)