fix(windows): use isExecutable for icon and color lookup (#2448)

* fix(windows): use `isExecutable` for icon and color lookup

* perf(windows): avoid re-parsing `PATHEXT` in `isExecutable`

* docs: update `CHANGELOG.md`
This commit is contained in:
CatsDeservePets authored and GitHub committed 2026-03-21 04:09:20 +01:00
1 parent f1a1097db5
commit 551f9d3418
4 files changed
+19 -7

No files matched your search

+1
View File
@@ -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)
+1 -1
View File
@@ -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"
}
+1 -1
View File
@@ -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"
}
+16 -5
View File
@@ -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
}
}