mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-28 11:11:47 +02:00
Use KITTY_PID to find kitty exe when possible
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
|
"github.com/shirou/gopsutil/v3/process"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -66,8 +67,16 @@ func Abspath(path string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var KittyExe = sync.OnceValue(func() string {
|
var KittyExe = sync.OnceValue(func() string {
|
||||||
exe, err := os.Executable()
|
if kitty_pid := os.Getenv("KITTY_PID"); kitty_pid != "" {
|
||||||
if err == nil {
|
if kp, err := strconv.Atoi(kitty_pid); err == nil {
|
||||||
|
if p, err := process.NewProcess(int32(kp)); err == nil {
|
||||||
|
if exe, err := p.Exe(); err == nil && filepath.IsAbs(exe) && filepath.Base(exe) == "kitty" {
|
||||||
|
return exe
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if exe, err := os.Executable(); err == nil {
|
||||||
ans := filepath.Join(filepath.Dir(exe), "kitty")
|
ans := filepath.Join(filepath.Dir(exe), "kitty")
|
||||||
if s, err := os.Stat(ans); err == nil && !s.IsDir() {
|
if s, err := os.Stat(ans); err == nil && !s.IsDir() {
|
||||||
return ans
|
return ans
|
||||||
|
|||||||
Reference in New Issue
Block a user