glob-select implementation (#184)
* glob-select logical implementation * documentation * indentation * indentation * indentation * save * merge glob selects * check if selected before toggling * glob-unselect * identation ... * return early
This commit is contained in:
parent
eb8e516cfb
commit
bf39c7c63b
@ -58,6 +58,8 @@ var (
|
||||
"echoerr",
|
||||
"cd",
|
||||
"select",
|
||||
"glob-select",
|
||||
"glob-unselect",
|
||||
"source",
|
||||
"push",
|
||||
}
|
||||
|
2
doc.go
2
doc.go
@ -62,6 +62,8 @@ The following commands are provided by lf without default keybindings:
|
||||
echoerr same as echomsg but red color
|
||||
cd change working directory to the argument
|
||||
select change current file selection to the argument
|
||||
glob-select select files that match the given glob
|
||||
glob-unselect unselect files that match the given glob
|
||||
source read the configuration file in the argument
|
||||
push simulate key pushes given in the argument
|
||||
delete remove the current file or selected file(s)
|
||||
|
@ -65,6 +65,8 @@ The following commands are provided by lf without default keybindings:
|
||||
echoerr same as echomsg but red color
|
||||
cd change working directory to the argument
|
||||
select change current file selection to the argument
|
||||
glob-select select files that match the given glob
|
||||
glob-unselect unselect files that match the given glob
|
||||
source read the configuration file in the argument
|
||||
push simulate key pushes given in the argument
|
||||
delete remove the current file or selected file(s)
|
||||
|
21
eval.go
21
eval.go
@ -833,6 +833,27 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
if wd != path {
|
||||
app.nav.marks["'"] = wd
|
||||
}
|
||||
case "glob-select":
|
||||
if len(e.args) != 1 {
|
||||
app.ui.echoerr("glob-select: requires a pattern to match")
|
||||
return
|
||||
}
|
||||
|
||||
if err := app.nav.globSel(e.args[0], false); err != nil {
|
||||
app.ui.echoerrf("%s", err)
|
||||
return
|
||||
}
|
||||
case "glob-unselect":
|
||||
if len(e.args) != 1 {
|
||||
app.ui.echoerr("glob-unselect: requires a pattern to match")
|
||||
return
|
||||
}
|
||||
|
||||
if err := app.nav.globSel(e.args[0], true); err != nil {
|
||||
app.ui.echoerrf("%s", err)
|
||||
return
|
||||
}
|
||||
|
||||
case "source":
|
||||
if len(e.args) != 1 {
|
||||
app.ui.echoerr("source: requires an argument")
|
||||
|
2
lf.1
2
lf.1
@ -74,6 +74,8 @@ The following commands are provided by lf without default keybindings:
|
||||
echoerr same as echomsg but red color
|
||||
cd change working directory to the argument
|
||||
select change current file selection to the argument
|
||||
glob-select select files that match the given glob
|
||||
glob-unselect unselect files that match the given glob
|
||||
source read the configuration file in the argument
|
||||
push simulate key pushes given in the argument
|
||||
delete remove the current file or selected file(s)
|
||||
|
24
nav.go
24
nav.go
@ -794,6 +794,30 @@ func (nav *nav) sel(path string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nav *nav) globSel(pattern string, invert bool) error {
|
||||
curDir := nav.currDir()
|
||||
anyMatches := false
|
||||
|
||||
for i := 0; i < len(curDir.files); i++ {
|
||||
match, err := filepath.Match(pattern, curDir.files[i].Name())
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("glob-select: %s", err)
|
||||
}
|
||||
if match {
|
||||
anyMatches = true
|
||||
fpath := filepath.Join(curDir.path, curDir.files[i].Name())
|
||||
if _, ok := nav.selections[fpath]; ok == invert {
|
||||
nav.toggleSelection(fpath)
|
||||
}
|
||||
}
|
||||
}
|
||||
if !anyMatches {
|
||||
return fmt.Errorf("glob-select: pattern not found: %s", pattern)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func findMatch(name, pattern string) bool {
|
||||
if gOpts.ignorecase {
|
||||
lpattern := strings.ToLower(pattern)
|
||||
|
Loading…
Reference in New Issue
Block a user