diff --git a/CHANGELOG.md b/CHANGELOG.md index bb30d56a..02248325 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), ## r41 (Unreleased) +### Added + +- A new server command `list` is added to print the IDs of all currently connected clients (#2314). + ### Fixed - A bug where sixel images fail to display when scrolling back and forth is now fixed (#2301). diff --git a/doc.md b/doc.md index e6d86dfe..291f3eb2 100644 --- a/doc.md +++ b/doc.md @@ -86,7 +86,7 @@ Same as **-print-selection**, but write the newline-separated list to *path* ins **-remote** *command* -Send *command* to the running server (e.g. `send`, `query` or `quit`). See `REMOTE COMMANDS` for more details. +Send *command* to the running server (i.e. `send`, `query`, `list`, `quit`, or `quit!`). See `REMOTE COMMANDS` for more details. **-server** @@ -1777,6 +1777,10 @@ For example, to select a previous command using fzf and execute it: lf -remote "send $id $cmd" }} +The `list` command prints the IDs of all currently connected clients: + + lf -remote 'list' + There is also a `quit` command to quit the server when there are no connected clients left, and a `quit!` command to force quit the server by closing client connections first: lf -remote 'quit' diff --git a/doc.txt b/doc.txt index 402582c4..cb7a2088 100644 --- a/doc.txt +++ b/doc.txt @@ -91,8 +91,8 @@ SERVER -remote command - Send command to the running server (e.g. send, query or quit). See - REMOTE COMMANDS for more details. + Send command to the running server (i.e. send, query, list, quit, or + quit!). See REMOTE COMMANDS for more details. -server @@ -1960,6 +1960,10 @@ For example, to select a previous command using fzf and execute it: lf -remote "send $id $cmd" }} +The list command prints the IDs of all currently connected clients: + + lf -remote 'list' + There is also a quit command to quit the server when there are no connected clients left, and a quit! command to force quit the server by closing client connections first: diff --git a/lf.1 b/lf.1 index bb1e3fc1..b25510e9 100644 --- a/lf.1 +++ b/lf.1 @@ -1,6 +1,6 @@ .\" Automatically generated by Pandoc 3.7.0.2 .\" -.TH "LF" "1" "2025\-12\-10" "r40" "DOCUMENTATION" +.TH "LF" "1" "2025\-12\-21" "r41" "DOCUMENTATION" .SH NAME lf \- terminal file manager .SH SYNOPSIS @@ -88,8 +88,9 @@ list to \f[I]path\f[R] instead of stdout. .SS SERVER .TP \f[B]\-remote\f[R] \f[I]command\f[R] -Send \f[I]command\f[R] to the running server (e.g. -\f[CR]send\f[R], \f[CR]query\f[R] or \f[CR]quit\f[R]). +Send \f[I]command\f[R] to the running server (i.e. +\f[CR]send\f[R], \f[CR]query\f[R], \f[CR]list\f[R], \f[CR]quit\f[R], or +\f[CR]quit!\f[R]). See \f[CR]REMOTE COMMANDS\f[R] for more details. .TP \f[B]\-server\f[R] @@ -1849,6 +1850,13 @@ map ${{ }} .EE .PP +The \f[CR]list\f[R] command prints the IDs of all currently connected +clients: +.IP +.EX +lf \-remote \(aqlist\(aq +.EE +.PP There is also a \f[CR]quit\f[R] command to quit the server when there are no connected clients left, and a \f[CR]quit!\f[R] command to force quit the server by closing client connections first: diff --git a/server.go b/server.go index 0055656d..9deae0a1 100644 --- a/server.go +++ b/server.go @@ -6,6 +6,7 @@ import ( "log" "net" "os" + "sort" "strconv" ) @@ -106,6 +107,15 @@ Loop: } else { echoerr(c, "listen: drop: requires a client id") } + case "list": + ids := make([]int, 0, len(gConnList)) + for id := range gConnList { + ids = append(ids, id) + } + sort.Ints(ids) + for _, id := range ids { + fmt.Fprintln(c, id) + } case "send": if rest != "" { word2, rest2 := splitWord(rest)