From patchwork Mon Jun 5 12:19:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Efraim Flashner X-Patchwork-Id: 50685 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 1D65927BBE9; Mon, 5 Jun 2023 13:21:10 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 201E727BBE2 for ; Mon, 5 Jun 2023 13:21:06 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q69CZ-0001MQ-5q; Mon, 05 Jun 2023 08:20:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q69Br-0001Hf-Fu for guix-patches@gnu.org; Mon, 05 Jun 2023 08:20:05 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q69Bq-0000Yi-8q for guix-patches@gnu.org; Mon, 05 Jun 2023 08:20:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q69Bp-0003NA-Kp for guix-patches@gnu.org; Mon, 05 Jun 2023 08:20:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#63909] [PATCH] home: Add inputrc service. Resent-From: Efraim Flashner Original-Sender: "Debbugs-submit" Resent-CC: , guix-patches@gnu.org Resent-Date: Mon, 05 Jun 2023 12:20:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 63909 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 63909@debbugs.gnu.org Cc: Efraim Flashner , ( , Andrew Tropin , Ludovic =?utf-8?q?Court=C3=A8s?= X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Xcc: ( , Andrew Tropin , Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by submit@debbugs.gnu.org id=B.168596757212916 (code B ref -1); Mon, 05 Jun 2023 12:20:01 +0000 Received: (at submit) by debbugs.gnu.org; 5 Jun 2023 12:19:32 +0000 Received: from localhost ([127.0.0.1]:48330 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q69BL-0003MG-Iv for submit@debbugs.gnu.org; Mon, 05 Jun 2023 08:19:32 -0400 Received: from lists.gnu.org ([209.51.188.17]:38434) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q69BI-0003M6-R4 for submit@debbugs.gnu.org; Mon, 05 Jun 2023 08:19:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q69BF-0001Cj-38 for guix-patches@gnu.org; Mon, 05 Jun 2023 08:19:28 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q69BC-0000UR-N4 for guix-patches@gnu.org; Mon, 05 Jun 2023 08:19:24 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3f730c1253fso15083625e9.1 for ; Mon, 05 Jun 2023 05:19:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685967561; x=1688559561; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=z+w1EIm+JkVk3uX1q6j1vUHiTmy2iURlBZ4bKKFARlQ=; b=NWIkJSqTB8CEPU3J5ZKQdAQOSYu3fSCTSygbzJqX81v2p0W4Jo4nFhgubdXB0MKGTy 9OcVMF96yZB5ErgA+OWacXoo7pjfk4LiEqfleo7vnsOKM3Ceyw2naeAFJfuc3SJxJdTb WwKdoHi1h//C2zdRsmtn/35K7ZFEkzF8YL3zQHbqnhZHT/F/2v/0GE0ACcxd9NJhjwPI UREIsgnLTx+5BwAe+YdvzTBBi3rSPrsf2VyHlrtCcEkveWY5vvGT4PPKZ0pnYB6Sm2G6 EgduvPizrqY/E8vDpPTzZX2t5YsykLk2p7ngCCLxEHsFD6uhKmBMXuKymy2e4dFUXon3 yvCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685967561; x=1688559561; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=z+w1EIm+JkVk3uX1q6j1vUHiTmy2iURlBZ4bKKFARlQ=; b=MgVx1Tiy4Osaf75Suvdkm88F5Sk4APgyTwu9vD31rsxv/l58SLzmf3aasyoD3jDktd dXXJDOaxvDXnr9zwptFuDj4PgVfThnR8TeN6g1dL5eMhA7gnYYoGpVntkFMmtZgSmnl5 fPKxIU3TknrF6I6F8HRdlxkJSdBRyJ/bBCYCVrH7w+OLlp4HlwqoAU2nq5xJdmrtEK6k J5fxhPf4BZMAUdNpiRxfwq5NCGQBReyP7OrdgV+3bNkxVsFgXB2aFjHxrviDG6Mx0dYU nSz2yfO12trW1LUUaX3P/WXKd3Yr2bEiUCgfZL1OOHQQkuk/hxNy+lx3vL/5w8BWZoZK q8gw== X-Gm-Message-State: AC+VfDyuZZ1u6lGxwKyoM810q1Gs3ZuL+HrojX+P0N3jbeDjdLtSPmt0 RmZRnw83G6E9S6bS//H2WkeTDiiHDwu92Q== X-Google-Smtp-Source: ACHHUZ4GCUMYxyCoJFUY6clpMGmOXia94OJB+9dbPA0Ii3z9yEbPHQM658Ky6q0g3AelnDLpO5ZN9g== X-Received: by 2002:a7b:cd96:0:b0:3f7:7211:5317 with SMTP id y22-20020a7bcd96000000b003f772115317mr2232094wmj.31.1685967560893; Mon, 05 Jun 2023 05:19:20 -0700 (PDT) Received: from localhost ([37.46.46.3]) by smtp.gmail.com with ESMTPSA id 8-20020a05600c230800b003f6cf9afc25sm14374718wmo.40.2023.06.05.05.19.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jun 2023 05:19:20 -0700 (PDT) From: Efraim Flashner Date: Mon, 5 Jun 2023 15:19:24 +0300 Message-Id: <29f421343373bc3655abb9961f254880a295f6f7.1685967547.git.efraim@flashner.co.il> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=efraim.flashner@gmail.com; helo=mail-wm1-x329.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/home/services/shells.scm (home-inputrc-service-type, home-inputrc-configuration): New variables. (serialize-inputrc-key-bindings, serialize-inputrc-variables, serialize-inputrc-conditional-constructs, serialize-inputrc-extra-content, generate-home-inputrc-documentation): New procedures. --- gnu/home/services/shells.scm | 145 ++++++++++++++++++++++++++++++++++- 1 file changed, 144 insertions(+), 1 deletion(-) base-commit: 940665301de4effd065d24c167f619286f2adf4c diff --git a/gnu/home/services/shells.scm b/gnu/home/services/shells.scm index f05f2221d6..bc3daf7a21 100644 --- a/gnu/home/services/shells.scm +++ b/gnu/home/services/shells.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2021 Andrew Tropin ;;; Copyright © 2021 Xinglu Chen +;;; Copyright © 2023 Efraim Flashner ;;; ;;; This file is part of GNU Guix. ;;; @@ -44,7 +45,10 @@ (define-module (gnu home services shells) home-fish-service-type home-fish-configuration - home-fish-extension)) + home-fish-extension + + home-inputrc-service-type + home-inputrc-configuration)) ;;; Commentary: ;;; @@ -626,6 +630,138 @@ (define home-fish-service-type (description "\ Install and configure Fish, the friendly interactive shell."))) + +;;; +;;; Readline. +;;; + +(define (serialize-inputrc-key-bindings field-name val) + #~(string-append + #$@(map + (match-lambda + ((key . value) + #~(string-append #$key ": " #$value "\n"))) + val))) + +(define (serialize-inputrc-variables field-name val) + #~(string-append + #$@(map + (match-lambda + ((key . #f) + #~(string-append "set " #$key " off\n")) + ((key . #t) + #~(string-append "set " #$key " on\n")) + ((key . value) + #~(string-append "set " #$key " " #$value "\n"))) + val))) + +(define (serialize-inputrc-conditional-constructs field-name val) + #~(string-append + #$@(map + (match-lambda + (("$endif" . _) + "$endif\n") + (("$include" . value) + #~(string-append "$include " #$value "\n")) + ;; TODO: key can only be "$if" or "$else". + ((key . value) + #~(string-append #$key "\n" + #$(serialize-configuration + value + home-inputrc-configuration-fields)))) + val))) + +(define (serialize-inputrc-extra-content field-name value) + #~(if (string=? #$value "") "" (string-append #$value "\n"))) + +(define-configuration home-inputrc-configuration + (key-bindings + (alist '()) + "Association list of readline key bindings to be added to the @code{.inputrc} +file. This is where code like this: + +@lisp +'((\"Control-l\" . \"clear-screen\")) +@end lisp + +turns into + +@example +Control-l: clear-screen +@end example" + (serializer serialize-inputrc-key-bindings)) + (variables + (alist '()) + "Association list of readline variables to set. This is where configuration +options like this: + +@lisp +'((\"bell-style\" . \"visible\") + (\"colored-completion-prefix\" . #t)) +@end lisp + +turns into + +@example +set bell-style visible +set colored-completion-prefix on +@end example" + (serializer serialize-inputrc-variables)) + (conditional-constructs + (alist '()) + "Association list of conditionals to add to the intialization file. This +includes @command{$if}, @command{else}, @command{endif} and @{include} and they +receive a value of another @command{home-inputrc-configuration}. + +@lisp +(conditional-constructs + `((\"$if mode=vi\" . + ,(home-inputrc-configuration + (variables + `((\"show-mode-in-prompt\" . #t))))) + (\"$else\" . + ,(home-inputrc-configuration + (key-bindings + `((\"Control-l\" . \"clear-screen\"))))) + (\"$endif\" . #t))) +@end lisp + +turns into + +@example +$if mode=vi +set show-mode-in-prompt on +$else +Control-l: clear-screen +$endif +@end example" + (serializer serialize-inputrc-conditional-constructs)) + (extra-content + (string "") + "Extra content appended as-is to the configuration file. Run @command{man +readline} for more information about all the configuration options." + (serializer serialize-inputrc-extra-content))) + +(define (home-inputrc-files config) + (list + `(".inputrc" + ,(mixed-text-file "inputrc" + (serialize-configuration + config + home-inputrc-configuration-fields))))) + +(define home-inputrc-service-type + (service-type (name 'inputrc) + (extensions + (list (service-extension home-files-service-type + home-inputrc-files))) + (default-value (home-inputrc-configuration)) + (description "Configure readline in @code{.inputrc}."))) + + +;;; +;;; Documentation. +;;; (define (generate-home-shell-profile-documentation) (generate-documentation @@ -662,3 +798,10 @@ (define (generate-home-fish-documentation) `((home-fish-extension ,home-fish-extension-fields)) 'home-fish-extension))) + +(define (generate-home-inputrc-documentation) + (string-append + (generate-documentation + `((home-inputrc-configuration + ,home-inputrc-configuration-fields)) + 'home-inputrc-configuration)))