~niklaseklund/detached.el

detached.el: Patch for OSX tail command line args v1 PROPOSED

Here is the patch for osx tail compatibility, have tested on linux as
well so I don't believe this will break on linux.

Daniel Pettersson (1):
  Add support for OSX tail

 detached.el           | 8 ++++----
 test/detached-test.el | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

-- 
2.34.5
#868684 .build.yml failed
detached.el/patches/.build.yml: FAILED in 1m23s

[Patch for OSX tail command line args][0] from [~dpettersson][1]

[0]: https://lists.sr.ht/~niklaseklund/detached.el/patches/36365
[1]: mailto:daniel@dpettersson.net

✗ #868684 FAILED detached.el/patches/.build.yml https://builds.sr.ht/~niklaseklund/job/868684
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~niklaseklund/detached.el/patches/36365/mbox | git am -3
Learn more about email & git

Re: [PATCH detached.el 0/1] Patch for OSX tail command line args Export this patch

~dpettersson <dpettersson@git.sr.ht> writes:

> Here is the patch for osx tail compatibility, have tested on linux as
> well so I don't believe this will break on linux.

Nice, thanks :). I tried out your patch and actually realized there was a
bug present already on the main branch related to your change.

,(concat "-n " detached-session-context-lines)

This wouldn't work since detached-session-context-lines is a number and
not a string.

Your patch looks good, one thing that I think we should change is that
the functions, when concat is not passed, now needs to be separated
since there is a space between the flag and the value.

Also added a test to make sure that the detached--tail-command do what
we expect. If these changes looks good to you then maybe you can add
them to your patch and verify that the behavior still works as you
expect.

/Niklas

