unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* How to pass something on to xargs rm?
@ 2016-12-27 11:33 ng0
  2016-12-27 12:07 ` John Darrington
  0 siblings, 1 reply; 5+ messages in thread
From: ng0 @ 2016-12-27 11:33 UTC (permalink / raw)
  To: guile-user

Hi,

I have some scripts and small applications I'm slowly moving over
to guile.
One of them features this[0] line at the end which passes results on
to xargs rm. I picked a start with just (system*) everything I
had before to learn about the behavior and outcome, and improve
from this point.
I know that "|" will not work, so what else could possibly work
(for starters, in the long run I'll generalize and extend what I
currently have) to execute this command which deletes every file
listed in the previous search?

[0]: notmuch search --output=files tag:deleted | xargs -L 1 rm

Thanks,
-- 
♥Ⓐ  ng0
PGP keys and more: https://n0is.noblogs.org/ http://ng0.chaosnet.org



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to pass something on to xargs rm?
  2016-12-27 11:33 How to pass something on to xargs rm? ng0
@ 2016-12-27 12:07 ` John Darrington
  2016-12-27 12:42   ` ng0
  0 siblings, 1 reply; 5+ messages in thread
From: John Darrington @ 2016-12-27 12:07 UTC (permalink / raw)
  To: ng0; +Cc: guile-user

[-- Attachment #1: Type: text/plain, Size: 1030 bytes --]

On Tue, Dec 27, 2016 at 11:33:21AM +0000, ng0 wrote:
     Hi,
     
     I have some scripts and small applications I'm slowly moving over
     to guile.
     One of them features this[0] line at the end which passes results on
     to xargs rm. I picked a start with just (system*) everything I
     had before to learn about the behavior and outcome, and improve
     from this point.
     I know that "|" will not work, so what else could possibly work
     (for starters, in the long run I'll generalize and extend what I
     currently have) to execute this command which deletes every file
     listed in the previous search?
     
     [0]: notmuch search --output=files tag:deleted | xargs -L 1 rm
     

I think you want something like:   .... | xargs -I {} rm {}


J'

-- 
Avoid eavesdropping.  Send strong encrypted email.
PGP Public key ID: 1024D/2DE827B3 
fingerprint = 8797 A26D 0854 2EAB 0285  A290 8A67 719C 2DE8 27B3
See http://sks-keyservers.net or any PGP keyserver for public key.


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to pass something on to xargs rm?
  2016-12-27 12:07 ` John Darrington
@ 2016-12-27 12:42   ` ng0
  2016-12-27 13:04     ` Eli Zaretskii
  2017-05-29  9:36     ` Thien-Thi Nguyen
  0 siblings, 2 replies; 5+ messages in thread
From: ng0 @ 2016-12-27 12:42 UTC (permalink / raw)
  To: John Darrington; +Cc: guile-user

John Darrington <john@darrington.wattle.id.au> writes:

> On Tue, Dec 27, 2016 at 11:33:21AM +0000, ng0 wrote:
>      Hi,
>      
>      I have some scripts and small applications I'm slowly moving over
>      to guile.
>      One of them features this[0] line at the end which passes results on
>      to xargs rm. I picked a start with just (system*) everything I
>      had before to learn about the behavior and outcome, and improve
>      from this point.
>      I know that "|" will not work, so what else could possibly work
>      (for starters, in the long run I'll generalize and extend what I
>      currently have) to execute this command which deletes every file
>      listed in the previous search?
>      
>      [0]: notmuch search --output=files tag:deleted | xargs -L 1 rm
>      
>
> I think you want something like:   .... | xargs -I {} rm {}
>
>
> J'

I think I was a bit too verbose with my question. I meant to say:
the part behind the "|", which originates from a 1:1 conversion of
the bash based part, is ignored for obvious reasons. But what
would be a quick way (until I've learned enough on this topic
myself) to perform the deletion?
I know that the original, "notmuch search --output=files
tag:deleted | xargs -L 1 rm" works in the bash script, but for
the .scm script, everything above (fetching mail, tagging mail)
works and this part is ignored:
(system* "notmuch" "search" "--output=files" "tag:deleted" "|" "xargs" "-L" "1" "rm")

To give you an idea, this is (part of) the mailget.scm:

ng0@wasp ~$ cat mailget
#!/home/ng0/.guix-profile/bin/guile \
-s
!#

  (let* ((home (getenv "HOME"))
         ;;(tor-on (system* "." "torsocks" "on"))
         ;;(tor-off (system* "." "torsocks" "off"))
         (nm-new (system* "notmuch" "new")))
    (chdir (string-append home "/.getmail"))
    ;; tor-on
    ;;# find . -name '*.rc' | xargs -n1 -i basename {} .rc | xargs -P 2 -n1 -i getmail -r {}.rc
    ;; FIXME: *.rc not found here:
    ;; (system* "parallel" "getmail" "-q" "-r" "{}" ":::" "*.rc")
    (system* "getmail" "-r" "getmailrc_grrlz_2.rc")
    (system* "getmail" "-r" "getmailrc_runbox.rc")
    ;;tor-off
    nm-new
    (system* "notmuch" "tag" "-inbox" "+sometag" "--" "some subject")

    …
    ;; Of course I don't have literally somesubject sometag, I
       just will not expose what I tag and sort.
    …

    (system* "notmuch" "search" "--output=files" "tag:deleted" "|" "xargs" "-L" "1" "rm")
    (display "done")
    (newline))


If there is no obvious, quick solution based on what I currently
do, I will gladly accept any small pointers to subjects I could
read into and solve it later in a better version. I consider the
current script just a small hack.
One solution I can imagine is that I write some functions which
will allow me to save the output of such a search into a list I
can work with and execute the physical deletion on each element.

> -- 
> Avoid eavesdropping.  Send strong encrypted email.
> PGP Public key ID: 1024D/2DE827B3 
> fingerprint = 8797 A26D 0854 2EAB 0285  A290 8A67 719C 2DE8 27B3
> See http://sks-keyservers.net or any PGP keyserver for public key.
>

-- 
♥Ⓐ  ng0
PGP keys and more: https://n0is.noblogs.org/ http://ng0.chaosnet.org



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to pass something on to xargs rm?
  2016-12-27 12:42   ` ng0
