From: Efraim Flashner <efraim@flashner.co.il>
To: 63909@debbugs.gnu.org
Cc: "Efraim Flashner" <efraim@flashner.co.il>
Subject: [bug#63909] [PATCH] home: Add inputrc service.
Date: Mon, 5 Jun 2023 15:19:24 +0300 [thread overview]
Message-ID: <29f421343373bc3655abb9961f254880a295f6f7.1685967547.git.efraim@flashner.co.il> (raw)
* 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(-)
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 <andrew@trop.in>
;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
+;;; Copyright © 2023 Efraim Flashner <efraim@flashner.co.il>
;;;
;;; 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.")))
+\f
+;;;
+;;; 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}.")))
+
+\f
+;;;
+;;; 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)))
base-commit: 940665301de4effd065d24c167f619286f2adf4c
--
Efraim Flashner <efraim@flashner.co.il> רנשלפ םירפא
GPG key = A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted
next reply other threads:[~2023-06-05 12:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-05 12:19 Efraim Flashner [this message]
2023-06-16 13:40 ` [bug#63909] [PATCH] home: Add inputrc service Ludovic Courtès
2023-06-18 8:49 ` [bug#63909] [PATCH v2] " Efraim Flashner
[not found] ` <handler.64148.B.168707819619994.ack@debbugs.gnu.org>
2023-07-06 13:21 ` bug#63909: bug#64148: Acknowledgement ([PATCH v2] home: Add inputrc service.) Efraim Flashner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=29f421343373bc3655abb9961f254880a295f6f7.1685967547.git.efraim@flashner.co.il \
--to=efraim@flashner.co.il \
--cc=63909@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
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).