1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-05-17 22:32:58 +02:00
lazygit/pkg/config/config_linux.go
Baptiste Ottino 4cfeb18632 Fix opening files with explorer in WSL
The OS command to open file in explorer in WSL doesn't currently work as
expected; it always opens the file explorer at the default opening
location. This is because the {{filename}} variable returns the path in
WSL format, and not in the format expected by Windows.

We use wslpath, a utility shipped with WSL, to make the path conversion.
2024-12-04 09:43:30 +01:00

34 lines
834 B
Go

package config
import (
"os"
"strings"
)
func isWSL() bool {
data, err := os.ReadFile("/proc/sys/kernel/osrelease")
return err == nil && strings.Contains(string(data), "microsoft")
}
func isContainer() bool {
data, err := os.ReadFile("/proc/1/cgroup")
return err == nil && (strings.Contains(string(data), "docker") ||
strings.Contains(string(data), "/lxc/") ||
os.Getenv("CONTAINER") != "")
}
// GetPlatformDefaultConfig gets the defaults for the platform
func GetPlatformDefaultConfig() OSConfig {
if isWSL() && !isContainer() {
return OSConfig{
Open: `powershell.exe start explorer.exe "$(wslpath -w {{filename}})" >/dev/null`,
OpenLink: `powershell.exe start {{link}} >/dev/null`,
}
}
return OSConfig{
Open: `xdg-open {{filename}} >/dev/null`,
OpenLink: `xdg-open {{link}} >/dev/null`,
}
}