@ 2016-12-27 13:04     ` Eli Zaretskii
  2017-05-29  9:36     ` Thien-Thi Nguyen
  1 sibling, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2016-12-27 13:04 UTC (permalink / raw)
  To: ng0; +Cc: guile-user

> From: ng0 <ng0@libertad.pw>
> Date: Tue, 27 Dec 2016 12:42:13 +0000
> Cc: guile-user@gnu.org
> 
> I think I was a bit too verbose with my question. I meant to say:
> the part behind the "|", which originates from a 1:1 conversion of
> the bash based part, is ignored for obvious reasons. But what
> would be a quick way (until I've learned enough on this topic
> myself) to perform the deletion?
> I know that the original, "notmuch search --output=files
> tag:deleted | xargs -L 1 rm" works in the bash script, but for
> the .scm script, everything above (fetching mail, tagging mail)
> works and this part is ignored:
> (system* "notmuch" "search" "--output=files" "tag:deleted" "|" "xargs" "-L" "1" "rm")

'system*' doesn't run the shell.  You need either 'system' (which
does), or use 'open-pipe*', 'open-input-pipe', etc.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to pass something on to xargs rm?
  2016-12-27 12:42   ` ng0
  2016-12-27 13:04     ` Eli Zaretskii
@ 2017-05-29  9:36     ` Thien-Thi Nguyen
  1 sibling, 0 replies; 5+ messages in thread
From: Thien-Thi Nguyen @ 2017-05-29  9:36 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 817 bytes --]


() ng0 <ng0@libertad.pw>
() Tue, 27 Dec 2016 12:42:13 +0000

   (system* "notmuch" "search" "--output=files" "tag:deleted" 
   "|" "xargs" "-L" "1" "rm")

Here's what i would do (untested):

(use-modules (ice-9 popen) (ice-9 rdelim))
(let* ((port (open-input-pipe "notmuch ..."))
       ;; no loop necessary, we only want one
       (filename (read-line port)))
  (close-port port)
  (delete-file filename))

Since this response is very late, i wonder if you have already
found a solution.  If so, would you mind posting it?

-- 
Thien-Thi Nguyen -----------------------------------------------
 (defun responsep (query)
   (pcase (context query)
     (`(technical ,ml) (correctp ml))
     ...))                              748E A0E8 1CB8 A748 9BFA
--------------------------------------- 6CE4 6703 2224 4C80 7502


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-05-29  9:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-27 11:33 How to pass something on to xargs rm? ng0
2016-12-27 12:07 ` John Darrington
2016-12-27 12:42   ` ng0
2016-12-27 13:04     ` Eli Zaretskii
2017-05-29  9:36     ` Thien-Thi Nguyen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).