-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopen_cmd.go
More file actions
35 lines (27 loc) · 856 Bytes
/
open_cmd.go
File metadata and controls
35 lines (27 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"fmt"
"os"
"os/exec"
"syscall"
)
func open_cmd() {
path_to_open := current_active_explorer_window()
if path_to_open == "" || path_to_open == "NOT_FOUND" {
path_to_open = "C:\\"
}
fmt.Printf("Final Path: %s\n", path_to_open)
cmd := exec.Command("cmd", "/C", "start", "cmd.exe", "/K", "cd /d "+path_to_open)
cmd.Env = os.Environ() // Ensure environment variables are passed along
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
if err := cmd.Run(); err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
fmt.Printf("VS Code exited with error: %v\n", exitErr)
} else {
fmt.Printf("Error running VS Code: %s\n", err)
}
fmt.Println("Make sure VS Code is installed and 'code' command is in your PATH.")
return
}
fmt.Printf("Successfully opened VS Code with path: %s\n", path_to_open)
}