diff --git a/detached.el b/detached.el
index f7dbbff..77f3eef 100644
--- a/detached.el
+++ b/detached.el
@@ -920,7 +920,8 @@ Optionally CONCAT the command return command into a string."
  (detached-connection-local-variables
   (let* ((log (detached--session-file session 'log t))
          (tail-command `(,detached-tail-program "-F"
                                                 ,(concat "-n " detached-session-context-lines)
                                                 "-n"
                                                 ,(number-to-string detached-session-context-lines)
                                                 ,log)))
     (cond ((eq 'create detached-session-mode)
            (detached--dtach-command session))
@@ -965,7 +966,8 @@ Optionally CONCAT the command return command into a string."
              " ")
           (append
            (when detached-show-session-context
              `(,detached-tail-program ,(format "-n %s" detached-session-context-lines)
              `(,detached-tail-program "-n"
                                       ,(number-to-string detached-session-context-lines)
                                       ,(concat log ";")))
            `(,detached-dtach-program ,dtach-arg ,socket "-r" "none")))
       (if concat
diff --git a/test/detached-test.el b/test/detached-test.el
index b53c02c..cc4ac5d 100644
--- a/test/detached-test.el
+++ b/test/detached-test.el
@@ -66,6 +66,24 @@

;;;; Tests

(ert-deftest detached-test-tail-command ()
  (detached-test--with-temp-database
   (cl-letf* ((detached-tail-program "tail")
              (session (detached-create-session "ls -la"))
              (detached-show-session-context t)
              (detached-session-context-lines 20)
              ((symbol-function #'detached-create-session)
               (lambda (_)
                 session)))
     (let* ((log (detached--session-file session 'log t))
            (expected `(,detached-tail-program
                        "-F" "-n" ,(number-to-string detached-session-context-lines)
                        ,log))
            (expected-concat (string-join expected " ")))
       (let ((detached-session-mode 'create-and-attach))
         (should (equal expected (detached--tail-command session)))
         (should (equal expected-concat (detached--tail-command session t))))))))

(ert-deftest detached-test-dtach-command ()
  (detached-test--with-temp-database
   (cl-letf* ((detached-dtach-program "dtach")
@@ -96,7 +114,7 @@
     (let* ((detached-session-mode 'attach)
            (log (detached--session-file session 'log t))
            (expected `(,detached-tail-program
                        ,(format "-n %s" detached-session-context-lines)
                        "-n" ,(number-to-string detached-session-context-lines)
                        ,(format "%s;" log)
                        ,detached-dtach-program "-a" ,(detached--session-file session 'socket t) "-r" "none"))
            (expected-concat (format "%s %s; %s -a %s -r none"

[PATCH detached.el 1/1] Add support for OSX tail Export this patch

From: Daniel Pettersson <daniel@dpettersson.net>

Strangely the tail of unixes has diverted. OSX tail does not have
support for "--" or long args. But the same functionality is hidden
under short args.

`--follow=name`, `--lines=` and `--retry` is not supported by OSX tail.

- `--lines=` is replaced by the short alternative `-n`

>      -n, --lines=[+]NUM
>             output the last NUM lines, instead of the last 10; or use
>             -n +NUM to output starting with line NUM
>
> tail(1) — Linux manual page

- `--follow=name` and `--retry` by `-F`

>      -F     same as --follow=name --retry
>
> tail(1) — Linux manual page

There is some trade off regarding descriptiveness but OSX support
seams preferable - OSX user
---
Hey again Niklas!

I sent a PR/Feature request when the repo was hosted at gitlab,
regarding having last shell-command as initial input for completing-
read.

Pushing changes that I had locally. I have a FSF copyright assignment
for emacs pending, but while that is pending I thought I would send this
patch before I forget.

Can ping you when the assignment is completed.

Also having some issues with "tail" on OSX as --lines is not supported,
the replacement would be "tail -10" for 10 lines.

Can create a patch for when I have some time left over.

PS: I could not find a mail address in the README so I am hoping this
the correct one.

-- daniel pettersson

 detached.el           | 8 ++++----
 test/detached-test.el | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/detached.el b/detached.el
index b878ea6..73c3eee 100644
--- a/detached.el
+++ b/detached.el
@@ -919,8 +919,8 @@ Optionally CONCAT the command return command into a string."
Optionally CONCAT the command return command into a string."
  (detached-connection-local-variables
   (let* ((log (detached--session-file session 'log t))
          (tail-command `(,detached-tail-program "--follow=name" "--retry"
                                                 ,(concat "--lines=" detached-session-context-lines)
          (tail-command `(,detached-tail-program "-F"
                                                 ,(concat "-n " detached-session-context-lines)
                                                 ,log)))
     (cond ((eq 'create detached-session-mode)
            (detached--dtach-command session))
@@ -957,7 +957,7 @@ Optionally CONCAT the command return command into a string."
         (if concat
             (string-join
              `(,(when detached-show-session-context
                   (format  "%s --lines=%s %s;" detached-tail-program detached-session-context-lines log))
                   (format  "%s -n %s %s;" detached-tail-program detached-session-context-lines log))
                ,detached-dtach-program
                ,dtach-arg
                ,socket
@@ -965,7 +965,7 @@ Optionally CONCAT the command return command into a string."
              " ")
           (append
            (when detached-show-session-context
              `(,detached-tail-program ,(format "--lines=%s" detached-session-context-lines)
              `(,detached-tail-program ,(format "-n %s" detached-session-context-lines)
                                       ,(concat log ";")))
            `(,detached-dtach-program ,dtach-arg ,socket "-r" "none")))
       (if concat
diff --git a/test/detached-test.el b/test/detached-test.el
index 513eb72..b53c02c 100644
--- a/test/detached-test.el
+++ b/test/detached-test.el
@@ -96,11 +96,11 @@
     (let* ((detached-session-mode 'attach)
            (log (detached--session-file session 'log t))
            (expected `(,detached-tail-program
                        ,(format "--lines=%s" detached-session-context-lines)
                        ,(format "-n %s" detached-session-context-lines)
                        ,(format "%s;" log)
                        ,detached-dtach-program "-a" ,(detached--session-file session 'socket t) "-r" "none"))
            (expected-concat (format "%s %s; %s -a %s -r none"
                                     (format "%s --lines=%s" detached-tail-program detached-session-context-lines)
                                     (format "%s -n %s" detached-tail-program detached-session-context-lines)
                                     log
                                     detached-dtach-program
                                     (detached--session-file session 'socket t))))
-- 
2.34.5
detached.el/patches/.build.yml: FAILED in 1m23s

[Patch for OSX tail command line args][0] from [~dpettersson][1]

[0]: https://lists.sr.ht/~niklaseklund/detached.el/patches/36365
[1]: mailto:daniel@dpettersson.net

✗ #868684 FAILED detached.el/patches/.build.yml https://builds.sr.ht/~niklaseklund/job/868684