1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
Description: Add an ability to query files in the current directory as displayed in lf
Author: MahouShoujoMivutilde
Origin: upstream
Bug: https://github.com/gokcehan/lf/issues/1084
Applied-Upstream: https://github.com/gokcehan/lf/commit/1878faa942f5690a1541209f8ae432c26f554f59
Reviewed-by: Nick Morrott <nickm@debian.org>
Last-Update: 2025-05-04
---
--- a/app.go
+++ b/app.go
@@ -549,6 +549,7 @@
gState.data["cmds"] = listCmds().String()
gState.data["jumps"] = listJumps(app.nav.jumpList, app.nav.jumpListInd).String()
gState.data["history"] = listHistory(app.cmdHistory).String()
+ gState.data["files"] = listFilesInCurrDir(app.nav).String()
gState.mutex.Unlock()
cmd := shellCommand(s, args)
--- a/doc.md
+++ b/doc.md
@@ -1470,6 +1470,7 @@
cmds list of commands created by the 'cmd' command
jumps contents of the jump list, showing previously visited locations
history list of previously executed commands on the command line
+ files list of files in the currently open directory as displayed by lf, empty if dir is still loading
This is useful for scripting actions based on the internal state of lf.
For example, to select a previous command using fzf and execute it:
--- a/doc.txt
+++ b/doc.txt
@@ -1634,6 +1634,7 @@
cmds list of commands created by the 'cmd' command
jumps contents of the jump list, showing previously visited locations
history list of previously executed commands on the command line
+ files list of files in the currently open directory as displayed by lf, empty if dir is still loading
This is useful for scripting actions based on the internal state of lf.
For example, to select a previous command using fzf and execute it:
--- a/lf.1
+++ b/lf.1
@@ -1807,6 +1807,7 @@
cmds list of commands created by the \[aq]cmd\[aq] command
jumps contents of the jump list, showing previously visited locations
history list of previously executed commands on the command line
+files list of files in the currently open directory as displayed by lf, empty if dir is still loading
\f[R]
.fi
.PP
--- a/ui.go
+++ b/ui.go
@@ -1211,6 +1211,24 @@
return b
}
+func listFilesInCurrDir(nav *nav) *bytes.Buffer {
+ if !nav.init {
+ return nil
+ }
+ dir := nav.currDir()
+ if dir.loading {
+ log.Printf("listFilesInCurrDir(): %s is still loading, `files` isn't ready for remote query", dir.path)
+ return nil
+ }
+
+ b := new(bytes.Buffer)
+ for _, file := range dir.files {
+ fmt.Fprintln(b, file.path)
+ }
+
+ return b
+}
+
func (ui *ui) pollEvent() tcell.Event {
select {
case val := <-ui.keyChan:
|