Revert "dirtyfiles: files that don't require cleaning before previewing them (#729)"

This reverts commit 673dad9f07.
This commit is contained in:
Gokcehan 2022-01-22 16:57:28 +03:00
parent 85c73978fe
commit 930364ce78
8 changed files with 4 additions and 73 deletions

1
app.go
View File

@ -481,7 +481,6 @@ func (app *app) runShell(s string, args []string, prefix string) {
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
app.nav.previewChan <- "" app.nav.previewChan <- ""
app.nav.previewChan <- "!"
if err := app.ui.suspend(); err != nil { if err := app.ui.suspend(); err != nil {
log.Printf("suspend: %s", err) log.Printf("suspend: %s", err)
} }

View File

@ -87,7 +87,6 @@ var (
"dironly", "dironly",
"nodironly", "nodironly",
"dironly!", "dironly!",
"dirtyfiles",
"drawbox", "drawbox",
"nodrawbox", "nodrawbox",
"drawbox!", "drawbox!",

9
doc.go
View File

@ -105,7 +105,6 @@ The following options can be used to customize the behavior of lf:
dircounts bool (default off) dircounts bool (default off)
dirfirst bool (default on) dirfirst bool (default on)
dironly bool (default off) dironly bool (default off)
dirtyfiles []string (default '!*')
drawbox bool (default off) drawbox bool (default off)
errorfmt string (default "\033[7;31;47m%s\033[0m") errorfmt string (default "\033[7;31;47m%s\033[0m")
filesep string (default "\n") filesep string (default "\n")
@ -535,14 +534,6 @@ Show directories first above regular files.
Show only directories. Show only directories.
dirtyfiles []string (default '!*')
List of dirty file glob patterns.
These files won't have 'cleaner' executed before previewing them.
Patterns can be given as relative or absolute paths.
Globbing supports the usual special characters, '*' to match any sequence, '?' to match any character, and '[...]' or '[^...] to match character sets or ranges.
In addition, if a pattern starts with '!', then its matches are excluded from dirty files.
drawbox bool (default off) drawbox bool (default off)
Draw boxes around panes with box drawing characters. Draw boxes around panes with box drawing characters.

View File

@ -109,7 +109,6 @@ The following options can be used to customize the behavior of lf:
dircounts bool (default off) dircounts bool (default off)
dirfirst bool (default on) dirfirst bool (default on)
dironly bool (default off) dironly bool (default off)
dirtyfiles []string (default '!*')
drawbox bool (default off) drawbox bool (default off)
errorfmt string (default "\033[7;31;47m%s\033[0m") errorfmt string (default "\033[7;31;47m%s\033[0m")
filesep string (default "\n") filesep string (default "\n")
@ -566,15 +565,6 @@ Show directories first above regular files.
Show only directories. Show only directories.
dirtyfiles []string (default '!*')
List of dirty file glob patterns. These files won't have 'cleaner' executed
before previewing them. Patterns can be given as relative or absolute paths.
Globbing supports the usual special characters, '*' to match any sequence,
'?' to match any character, and '[...]' or '[^...] to match character sets
or ranges. In addition, if a pattern starts with '!', then its matches are
excluded from dirty files.
drawbox bool (default off) drawbox bool (default off)
Draw boxes around panes with box drawing characters. Draw boxes around panes with box drawing characters.

18
eval.go
View File

@ -68,24 +68,6 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.sortType.option ^= dirfirstSort gOpts.sortType.option ^= dirfirstSort
app.nav.sort() app.nav.sort()
app.ui.sort() app.ui.sort()
case "dirtyfiles":
toks := strings.Split(e.val, ":")
for _, s := range toks {
if s == "" {
app.ui.echoerr("dirtyfiles: glob should be non-empty")
return
}
_, err := filepath.Match(s, "a")
if err != nil {
app.ui.echoerrf("dirtyfiles: %s", err)
return
}
}
gOpts.dirtyfiles = toks
app.nav.sort()
app.nav.position()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "drawbox": case "drawbox":
gOpts.drawbox = true gOpts.drawbox = true
app.ui.renew() app.ui.renew()

7
lf.1
View File

@ -124,7 +124,6 @@ The following options can be used to customize the behavior of lf:
dircounts bool (default off) dircounts bool (default off)
dirfirst bool (default on) dirfirst bool (default on)
dironly bool (default off) dironly bool (default off)
dirtyfiles []string (default '!*')
drawbox bool (default off) drawbox bool (default off)
errorfmt string (default "\e033[7;31;47m%s\e033[0m") errorfmt string (default "\e033[7;31;47m%s\e033[0m")
filesep string (default "\en") filesep string (default "\en")
@ -663,12 +662,6 @@ Show directories first above regular files.
.PP .PP
Show only directories. Show only directories.
.PP .PP
.EX
dirtyfiles []string (default '!*')
.EE
.PP
List of dirty file glob patterns. These files won't have 'cleaner' executed before previewing them. Patterns can be given as relative or absolute paths. Globbing supports the usual special characters, '*' to match any sequence, '?' to match any character, and '[...]' or '[^...] to match character sets or ranges. In addition, if a pattern starts with '!', then its matches are excluded from dirty files.
.PP
.EX .EX
drawbox bool (default off) drawbox bool (default off)
.EE .EE

29
nav.go
View File

@ -115,7 +115,6 @@ type dir struct {
sortType sortType // sort method and options from last sort sortType sortType // sort method and options from last sort
dironly bool // dironly value from last sort dironly bool // dironly value from last sort
hiddenfiles []string // hiddenfiles value from last sort hiddenfiles []string // hiddenfiles value from last sort
dirtyfiles []string // files that don't require cleaning
filter []string // last filter for this directory filter []string // last filter for this directory
ignorecase bool // ignorecase value from last sort ignorecase bool // ignorecase value from last sort
ignoredia bool // ignoredia value from last sort ignoredia bool // ignoredia value from last sort
@ -155,7 +154,6 @@ func (dir *dir) sort() {
dir.sortType = gOpts.sortType dir.sortType = gOpts.sortType
dir.dironly = gOpts.dironly dir.dironly = gOpts.dironly
dir.hiddenfiles = gOpts.hiddenfiles dir.hiddenfiles = gOpts.hiddenfiles
dir.dirtyfiles = gOpts.dirtyfiles
dir.ignorecase = gOpts.ignorecase dir.ignorecase = gOpts.ignorecase
dir.ignoredia = gOpts.ignoredia dir.ignoredia = gOpts.ignoredia
@ -363,7 +361,6 @@ func (nav *nav) loadDirInternal(path string) *dir {
path: path, path: path,
sortType: gOpts.sortType, sortType: gOpts.sortType,
hiddenfiles: gOpts.hiddenfiles, hiddenfiles: gOpts.hiddenfiles,
dirtyfiles: gOpts.dirtyfiles,
ignorecase: gOpts.ignorecase, ignorecase: gOpts.ignorecase,
ignoredia: gOpts.ignoredia, ignoredia: gOpts.ignoredia,
} }
@ -525,26 +522,21 @@ func (nav *nav) previewLoop(ui *ui) {
var prev string var prev string
for path := range nav.previewChan { for path := range nav.previewChan {
clear := len(path) == 0 clear := len(path) == 0
forceClear := path == "!"
loop: loop:
for { for {
select { select {
case path = <-nav.previewChan: case path = <-nav.previewChan:
clear = clear || len(path) == 0 clear = clear || len(path) == 0
forceClear = forceClear || path == "!"
default: default:
break loop break loop
} }
} }
dir := nav.currDir()
if clear && len(gOpts.previewer) != 0 && len(gOpts.cleaner) != 0 && nav.volatilePreview { if clear && len(gOpts.previewer) != 0 && len(gOpts.cleaner) != 0 && nav.volatilePreview {
if forceClear || !isDirty(dir.files[dir.ind], dir.path, dir.dirtyfiles) { cmd := exec.Command(gOpts.cleaner, prev)
cmd := exec.Command(gOpts.cleaner, prev) if err := cmd.Run(); err != nil {
if err := cmd.Run(); err != nil { log.Printf("cleaning preview: %s", err)
log.Printf("cleaning preview: %s", err)
}
nav.volatilePreview = false
} }
nav.volatilePreview = false
} }
if len(path) != 0 { if len(path) != 0 {
win := ui.wins[len(ui.wins)-1] win := ui.wins[len(ui.wins)-1]
@ -554,19 +546,6 @@ func (nav *nav) previewLoop(ui *ui) {
} }
} }
func isDirty(f os.FileInfo, path string, dirtyfiles []string) bool {
dirty := false
for _, pattern := range dirtyfiles {
matched := matchPattern(strings.TrimPrefix(pattern, "!"), f.Name(), path)
if strings.HasPrefix(pattern, "!") && matched {
dirty = false
} else if matched {
dirty = true
}
}
return dirty
}
func matchPattern(pattern, name, path string) bool { func matchPattern(pattern, name, path string) bool {
s := name s := name

View File

@ -65,7 +65,6 @@ var gOpts struct {
truncatechar string truncatechar string
ratios []int ratios []int
hiddenfiles []string hiddenfiles []string
dirtyfiles []string
info []string info []string
shellopts []string shellopts []string
keys map[string]expr keys map[string]expr
@ -112,7 +111,6 @@ func init() {
gOpts.truncatechar = "~" gOpts.truncatechar = "~"
gOpts.ratios = []int{1, 2, 3} gOpts.ratios = []int{1, 2, 3}
gOpts.hiddenfiles = []string{".*"} gOpts.hiddenfiles = []string{".*"}
gOpts.dirtyfiles = []string{"!*"}
gOpts.info = nil gOpts.info = nil
gOpts.shellopts = nil gOpts.shellopts = nil
gOpts.sortType = sortType{naturalSort, dirfirstSort} gOpts.sortType = sortType{naturalSort, dirfirstSort}