From 06a30eda19c35eb993426396a641a87543e85bc3 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Wed, 19 May 2021 21:55:19 +0300 Subject: [PATCH] add 'autoquit' option to auto quit server on quit cc #177 --- app.go | 9 +++++++-- complete.go | 3 +++ doc.go | 5 +++++ docstring.go | 5 +++++ eval.go | 6 ++++++ lf.1 | 7 +++++++ opts.go | 2 ++ 7 files changed, 35 insertions(+), 2 deletions(-) diff --git a/app.go b/app.go index 4b3c4a4e..0006cec6 100644 --- a/app.go +++ b/app.go @@ -59,11 +59,16 @@ func newApp(ui *ui, nav *nav) *app { } func (app *app) quit() { + if err := app.writeHistory(); err != nil { + log.Printf("writing history file: %s", err) + } if err := remote(fmt.Sprintf("drop %d", gClientID)); err != nil { log.Printf("dropping connection: %s", err) } - if err := app.writeHistory(); err != nil { - log.Printf("writing history file: %s", err) + if gOpts.autoquit { + if err := remote("quit"); err != nil { + log.Printf("auto quitting server: %s", err) + } } os.Remove(gLogPath) } diff --git a/complete.go b/complete.go index 58fd6b62..2b61b715 100644 --- a/complete.go +++ b/complete.go @@ -70,6 +70,9 @@ var ( "anchorfind", "noanchorfind", "anchorfind!", + "autoquit", + "noautoquit", + "autoquit!", "dircounts", "nodircounts", "dircounts!", diff --git a/doc.go b/doc.go index 43e7b990..bf973efd 100644 --- a/doc.go +++ b/doc.go @@ -98,6 +98,7 @@ The following command line commands are provided by lf: The following options can be used to customize the behavior of lf: anchorfind bool (default on) + autoquit bool (default off) dircounts bool (default off) dirfirst bool (default on) drawbox bool (default off) @@ -489,6 +490,10 @@ Character ':' is used as the separator for list options '[]int' and '[]string'. When this option is enabled, find command starts matching patterns from the beginning of file names, otherwise, it can match at an arbitrary position. + autoquit bool (default off) + +Automatically quit server when there are no clients left connected. + dircounts bool (default off) When this option is enabled, directory sizes show the number of items inside instead of the size of directory file. diff --git a/docstring.go b/docstring.go index f077fd21..2619bbf0 100644 --- a/docstring.go +++ b/docstring.go @@ -102,6 +102,7 @@ The following command line commands are provided by lf: The following options can be used to customize the behavior of lf: anchorfind bool (default on) + autoquit bool (default off) dircounts bool (default off) dirfirst bool (default on) drawbox bool (default off) @@ -515,6 +516,10 @@ Character ':' is used as the separator for list options '[]int' and When this option is enabled, find command starts matching patterns from the beginning of file names, otherwise, it can match at an arbitrary position. + autoquit bool (default off) + +Automatically quit server when there are no clients left connected. + dircounts bool (default off) When this option is enabled, directory sizes show the number of items inside diff --git a/eval.go b/eval.go index d7153c62..eaed98df 100644 --- a/eval.go +++ b/eval.go @@ -20,6 +20,12 @@ func (e *setExpr) eval(app *app, args []string) { gOpts.anchorfind = false case "anchorfind!": gOpts.anchorfind = !gOpts.anchorfind + case "autoquit": + gOpts.autoquit = true + case "noautoquit": + gOpts.autoquit = false + case "autoquit!": + gOpts.autoquit = !gOpts.autoquit case "dircounts": gOpts.dircounts = true case "nodircounts": diff --git a/lf.1 b/lf.1 index 74715ae1..cc32e963 100644 --- a/lf.1 +++ b/lf.1 @@ -116,6 +116,7 @@ The following options can be used to customize the behavior of lf: .PP .EX anchorfind bool (default on) + autoquit bool (default off) dircounts bool (default off) dirfirst bool (default on) drawbox bool (default off) @@ -609,6 +610,12 @@ This section shows information about options to customize the behavior. Characte .PP When this option is enabled, find command starts matching patterns from the beginning of file names, otherwise, it can match at an arbitrary position. .PP +.EX + autoquit bool (default off) +.EE +.PP +Automatically quit server when there are no clients left connected. +.PP .EX dircounts bool (default off) .EE diff --git a/opts.go b/opts.go index 62edda00..904e31e8 100644 --- a/opts.go +++ b/opts.go @@ -29,6 +29,7 @@ type sortType struct { var gOpts struct { anchorfind bool + autoquit bool dircounts bool drawbox bool globsearch bool @@ -71,6 +72,7 @@ var gOpts struct { func init() { gOpts.anchorfind = true + gOpts.autoquit = false gOpts.dircounts = false gOpts.drawbox = false gOpts.globsearch = false