Implement files query to export files in the current directory as (#1949)
presented in lf (including filter/sorting) `lf -remote "query $id files"` This version updates `files` list only before running shell commands.
This commit is contained in:
1 parent
3fdd991040
commit
1878faa942
5 files changed
+23
-1
No files matched your search
@@ -552,6 +552,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
||||
gState.data["cmds"] = listCmds()
|
||||
gState.data["jumps"] = listJumps(app.nav.jumpList, app.nav.jumpListInd)
|
||||
gState.data["history"] = listHistory(app.cmdHistory)
|
||||
gState.data["files"] = listFilesInCurrDir(app.nav)
|
||||
gState.mutex.Unlock()
|
||||
|
||||
cmd := shellCommand(s, args)
|
||||
|
||||
@@ -1470,6 +1470,7 @@ The following types of information are supported:
|
||||
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:
|
||||
|
||||
@@ -1634,6 +1634,7 @@ The following types of information are supported:
|
||||
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:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
.\" Automatically generated by Pandoc 2.11.4
|
||||
.\"
|
||||
.TH "LF" "1" "2025-02-18" "" "DOCUMENTATION"
|
||||
.TH "LF" "1" "2025-04-08" "r34-21-g3fdd991" "DOCUMENTATION"
|
||||
.hy
|
||||
.SH NAME
|
||||
.PP
|
||||
@@ -1807,6 +1807,7 @@ cmaps list of mappings created by the \[aq]cmap\[aq] command
|
||||
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
|
||||
|
||||
@@ -1224,6 +1224,24 @@ func listMarks(marks map[string]string) string {
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func listFilesInCurrDir(nav *nav) string {
|
||||
if !nav.init {
|
||||
return ""
|
||||
}
|
||||
dir := nav.currDir()
|
||||
if dir.loading {
|
||||
log.Printf("listFilesInCurrDir(): %s is still loading, `files` isn't ready for remote query", dir.path)
|
||||
return ""
|
||||
}
|
||||
|
||||
b := new(strings.Builder)
|
||||
for _, file := range dir.files {
|
||||
fmt.Fprintln(b, file.path)
|
||||
}
|
||||
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func (ui *ui) pollEvent() tcell.Event {
|
||||
select {
|
||||
case val := <-ui.keyChan:
|
||||
|
||||
Reference in new issue
Block a user