From b431d8fea195b113a5bb0eb8c01b7d5d986e4450 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sat, 2 Nov 2013 20:30:49 -0600 Subject: [PATCH] launcher ".desktop" handling: preserve existing `Exec=` content --- .../racket-doc/scribblings/raco/launcher.scrbl | 14 +++++++++----- racket/collects/launcher/launcher.rkt | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/pkgs/racket-pkgs/racket-doc/scribblings/raco/launcher.scrbl b/pkgs/racket-pkgs/racket-doc/scribblings/raco/launcher.scrbl index 67e67322eb..ce1500dc0d 100644 --- a/pkgs/racket-pkgs/racket-doc/scribblings/raco/launcher.scrbl +++ b/pkgs/racket-pkgs/racket-doc/scribblings/raco/launcher.scrbl @@ -117,11 +117,15 @@ the following additional associations apply to launchers: @item{@racket['desktop] (Unix) --- a string containing the content of a @filepath{.desktop} file for the launcher, where @tt{Exec} - and @tt{Icon} items should be omitted, because they will be - added automatically. The file is written to the directory - produced by @racket[(find-apps-dir)] or - @racket[(find-user-apps-dir)]. A @racket['desktop] value is - used only when @racket['install-mode] is also specified.} + and @tt{Icon} entries are added automatically. If an @tt{Exec} + entry exists in the string, and if its value starts with a + non-empty sequence of alpha-numeric ASCII characters followed + by a space, then the space and remainder of the value is + appended to the automatically generated value. + The @filepath{.desktop} file is written to the directory produced by + @racket[(find-apps-dir)] or @racket[(find-user-apps-dir)]. A + @racket['desktop] value is used only when + @racket['install-mode] is also specified.} @item{@racket['png] (Unix) : An icon file path (suffix @filepath{.png}) to be referenced by a @filepath{.desktop} diff --git a/racket/collects/launcher/launcher.rkt b/racket/collects/launcher/launcher.rkt index c08bc030fb..775e69ec4d 100644 --- a/racket/collects/launcher/launcher.rkt +++ b/racket/collects/launcher/launcher.rkt @@ -539,8 +539,20 @@ file #:exists 'truncate (lambda (o) - (displayln (regexp-replace #rx"\n+$" (cdr m) "") o) - (fprintf o "Exec=~a\n" (adjust-path dest)) + (define content (cdr m)) + (displayln (regexp-replace #rx"\n+$" + (regexp-replace "(?m:^Exec=.*)\n*" + content + "") + "") + o) + (fprintf o "Exec=~a~a\n" + (adjust-path dest) + ;; Keep rest of existing line, if any: + (let ([m (regexp-match "(?m:^Exec=[a-zA-Z0-9]+( .*))" content)]) + (if m + (cadr m) + ""))) (let ([m (or (assq 'png aux) (assq 'ico aux))]) (when m