diff --git a/CHANGELOG.md b/CHANGELOG.md index e13c700e..fe69256b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), - The `cmd-transpose` command now advances the cursor correctly after swapping characters (#2413). - Symbolic links are no longer followed when changing directories (#2423). - Using the `select` command with a blank string as the argument now properly raises an error instead of changing to the parent directory (#2429). +- Executable files on Windows are now correctly recognized for icon and color lookup based on `PATHEXT` (#2448). ## [r41](https://github.com/gokcehan/lf/releases/tag/r41) diff --git a/colors.go b/colors.go index d4463145..cb4cf3bc 100644 --- a/colors.go +++ b/colors.go @@ -259,7 +259,7 @@ func (sm styleMap) get(f *file) tcell.Style { key = "su" case f.Mode()&os.ModeSetgid != 0: key = "sg" - case f.Mode()&0o111 != 0: + case isExecutable(f.FileInfo): key = "ex" } diff --git a/icons.go b/icons.go index 525341c9..761bd5c4 100644 --- a/icons.go +++ b/icons.go @@ -165,7 +165,7 @@ func (im iconMap) get(f *file) iconDef { key = "su" case f.Mode()&os.ModeSetgid != 0: key = "sg" - case f.Mode()&0o111 != 0: + case isExecutable(f.FileInfo): key = "ex" } diff --git a/os_windows.go b/os_windows.go index f0f77a9c..7ac223e0 100644 --- a/os_windows.go +++ b/os_windows.go @@ -3,7 +3,6 @@ package main import ( "cmp" "fmt" - "log" "os" "os/exec" "os/user" @@ -21,7 +20,7 @@ var ( envShell = os.Getenv("SHELL") ) -var envPathExt = os.Getenv("PATHEXT") +var envPathExts []string var ( gDefaultShell = "cmd" @@ -115,6 +114,14 @@ func init() { gDefaultSocketPath = filepath.Join(runtime, fmt.Sprintf("lf.%s.sock", gUser.Username)) syscall.Close(socket) } + + s := cmp.Or(os.Getenv("PATHEXT"), ".COM;.EXE;.BAT;.CMD") + for ext := range strings.SplitSeq(s, ";") { + if ext == "" { + continue + } + envPathExts = append(envPathExts, strings.ToLower(ext)) + } } func detachedCommand(name string, arg ...string) *exec.Cmd { @@ -174,9 +181,13 @@ func setDefaults() { func setUserUmask() {} func isExecutable(f os.FileInfo) bool { - for e := range strings.SplitSeq(envPathExt, string(filepath.ListSeparator)) { - if strings.HasSuffix(strings.ToLower(f.Name()), strings.ToLower(e)) { - log.Print(f.Name(), e) + ext := filepath.Ext(f.Name()) + if ext == "" { + return false + } + ext = strings.ToLower(ext) + for _, x := range envPathExts { + if ext == x { return true } }