add builtin 'select' command to change selection
This commit is contained in:
parent
32d729eac1
commit
4f05975e77
1
comp.go
1
comp.go
@ -46,6 +46,7 @@ var (
|
|||||||
"sync",
|
"sync",
|
||||||
"echo",
|
"echo",
|
||||||
"cd",
|
"cd",
|
||||||
|
"select",
|
||||||
"push",
|
"push",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
doc.go
1
doc.go
@ -47,6 +47,7 @@ The following commands are provided by lf without default keybindings:
|
|||||||
sync synchronizes yanked/deleted files with server
|
sync synchronizes yanked/deleted files with server
|
||||||
echo prints its arguments to the message line
|
echo prints its arguments to the message line
|
||||||
cd changes working directory to its argument
|
cd changes working directory to its argument
|
||||||
|
select changes current file selection to its argument
|
||||||
push simulate key pushes given in its argument
|
push simulate key pushes given in its argument
|
||||||
|
|
||||||
The following command line commands are provided by lf with default
|
The following command line commands are provided by lf with default
|
||||||
|
@ -51,6 +51,7 @@ The following commands are provided by lf without default keybindings:
|
|||||||
sync synchronizes yanked/deleted files with server
|
sync synchronizes yanked/deleted files with server
|
||||||
echo prints its arguments to the message line
|
echo prints its arguments to the message line
|
||||||
cd changes working directory to its argument
|
cd changes working directory to its argument
|
||||||
|
select changes current file selection to its argument
|
||||||
push simulate key pushes given in its argument
|
push simulate key pushes given in its argument
|
||||||
|
|
||||||
The following command line commands are provided by lf with default
|
The following command line commands are provided by lf with default
|
||||||
|
11
eval.go
11
eval.go
@ -387,6 +387,17 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
case "select":
|
||||||
|
if len(e.args) != 1 {
|
||||||
|
app.ui.print("select: requires an argument")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := app.nav.find(e.args[0]); err != nil {
|
||||||
|
app.ui.printf("%s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "push":
|
case "push":
|
||||||
if len(e.args) > 0 {
|
if len(e.args) > 0 {
|
||||||
log.Println("pushing keys", e.args[0])
|
log.Println("pushing keys", e.args[0])
|
||||||
|
25
nav.go
25
nav.go
@ -260,6 +260,7 @@ func (nav *nav) getDirs(wd string) {
|
|||||||
|
|
||||||
for curr, base := wd, ""; !isRoot(base); curr, base = filepath.Dir(curr), filepath.Base(curr) {
|
for curr, base := wd, ""; !isRoot(base); curr, base = filepath.Dir(curr), filepath.Base(curr) {
|
||||||
dir := nav.loadDir(curr)
|
dir := nav.loadDir(curr)
|
||||||
|
dir.find(base, nav.height)
|
||||||
dirs = append(dirs, dir)
|
dirs = append(dirs, dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -618,6 +619,30 @@ func (nav *nav) cd(wd string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (nav *nav) find(path string) error {
|
||||||
|
lstat, err := os.Stat(path)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("select: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
dir := filepath.Dir(path)
|
||||||
|
|
||||||
|
if err := nav.cd(dir); err != nil {
|
||||||
|
return fmt.Errorf("select: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
base := filepath.Base(path)
|
||||||
|
|
||||||
|
last := nav.dirs[len(nav.dirs)-1]
|
||||||
|
if last.loading {
|
||||||
|
last.fi = append(last.fi, &file{FileInfo: lstat})
|
||||||
|
} else {
|
||||||
|
last.find(base, nav.height)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func match(pattern, name string) (matched bool, err error) {
|
func match(pattern, name string) (matched bool, err error) {
|
||||||
if gOpts.ignorecase {
|
if gOpts.ignorecase {
|
||||||
lpattern := strings.ToLower(pattern)
|
lpattern := strings.ToLower(pattern)
|
||||||
|
Loading…
Reference in New Issue
Block a user