From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id zt1lK3m6h2EC2gAAgWs5BA (envelope-from ) for ; Sun, 07 Nov 2021 12:37:29 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id Hyg/Jnm6h2ExdwAAbx9fmQ (envelope-from ) for ; Sun, 07 Nov 2021 11:37:29 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 19A7D11A50 for ; Sun, 7 Nov 2021 12:37:29 +0100 (CET) Received: from localhost ([::1]:49632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mjgUK-0001b9-AZ for larch@yhetil.org; Sun, 07 Nov 2021 06:37:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57548) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mjgTw-0001ZL-BR for guix-patches@gnu.org; Sun, 07 Nov 2021 06:37:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:40399) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mjgTu-00063p-KV for guix-patches@gnu.org; Sun, 07 Nov 2021 06:37:04 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mjgTu-0004X7-Hs for guix-patches@gnu.org; Sun, 07 Nov 2021 06:37:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51543] [PATCH v3 1/2] home: services: bash: Add =?UTF-8?Q?=E2=80=98aliases=E2=80=99?= field. Resent-From: Xinglu Chen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 07 Nov 2021 11:37:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51543 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 51543@debbugs.gnu.org Cc: Liliana Marie Prikler Received: via spool by 51543-submit@debbugs.gnu.org id=B51543.163628498717356 (code B ref 51543); Sun, 07 Nov 2021 11:37:02 +0000 Received: (at 51543) by debbugs.gnu.org; 7 Nov 2021 11:36:27 +0000 Received: from localhost ([127.0.0.1]:51941 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mjgTL-0004Vr-0X for submit@debbugs.gnu.org; Sun, 07 Nov 2021 06:36:27 -0500 Received: from h87-96-130-155.cust.a3fiber.se ([87.96.130.155]:49744 helo=mail.yoctocell.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mjgTJ-0004VT-JR for 51543@debbugs.gnu.org; Sun, 07 Nov 2021 06:36:26 -0500 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yoctocell.xyz; s=mail; t=1636284980; bh=iBLwIFgOsXIxcoZJgOGwguU56vQ4c0+RqPlbomA23A4=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=DoM74FXYTAi/eovNVYdFAGKwXFZcZgvgRaPVIni80Nbnty3EkvsgmFbcUXbykimiD 7eYoz5+eYuYXLXhhc/tE4Bkl4eLZu9yBVnpoo/N/QZ0foPBg7hdm9PV2PfNofvwRZw V0oo4nLlUkUx4Pl0nti33ZvcLFQjD57eIgybgqVs= In-Reply-To: References: Message-Id: <3a13e86e446d35aa456da06750ad658ba49fd48b.1636284793.git.public@yoctocell.xyz> Date: Sun, 07 Nov 2021 12:36:19 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1636285049; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=tVd/huopkG/sjCRwdzhpd5pCnWgQsUtO9OiazDu1unU=; b=bTtr1gAplc+Jt4rLHhLxfWLYEo9QPNq8WkoRy6rDZ3TXuuoAaMmlUpKrQ/Iqvt/tO2W/Xt ZXajxYOdABut3J8XUlWjp7YTrFv0mVo50WXNhXb2unRsfkre1CDsxEcKD3iMqmjYu/jhgh P6pxUo4GXY/0dUd8oMyYxHRvQqfNfBvR+xE8jvTLvCEgZSchEendVn/9bzWIVzIxxTCr3K wHaux45mG2SROZyInvpHjgnmC2qj9Exh+hj5lEc7If0z9l6hA+bhwDIewS58mHiZ5LOQX0 qO50tfd2+54VuFYQ+wPuR7aER36X8lIOkAjUlDxFtsGcdMCahaK81G7LbSzZ4Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1636285049; a=rsa-sha256; cv=none; b=UQOrkKlbbhNk9PSS8CziRo+2cmJhS+etK8hHsPoX7llG6MC1l0xIY/YJjJJ5WQOknIsCBx ajZ1IXo+CYGXFlfesEPs5ZrKe52TNMqzOUtF9Z6P7tBHKClstL/9DO2zfvIM13M/z9aucc eMqUd7J0Q1AhuQrbqTLkss4PSNhqfRv3mWP4D9gl9tAymPfpt907v7fZ7ozerPjTGQSUFr OPeKKCCmqKqfr6+CHrHZA+ph+xBqoSHYWOQCHa+j+N4LDoPF2nHnLg7h9ekDZ12BTEOEaz ptgY6+Pb/knTFZxrjZNv7Ak4araCZrYK96+6+dEXz+MoPnzdN5KCK+oI0JRC8A== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=yoctocell.xyz header.s=mail header.b=DoM74FXY; dmarc=fail reason="SPF not aligned (relaxed)" header.from=yoctocell.xyz (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -0.32 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=yoctocell.xyz header.s=mail header.b=DoM74FXY; dmarc=fail reason="SPF not aligned (relaxed)" header.from=yoctocell.xyz (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 19A7D11A50 X-Spam-Score: -0.32 X-Migadu-Scanner: scn0.migadu.com X-TUID: MllKwVNngH5E * doc/guix.texi (Shells Home Services): Document it. * gnu/home/services/shells.scm (bash-serialize-aliases): New procedure. (home-bash-configuration, home-bash-extension): Add =E2=80=98aliases=E2=80= =99 field. (home-bash-extensions): Adjust accordingly. * guix/scripts/home/import.scm (generate-bash-configuration+modules): Popul= ate the =E2=80=98alias=E2=80=99 field. --- doc/guix.texi | 14 ++++++ gnu/home/services/shells.scm | 83 ++++++++++++++++++++++++++---------- guix/scripts/home/import.scm | 24 +++++++++++ 3 files changed, 98 insertions(+), 23 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index ea1973f02c..f7312a5b30 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -36173,6 +36173,20 @@ @item @code{environment-variables} (default: @code{()}) (type: alist) Association list of environment variables to set for the Bash session. =20 +@item @code{aliases} (default: @code{()}) (type: alist) +Association list of aliases to set for the Bash session. The alias will +automatically be quoted, so something line this: + +@lisp +'((\"ls\" . \"ls -alF\")) +@end lisp + +turns into + +@example +alias ls=3D\"ls -alF\" +@end example + @item @code{bash-profile} (default: @code{()}) (type: text-config) List of file-like objects, which will be added to @file{.bash_profile}. Used for executing user's commands at start of login shell (In most diff --git a/gnu/home/services/shells.scm b/gnu/home/services/shells.scm index e2730967b2..f24e47f762 100644 --- a/gnu/home/services/shells.scm +++ b/gnu/home/services/shells.scm @@ -305,6 +305,18 @@ (define home-zsh-service-type ;;; Bash. ;;; =20 +(define (bash-serialize-aliases field-name val) + #~(string-append + #$@(map + (match-lambda + ((key . #f) + "") + ((key . #t) + #~(string-append "alias " #$key "\n")) + ((key . value) + #~(string-append "alias " #$key "=3D\"" #$value "\"\n"))) + val))) + (define-configuration home-bash-configuration (package (package bash) @@ -317,6 +329,21 @@ (define-configuration home-bash-configuration (alist '()) "Association list of environment variables to set for the Bash session." serialize-posix-env-vars) + (aliases + (alist '()) + "Association list of aliases to set for the Bash session. The alias wi= ll +automatically be quoted, so something line this: + +@lisp +'((\"ls\" . \"ls -alF\")) +@end lisp + +turns into + +@example +alias ls=3D\"ls -alF\" +@end example" + bash-serialize-aliases) (bash-profile (text-config '()) "List of file-like objects, which will be added to @file{.bash_profile}. @@ -387,10 +414,10 @@ (define* (file-if-not-empty field #:optional (extra-c= ontent #f)) (if (or extra-content (not (null? ((configuration-field-getter field-obj) config))= )) `(,(object->snake-case-string file-name) - ,(mixed-text-file + ,(apply mixed-text-file (object->snake-case-string file-name) - (if extra-content extra-content "") - (serialize-field field))) + (cons (serialize-field field) + (if extra-content extra-content '())))) '()))) =20 (filter @@ -413,8 +440,8 @@ (define* (file-if-not-empty field #:optional (extra-con= tent #f)) ,@(list (file-if-not-empty 'bashrc (if (home-bash-configuration-guix-defaults? config) - guix-bashrc - #f)) + (list (serialize-field 'aliases) guix-bashrc) + (list (serialize-field 'alises)))) (file-if-not-empty 'bash-logout))))) =20 (define (add-bash-packages config) @@ -424,6 +451,9 @@ (define-configuration/no-serialization home-bash-extens= ion (environment-variables (alist '()) "Association list of environment variables to set.") + (aliases + (alist '()) + "Association list of aliases to set.") (bash-profile (text-config '()) "List of file-like objects.") @@ -435,24 +465,31 @@ (define-configuration/no-serialization home-bash-exte= nsion "List of file-like objects.")) =20 (define (home-bash-extensions original-config extension-configs) - (home-bash-configuration - (inherit original-config) - (environment-variables - (append (home-bash-configuration-environment-variables original-config) - (append-map - home-bash-extension-environment-variables extension-configs))) - (bash-profile - (append (home-bash-configuration-bash-profile original-config) - (append-map - home-bash-extension-bash-profile extension-configs))) - (bashrc - (append (home-bash-configuration-bashrc original-config) - (append-map - home-bash-extension-bashrc extension-configs))) - (bash-logout - (append (home-bash-configuration-bash-logout original-config) - (append-map - home-bash-extension-bash-logout extension-configs))))) + (match original-config + (($ _ _ _ environment-variables aliases + bash-profile bashrc bash-logout) + (home-bash-configuration + (inherit original-config) + (environment-variables + (append environment-variables + (append-map + home-bash-extension-environment-variables extension-config= s))) + (aliases + (append aliases + (append-map + home-bash-extension-aliases extension-configs))) + (bash-profile + (append bash-profile + (append-map + home-bash-extension-bash-profile extension-configs))) + (bashrc + (append bashrc + (append-map + home-bash-extension-bashrc extension-configs))) + (bash-logout + (append bash-logout + (append-map + home-bash-extension-bash-logout extension-configs))))))) =20 (define home-bash-service-type (service-type (name 'home-bash) diff --git a/guix/scripts/home/import.scm b/guix/scripts/home/import.scm index 7a7712dd96..fbf89069a7 100644 --- a/guix/scripts/home/import.scm +++ b/guix/scripts/home/import.scm @@ -27,6 +27,9 @@ (define-module (guix scripts home import) #:use-module (gnu packages) #:use-module (ice-9 match) #:use-module (ice-9 pretty-print) + #:use-module (ice-9 rdelim) + #:use-module (ice-9 regex) + #:use-module (ice-9 popen) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) #:export (import-manifest @@ -56,11 +59,32 @@ (define (generate-bash-configuration+modules destinatio= n-directory) (define (destination-append path) (string-append destination-directory "/" path)) =20 + (define (bash-alias->pair line) + (if (string-prefix? "alias" line) + (let ((matched (string-match "alias (.+)=3D\"?'?([^\"']+)\"?'?" li= ne))) + `(,(match:substring matched 1) . ,(match:substring matched 2))) + '())) +=20=20 + (define (parse-aliases input) + (let loop ((line (read-line input)) + (result '())) + (if (eof-object? line) + (reverse result) + (loop (read-line input) + (cons (bash-alias->pair line) result))))) + (let ((rc (destination-append ".bashrc")) (profile (destination-append ".bash_profile")) (logout (destination-append ".bash_logout"))) `((service home-bash-service-type (home-bash-configuration + ,@(if (file-exists? rc) + `((aliases + ',(let* ((port (open-pipe* OPEN_READ "bash" "-i" = "-c" "alias")) + (alist (parse-aliases port))) + (close-port port) + (filter (negate null?) alist)))) + '()) ,@(if (file-exists? rc) `((bashrc (list (local-file ,rc --=20 2.33.0