From 86e84c9151e6970b8039a16ccfd7e49838d6b27d Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Sun, 6 Feb 2022 23:45:40 +0300 Subject: [PATCH] use XDG_RUNTIME_DIR for the socket file cc #722 #726 --- doc.go | 2 +- docstring.go | 2 +- lf.1 | 2 +- os.go | 7 ++++++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/doc.go b/doc.go index 025b9ed8..328c3c71 100644 --- a/doc.go +++ b/doc.go @@ -1026,7 +1026,7 @@ To use this feature, you need to use a client which supports communicating with OpenBSD implementation of netcat (nc) is one such example. You can use it to send a command to the socket file: - echo 'send echo hello world' | nc -U /tmp/lf.${USER}.sock + echo 'send echo hello world' | nc -U ${XDG_RUNTIME_DIR:-/tmp}/lf.${USER}.sock Since such a client may not be available everywhere, lf comes bundled with a command line flag to be used as such. When using lf, you do not need to specify the address of the socket file. diff --git a/docstring.go b/docstring.go index ee72228e..da8c0e55 100644 --- a/docstring.go +++ b/docstring.go @@ -1128,7 +1128,7 @@ To use this feature, you need to use a client which supports communicating with a UNIX-domain socket. OpenBSD implementation of netcat (nc) is one such example. You can use it to send a command to the socket file: - echo 'send echo hello world' | nc -U /tmp/lf.${USER}.sock + echo 'send echo hello world' | nc -U ${XDG_RUNTIME_DIR:-/tmp}/lf.${USER}.sock Since such a client may not be available everywhere, lf comes bundled with a command line flag to be used as such. When using lf, you do not need to diff --git a/lf.1 b/lf.1 index 86342364..c9114932 100644 --- a/lf.1 +++ b/lf.1 @@ -1213,7 +1213,7 @@ One of the more advanced features in lf is remote commands. All clients connect To use this feature, you need to use a client which supports communicating with a UNIX-domain socket. OpenBSD implementation of netcat (nc) is one such example. You can use it to send a command to the socket file: .PP .EX - echo 'send echo hello world' | nc -U /tmp/lf.${USER}.sock + echo 'send echo hello world' | nc -U ${XDG_RUNTIME_DIR:-/tmp}/lf.${USER}.sock .EE .PP Since such a client may not be available everywhere, lf comes bundled with a command line flag to be used as such. When using lf, you do not need to specify the address of the socket file. This is the recommended way of using remote commands since it is shorter and immune to socket file address changes: diff --git a/os.go b/os.go index 8db4b286..26623ae2 100644 --- a/os.go +++ b/os.go @@ -88,7 +88,12 @@ func init() { gMarksPath = filepath.Join(data, "lf", "marks") gHistoryPath = filepath.Join(data, "lf", "history") - gDefaultSocketPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.sock", gUser.Username)) + runtime := os.Getenv("XDG_RUNTIME_DIR") + if runtime == "" { + runtime = os.TempDir() + } + + gDefaultSocketPath = filepath.Join(runtime, fmt.Sprintf("lf.%s.sock", gUser.Username)) } func detachedCommand(name string, arg ...string) *exec.Cmd {