diff --git a/doc.md b/doc.md index 10b53459..c151001c 100644 --- a/doc.md +++ b/doc.md @@ -9,6 +9,7 @@ lf - terminal file manager [**-config** *path*] [**-cpuprofile** *path*] [**-doc**] +[**-help**] [**-last-dir-path** *path*] [**-log** *path*] [**-memprofile** *path*] @@ -19,7 +20,6 @@ lf - terminal file manager [**-server**] [**-single**] [**-version**] -[**-help**] [*cd-or-select-path*] # DESCRIPTION @@ -32,7 +32,113 @@ This documentation can either be read from the terminal using `lf -doc` or onlin You can also use the `help` command (default ``) inside lf to view the documentation in a pager. A man page with the same content is also available in the repository at https://github.com/gokcehan/lf/blob/master/lf.1 -You can run `lf -help` to see descriptions of command line options. +# OPTIONS + +## POSITIONAL ARGUMENTS + +**cd-or-select-path** + +Set the starting location. If *path* is a directory, start in there. If it's a file, start in the file's parent directory and select the file. When no *path* is supplied, lf uses the current directory. Only accepts one argument. + +## META OPTIONS + +**-doc** + +Show lf's documentation (same content as this file) and exit. + +**-help** + +Show command-line usage and exit. + +**-version** + +Show version information and exit. + +## STARTUP & CONFIGURATION + +**-command** *command* + +Execute *command* during client initialization (i.e. after reading configuration, before `on-init`). To execute more than one command, you can either use the **-command** flag multiple times or pass multiple commands at once by chaining them with ";". + +**-config** *path* + +Use the config file at *path* instead of the normal search locations. This only affects which `lfrc` is read at startup. + +## SHELL INTEGRATION + +**-print-last-dir** + +Print the last directory to stdout when lf exits. This can be used to let lf change your shells working directory. See `CHANGING DIRECTORY` for more details. + +**-last-dir-path** *path* + +Same as **-print-last-dir**, but write the directory to *path* instead of stdout. + +**-print-selection** + +Print selected files to stdout when opening a file in lf. This can be used to use lf as an "open file" dialog. First, select the files you want to pass to another program. Then, confirm the selection by opening a file. This causes lf to quit and print out the selection. Quitting lf prematurely discards the selection. + +**-selection-path** *path* + +Same as **-print-selection**, but write the newline-separated list to *path* instead of stdout. + +## SERVER + +**-remote** *command* + +Send *command* to the running server (e.g. `send`, `query` or `quit`). See `REMOTE COMMANDS` for more details. + +**-server** + +Start the (headless) server process explicitly. Runs in the foreground and writes server logs to stderr (or the file set with **-log**). Clients auto-start a server if none is running unless **-single** is used. + +**-single** + +Start a stand-alone client without a server. Disables remote control. + +## DIAGNOSTICS + +**-log** *path* + +Append runtime log messages to *path*. + +**-cpuprofile** *path* + +Write a CPU profile to *path*. The profile can be used by `go tool pprof`. + +**-memprofile** *path* + +Write a memory profile to *path*. The profile can be used by `go tool pprof`. + +## EXAMPLES + +Use `lf` to select files (while hiding certain file types): + + lf -command 'set nohidden' -command 'set hiddenfiles "*mp4:*pdf:*txt"' -print-selection + +Another sophisticated "open file" dialog focusing on design: + + lf -command 'set nopreview; set ratios 1; set drawbox; set promptfmt "Select files [%w] %S q: cancel, l: confirm"' -print-selection + +Open Downloads and set `sortby` and `info` to creation date: + + lf -command 'set sortby btime; set info btime' ~/Downloads + +Temporarily prevent `lf` from modifying the command history: + + lf -command 'set nohistory' + +Use default settings and log current session: + + lf -config /dev/null -log /tmp/lf.log + +Force-quit the server: + + lf -remote 'quit!' + +Inherit lf's working directory in your shell: + + cd "$(lf -print-last-dir)" # QUICK REFERENCE @@ -721,7 +827,7 @@ Delete the previous word in the backward direction. Capitalize/uppercase/lowercase the current word and jump to the next word. -# OPTIONS +# SETTINGS This section shows information about options to customize the behavior. Character `:` is used as the separator for list options `[]int` and `[]string`. @@ -1657,8 +1763,12 @@ There is also a `quit` command to quit the server when there are no connected cl lf -remote 'quit' lf -remote 'quit!' -Lastly, there is a `conn` command to connect the server to a client. -This should not be needed for users. +Lastly, the commands `conn` and `drop` connect or disconnect ID to/from the server: + + lf -remote 'conn $id' + lf -remote 'drop $id' + +These are internal and generally not needed by users. # FILE OPERATIONS diff --git a/doc.txt b/doc.txt index 98c51bf2..c22364cc 100644 --- a/doc.txt +++ b/doc.txt @@ -4,10 +4,10 @@ lf - terminal file manager SYNOPSIS -lf [-command command] [-config path] [-cpuprofile path] [-doc] +lf [-command command] [-config path] [-cpuprofile path] [-doc] [-help] [-last-dir-path path] [-log path] [-memprofile path] [-print-last-dir] [-print-selection] [-remote command] [-selection-path path] [-server] -[-single] [-version] [-help] [cd-or-select-path] +[-single] [-version] [cd-or-select-path] DESCRIPTION @@ -22,7 +22,135 @@ use the help command (default ) inside lf to view the documentation in a pager. A man page with the same content is also available in the repository at https://github.com/gokcehan/lf/blob/master/lf.1 -You can run lf -help to see descriptions of command line options. +OPTIONS + +POSITIONAL ARGUMENTS + +cd-or-select-path + + Set the starting location. If path is a directory, start in there. + If it's a file, start in the file's parent directory and select the + file. When no path is supplied, lf uses the current directory. Only + accepts one argument. + +META OPTIONS + +-doc + + Show lf's documentation (same content as this file) and exit. + +-help + + Show command-line usage and exit. + +-version + + Show version information and exit. + +STARTUP & CONFIGURATION + +-command command + + Execute command during client initialization (i.e. after reading + configuration, before on-init). To execute more than one command, + you can either use the -command flag multiple times or pass multiple + commands at once by chaining them with ";". + +-config path + + Use the config file at path instead of the normal search locations. + This only affects which lfrc is read at startup. + +SHELL INTEGRATION + +-print-last-dir + + Print the last directory to stdout when lf exits. This can be used + to let lf change your shells working directory. See + CHANGING DIRECTORY for more details. + +-last-dir-path path + + Same as -print-last-dir, but write the directory to path instead of + stdout. + +-print-selection + + Print selected files to stdout when opening a file in lf. This can + be used to use lf as an "open file" dialog. First, select the files + you want to pass to another program. Then, confirm the selection by + opening a file. This causes lf to quit and print out the selection. + Quitting lf prematurely discards the selection. + +-selection-path path + + Same as -print-selection, but write the newline-separated list to + path instead of stdout. + +SERVER + +-remote command + + Send command to the running server (e.g. send, query or quit). See + REMOTE COMMANDS for more details. + +-server + + Start the (headless) server process explicitly. Runs in the + foreground and writes server logs to stderr (or the file set with + -log). Clients auto-start a server if none is running unless -single + is used. + +-single + + Start a stand-alone client without a server. Disables remote + control. + +DIAGNOSTICS + +-log path + + Append runtime log messages to path. + +-cpuprofile path + + Write a CPU profile to path. The profile can be used by + go tool pprof. + +-memprofile path + + Write a memory profile to path. The profile can be used by + go tool pprof. + +EXAMPLES + +Use lf to select files (while hiding certain file types): + + lf -command 'set nohidden' -command 'set hiddenfiles "*mp4:*pdf:*txt"' -print-selection + +Another sophisticated "open file" dialog focusing on design: + + lf -command 'set nopreview; set ratios 1; set drawbox; set promptfmt "Select files [%w] %S q: cancel, l: confirm"' -print-selection + +Open Downloads and set sortby and info to creation date: + + lf -command 'set sortby btime; set info btime' ~/Downloads + +Temporarily prevent lf from modifying the command history: + + lf -command 'set nohistory' + +Use default settings and log current session: + + lf -config /dev/null -log /tmp/lf.log + +Force-quit the server: + + lf -remote 'quit!' + +Inherit lf's working directory in your shell: + + cd "$(lf -print-last-dir)" QUICK REFERENCE @@ -750,7 +878,7 @@ cmd-capitalize-word (default ), cmd-uppercase-word (default ), cmd-low Capitalize/uppercase/lowercase the current word and jump to the next word. -OPTIONS +SETTINGS This section shows information about options to customize the behavior. Character : is used as the separator for list options []int and @@ -1817,8 +1945,13 @@ closing client connections first: lf -remote 'quit' lf -remote 'quit!' -Lastly, there is a conn command to connect the server to a client. This -should not be needed for users. +Lastly, the commands conn and drop connect or disconnect ID to/from the +server: + + lf -remote 'conn $id' + lf -remote 'drop $id' + +These are internal and generally not needed by users. FILE OPERATIONS diff --git a/gen/deflist.lua b/gen/deflist.lua new file mode 100644 index 00000000..97331d3e --- /dev/null +++ b/gen/deflist.lua @@ -0,0 +1,45 @@ +local stringify = pandoc.utils.stringify +local List = pandoc.List +local DefinitionList = pandoc.DefinitionList + +-- We use bold paragraphs for flags (e.g. **-help**) +local function is_term(b) + return b.tag == "Para" and b.content[1] and b.content[1].tag == "Strong" +end + +-- GitHub-flavored markdown lacks native definition lists (i.e. ":" syntax). +-- Therefore, we generate them on the fly to get a better-looking "OPTIONS" +-- section in man pages and plain-text help without changing the source file. +function Blocks(blocks) + local out = List() + local i = 1 + local in_opts, lvl = false, nil + + while blocks[i] do + local b = blocks[i] + i = i + 1 + + if b.tag == "Header" then + -- Apply definition lists inside "OPTIONS" only + if stringify(b.content) == "OPTIONS" then + in_opts, lvl = true, b.level + else + in_opts = in_opts and b.level > lvl + end + out:insert(b) + elseif in_opts and is_term(b) then + -- Collect definition for current term + local def = List() + while blocks[i] and blocks[i].tag ~= "Header" and not is_term(blocks[i]) do + def:insert(blocks[i]) + i = i + 1 + end + out:insert(DefinitionList({ { b.content, { def } } })) + else + -- Pass through unchanged + out:insert(b) + end + end + + return out +end diff --git a/gen/doc.sh b/gen/doc.sh index 7801540a..9ee5c494 100755 --- a/gen/doc.sh +++ b/gen/doc.sh @@ -28,6 +28,7 @@ generate_man_page() { --volume "$PWD:/data" \ "$@" "$PANDOC_IMAGE" \ --standalone \ + --lua-filter /data/gen/deflist.lua \ --from gfm --to man \ --metadata=title:"LF" \ --metadata=section:"1" \ @@ -43,6 +44,7 @@ generate_plain_text() { --volume "$PWD:/data" \ "$@" "$PANDOC_IMAGE" \ --standalone \ + --lua-filter /data/gen/deflist.lua \ --from gfm --to plain \ doc.md -o doc.txt } diff --git a/lf.1 b/lf.1 index f774fe98..4c8130aa 100644 --- a/lf.1 +++ b/lf.1 @@ -1,17 +1,17 @@ .\" Automatically generated by Pandoc 3.7.0.2 .\" -.TH "LF" "1" "2025\-09\-29" "r39" "DOCUMENTATION" +.TH "LF" "1" "2025\-10\-17" "r39" "DOCUMENTATION" .SH NAME lf \- terminal file manager .SH SYNOPSIS \f[B]lf\f[R] [\f[B]\-command\f[R] \f[I]command\f[R]] [\f[B]\-config\f[R] \f[I]path\f[R]] [\f[B]\-cpuprofile\f[R] \f[I]path\f[R]] -[\f[B]\-doc\f[R]] [\f[B]\-last\-dir\-path\f[R] \f[I]path\f[R]] -[\f[B]\-log\f[R] \f[I]path\f[R]] [\f[B]\-memprofile\f[R] \f[I]path\f[R]] -[\f[B]\-print\-last\-dir\f[R]] [\f[B]\-print\-selection\f[R]] -[\f[B]\-remote\f[R] \f[I]command\f[R]] [\f[B]\-selection\-path\f[R] -\f[I]path\f[R]] [\f[B]\-server\f[R]] [\f[B]\-single\f[R]] -[\f[B]\-version\f[R]] [\f[B]\-help\f[R]] +[\f[B]\-doc\f[R]] [\f[B]\-help\f[R]] [\f[B]\-last\-dir\-path\f[R] +\f[I]path\f[R]] [\f[B]\-log\f[R] \f[I]path\f[R]] [\f[B]\-memprofile\f[R] +\f[I]path\f[R]] [\f[B]\-print\-last\-dir\f[R]] +[\f[B]\-print\-selection\f[R]] [\f[B]\-remote\f[R] \f[I]command\f[R]] +[\f[B]\-selection\-path\f[R] \f[I]path\f[R]] [\f[B]\-server\f[R]] +[\f[B]\-single\f[R]] [\f[B]\-version\f[R]] [\f[I]cd\-or\-select\-path\f[R]] .SH DESCRIPTION lf is a terminal file manager. @@ -30,9 +30,133 @@ A man page with the same content is also available in the repository at \c .UR https://github.com/gokcehan/lf/blob/master/lf.1 .UE \c +.SH OPTIONS +.SS POSITIONAL ARGUMENTS +.TP +\f[B]cd\-or\-select\-path\f[R] +Set the starting location. +If \f[I]path\f[R] is a directory, start in there. +If it\(aqs a file, start in the file\(aqs parent directory and select +the file. +When no \f[I]path\f[R] is supplied, lf uses the current directory. +Only accepts one argument. +.SS META OPTIONS +.TP +\f[B]\-doc\f[R] +Show lf\(aqs documentation (same content as this file) and exit. +.TP +\f[B]\-help\f[R] +Show command\-line usage and exit. +.TP +\f[B]\-version\f[R] +Show version information and exit. +.SS STARTUP & CONFIGURATION +.TP +\f[B]\-command\f[R] \f[I]command\f[R] +Execute \f[I]command\f[R] during client initialization (i.e. +after reading configuration, before \f[CR]on\-init\f[R]). +To execute more than one command, you can either use the +\f[B]\-command\f[R] flag multiple times or pass multiple commands at +once by chaining them with \(dq;\(dq. +.TP +\f[B]\-config\f[R] \f[I]path\f[R] +Use the config file at \f[I]path\f[R] instead of the normal search +locations. +This only affects which \f[CR]lfrc\f[R] is read at startup. +.SS SHELL INTEGRATION +.TP +\f[B]\-print\-last\-dir\f[R] +Print the last directory to stdout when lf exits. +This can be used to let lf change your shells working directory. +See \f[CR]CHANGING DIRECTORY\f[R] for more details. +.TP +\f[B]\-last\-dir\-path\f[R] \f[I]path\f[R] +Same as \f[B]\-print\-last\-dir\f[R], but write the directory to +\f[I]path\f[R] instead of stdout. +.TP +\f[B]\-print\-selection\f[R] +Print selected files to stdout when opening a file in lf. +This can be used to use lf as an \(dqopen file\(dq dialog. +First, select the files you want to pass to another program. +Then, confirm the selection by opening a file. +This causes lf to quit and print out the selection. +Quitting lf prematurely discards the selection. +.TP +\f[B]\-selection\-path\f[R] \f[I]path\f[R] +Same as \f[B]\-print\-selection\f[R], but write the newline\-separated +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]). +See \f[CR]REMOTE COMMANDS\f[R] for more details. +.TP +\f[B]\-server\f[R] +Start the (headless) server process explicitly. +Runs in the foreground and writes server logs to stderr (or the file set +with \f[B]\-log\f[R]). +Clients auto\-start a server if none is running unless +\f[B]\-single\f[R] is used. +.TP +\f[B]\-single\f[R] +Start a stand\-alone client without a server. +Disables remote control. +.SS DIAGNOSTICS +.TP +\f[B]\-log\f[R] \f[I]path\f[R] +Append runtime log messages to \f[I]path\f[R]. +.TP +\f[B]\-cpuprofile\f[R] \f[I]path\f[R] +Write a CPU profile to \f[I]path\f[R]. +The profile can be used by \f[CR]go tool pprof\f[R]. +.TP +\f[B]\-memprofile\f[R] \f[I]path\f[R] +Write a memory profile to \f[I]path\f[R]. +The profile can be used by \f[CR]go tool pprof\f[R]. +.SS EXAMPLES +Use \f[CR]lf\f[R] to select files (while hiding certain file types): +.IP +.EX +lf \-command \(aqset nohidden\(aq \-command \(aqset hiddenfiles \(dq*mp4:*pdf:*txt\(dq\(aq \-print\-selection +.EE .PP -You can run \f[CR]lf \-help\f[R] to see descriptions of command line -options. +Another sophisticated \(dqopen file\(dq dialog focusing on design: +.IP +.EX +lf \-command \(aqset nopreview; set ratios 1; set drawbox; set promptfmt \(dqSelect files [%w] %S q: cancel, l: confirm\(dq\(aq \-print\-selection +.EE +.PP +Open Downloads and set \f[CR]sortby\f[R] and \f[CR]info\f[R] to creation +date: +.IP +.EX +lf \-command \(aqset sortby btime; set info btime\(aq \(ti/Downloads +.EE +.PP +Temporarily prevent \f[CR]lf\f[R] from modifying the command history: +.IP +.EX +lf \-command \(aqset nohistory\(aq +.EE +.PP +Use default settings and log current session: +.IP +.EX +lf \-config /dev/null \-log /tmp/lf.log +.EE +.PP +Force\-quit the server: +.IP +.EX +lf \-remote \(aqquit!\(aq +.EE +.PP +Inherit lf\(aqs working directory in your shell: +.IP +.EX +cd \(dq$(lf \-print\-last\-dir)\(dq +.EE .SH QUICK REFERENCE The following commands are provided by lf: .IP @@ -665,7 +789,7 @@ Delete the previous word in the backward direction. .SS cmd\-capitalize\-word (default \f[CR]\f[R]), cmd\-uppercase\-word (default \f[CR]\f[R]), cmd\-lowercase\-word (default \f[CR]\f[R]) Capitalize/uppercase/lowercase the current word and jump to the next word. -.SH OPTIONS +.SH SETTINGS This section shows information about options to customize the behavior. Character \f[CR]:\f[R] is used as the separator for list options \f[CR][]int\f[R] and \f[CR][]string\f[R]. @@ -1706,9 +1830,15 @@ lf \-remote \(aqquit\(aq lf \-remote \(aqquit!\(aq .EE .PP -Lastly, there is a \f[CR]conn\f[R] command to connect the server to a -client. -This should not be needed for users. +Lastly, the commands \f[CR]conn\f[R] and \f[CR]drop\f[R] connect or +disconnect ID to/from the server: +.IP +.EX +lf \-remote \(aqconn $id\(aq +lf \-remote \(aqdrop $id\(aq +.EE +.PP +These are internal and generally not needed by users. .SH FILE OPERATIONS lf uses its own built\-in copy and move operations by default. These are implemented as asynchronous operations and progress is shown diff --git a/main.go b/main.go index f61c6d2e..0a08c811 100644 --- a/main.go +++ b/main.go @@ -239,6 +239,11 @@ func main() { false, "show documentation") + showHelp := flag.Bool( + "help", + false, + "show help") + showVersion := flag.Bool( "version", false, @@ -330,6 +335,8 @@ func main() { switch { case *showDoc: fmt.Print(genDocString) + case *showHelp: + flag.Usage() case *showVersion: printVersion() case *remoteCmd != "":