From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: Add helper for .desktop file creation? Date: Sat, 25 May 2019 14:06:20 +0200 Message-ID: <87d0k67n7n.fsf@nicolasgoaziou.fr> References: <878suwz3tg.fsf@ambrevar.xyz> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([209.51.188.92]:34011) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hUVYW-0001XJ-WC for guix-devel@gnu.org; Sat, 25 May 2019 08:13:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hUVRd-0006n4-G1 for guix-devel@gnu.org; Sat, 25 May 2019 08:06:39 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:47925) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hUVRc-0006bt-B3 for guix-devel@gnu.org; Sat, 25 May 2019 08:06:36 -0400 In-Reply-To: <878suwz3tg.fsf@ambrevar.xyz> (Pierre Neidhardt's message of "Fri, 24 May 2019 09:53:15 +0200") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Pierre Neidhardt Cc: Guix-devel Hello, Pierre Neidhardt writes: > Quite a bunch of packages need to provide their own .desktop since > upstream does not provide them. It's very evident in games.scm in > particular. Interestingly, I had the same itch recently. > It seems to be a good opportunity to factor this out. What about the > following? > > --8<---------------cut here---------------start------------->8--- > (define* (make-desktop-file destination #:key > (encoding "UTF-8") > name > (generic-name name) > comment > exec > icon > (startup-notify "true") > (terminal "false") > (type "Application") > (categories "Application")) > "Create a desktop file at DESTINATION for executable EXEC with name NAME. > Other arguments are optional." > (let ((maybe-print (lambda (key value) > (if value > (string-append key "=" value "\n") > "")))) > (mkdir-p (dirname destination)) > (with-output-to-file destination > (lambda _ > (display > (string-append > "[Desktop Entry]" "\n" > "Encoding=" encoding "\n" > "Name=" name "\n" > "GenericName=" generic-name "\n" > (maybe-print "Comment" comment) > "Exec=" exec "\n" > (maybe-print "Icon" icon) > "StartupNotify=" startup-notify "\n" > "Terminal=" terminal "\n" > "Type=" type "\n" > "Categories=" categories "\n")))))) > --8<---------------cut here---------------end--------------->8--- It looks interesting. I have a couple of suggestions, if you don't mind: - some items are missing, e.g., "Keywords". As you may know, you can have a look at for a full list. - some items you use a list of strings instead of a string (e.g., "Keywords", "Categories"), - it would be nice to handle localized values for keys. For example `drascula' package uses "Comment[fr]". It could possibly be implemented with an alist as the value. I know Nix provides such a function, but I haven't looked at its implementation yet. Regards, -- Nicolas Goaziou