diff --git a/cmd/restray/restic.go b/cmd/restray/restic.go index bd484e2..3e87b4c 100644 --- a/cmd/restray/restic.go +++ b/cmd/restray/restic.go @@ -69,6 +69,16 @@ func findResticFromShell() string { if runtime.GOOS == "windows" { return "" } + if sudoUser := os.Getenv("SUDO_USER"); sudoUser != "" { + out, err := exec.Command("sudo", "-n", "-u", sudoUser, "-i", "which", "restic").Output() + if err == nil { + if p := strings.TrimSpace(string(out)); p != "" { + if _, err := os.Stat(p); err == nil { + return p + } + } + } + } shell := os.Getenv("SHELL") if shell == "" { if runtime.GOOS == "darwin" {