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:
1 parent
f1a1097db5
commit
551f9d3418
4 files changed
+19
-7
No files matched your search
@@ -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).
|
- The `cmd-transpose` command now advances the cursor correctly after swapping characters (#2413).
|
||||||
- Symbolic links are no longer followed when changing directories (#2423).
|
- 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).
|
- 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)
|
## [r41](https://github.com/gokcehan/lf/releases/tag/r41)
|
||||||
|
|
||||||
|
|||||||
@@ -259,7 +259,7 @@ func (sm styleMap) get(f *file) tcell.Style {
|
|||||||
key = "su"
|
key = "su"
|
||||||
case f.Mode()&os.ModeSetgid != 0:
|
case f.Mode()&os.ModeSetgid != 0:
|
||||||
key = "sg"
|
key = "sg"
|
||||||
case f.Mode()&0o111 != 0:
|
case isExecutable(f.FileInfo):
|
||||||
key = "ex"
|
key = "ex"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ func (im iconMap) get(f *file) iconDef {
|
|||||||
key = "su"
|
key = "su"
|
||||||
case f.Mode()&os.ModeSetgid != 0:
|
case f.Mode()&os.ModeSetgid != 0:
|
||||||
key = "sg"
|
key = "sg"
|
||||||
case f.Mode()&0o111 != 0:
|
case isExecutable(f.FileInfo):
|
||||||
key = "ex"
|
key = "ex"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+16
-5
@@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"cmp"
|
"cmp"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/user"
|
"os/user"
|
||||||
@@ -21,7 +20,7 @@ var (
|
|||||||
envShell = os.Getenv("SHELL")
|
envShell = os.Getenv("SHELL")
|
||||||
)
|
)
|
||||||
|
|
||||||
var envPathExt = os.Getenv("PATHEXT")
|
var envPathExts []string
|
||||||
|
|
||||||
var (
|
var (
|
||||||
gDefaultShell = "cmd"
|
gDefaultShell = "cmd"
|
||||||
@@ -115,6 +114,14 @@ func init() {
|
|||||||
gDefaultSocketPath = filepath.Join(runtime, fmt.Sprintf("lf.%s.sock", gUser.Username))
|
gDefaultSocketPath = filepath.Join(runtime, fmt.Sprintf("lf.%s.sock", gUser.Username))
|
||||||
syscall.Close(socket)
|
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 {
|
func detachedCommand(name string, arg ...string) *exec.Cmd {
|
||||||
@@ -174,9 +181,13 @@ func setDefaults() {
|
|||||||
func setUserUmask() {}
|
func setUserUmask() {}
|
||||||
|
|
||||||
func isExecutable(f os.FileInfo) bool {
|
func isExecutable(f os.FileInfo) bool {
|
||||||
for e := range strings.SplitSeq(envPathExt, string(filepath.ListSeparator)) {
|
ext := filepath.Ext(f.Name())
|
||||||
if strings.HasSuffix(strings.ToLower(f.Name()), strings.ToLower(e)) {
|
if ext == "" {
|
||||||
log.Print(f.Name(), e)
|
return false
|
||||||
|
}
|
||||||
|
ext = strings.ToLower(ext)
|
||||||
|
for _, x := range envPathExts {
|
||||||
|
if ext == x {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user