From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id mAqzIpM6hWEeQQAAgWs5BA (envelope-from ) for ; Fri, 05 Nov 2021 15:07:15 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id 6PxbHpM6hWGMMQAAB5/wlQ (envelope-from ) for ; Fri, 05 Nov 2021 14:07:15 +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 25FCB1BCF for ; Fri, 5 Nov 2021 15:07:15 +0100 (CET) Received: from localhost ([::1]:44726 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mizsA-0003vG-95 for larch@yhetil.org; Fri, 05 Nov 2021 10:07:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35668) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mizp4-0006LK-FP for guix-patches@gnu.org; Fri, 05 Nov 2021 10:04:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:35171) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mizp4-0006b8-6q for guix-patches@gnu.org; Fri, 05 Nov 2021 10:04:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mizp4-0007Ng-3A for guix-patches@gnu.org; Fri, 05 Nov 2021 10:04:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#51543] [PATCH 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: Fri, 05 Nov 2021 14:04: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.163612100728309 (code B ref 51543); Fri, 05 Nov 2021 14:04:02 +0000 Received: (at 51543) by debbugs.gnu.org; 5 Nov 2021 14:03:27 +0000 Received: from localhost ([127.0.0.1]:46713 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mizoU-0007MW-Nh for submit@debbugs.gnu.org; Fri, 05 Nov 2021 10:03:27 -0400 Received: from h87-96-130-155.cust.a3fiber.se ([87.96.130.155]:33854 helo=mail.yoctocell.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mizoL-0007Lz-46 for 51543@debbugs.gnu.org; Fri, 05 Nov 2021 10:03:25 -0400 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yoctocell.xyz; s=mail; t=1636120991; bh=iBLwIFgOsXIxcoZJgOGwguU56vQ4c0+RqPlbomA23A4=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=iriNTP4d1MjMazcg+RPCGe2AJsJhuVUnxS6OsZyxZi9x+4tzDFGPuxbKstNXUPqB3 7dH9w4bx24Y9RdOw8wdUmBxptpqt1Att0NQb2gqHLAc+63NLHU6BjkcfdrxOOGRjX9 bKNbPHbTWyYMlDMjuY6+rSo7hpJU5+BIeVFHv9P8= In-Reply-To: References: Message-Id: Date: Fri, 05 Nov 2021 15:03:11 +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=1636121235; 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=AWiSqActLq9usrEqT4GhD0nKc7t89fYxqloLgi+h3qWRvN1Di2RfYJVfjQnKCnNzWXchBP CdeeG1CzxXHNN1/3Qs3+ceT5cXYPRvpYtzOfaDiw8EUu9G7Yv1Q9QmO3GustmE9WcomK16 KQxlMr5fAvoLkxectxLW+8W3bemjdpcSax8Y0hqUhfPzV32dqi+WTYsLQ1Jefp2JLFYEvE TM5mm3pOCQhVL+xKntQECPFyXhblnIh9y6RxEOXA+p5ps76rvheccfikFaAjrFxyBDI9zV qVg19i6CEtcqBYF/80KI3v146bFb9vdLYuHu6XAjGn5co7HvCjeG7X4QwLRnIg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1636121235; a=rsa-sha256; cv=none; b=p5dbnlq2X2o8Ga/BX5HxoApa3DfH3wST7TVip7c0e3BXVi3WjmGyF4iUPmNG4NDl91u430 ofTw6Hj5wQAkNrVDoEVNivXnGnwEK+CMVgxHY3UjmfIpYfxUkIx4qgQlHXxtnMUjM6sTds GTQBdd38cSCzzzmp1FmcZ1Sbc5s12cQGRGApWy9JSEjyd19s4C4rSut8KSq5zlj7vkdtmC rd4ntLVrWg3DNwlSpIdbv2v4zVkTJFOZy9f2aIj5nJmUqAr3CChKDiZlx0xTXptREnW9VJ x6yIOSPVT0ooZtQYaKSy2GiQdNV/O53jhEG94JTYq/W8eqd2/8BdWPdW5J4X6A== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=yoctocell.xyz header.s=mail header.b=iriNTP4d; 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=iriNTP4d; 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: 25FCB1BCF X-Spam-Score: -0.32 X-Migadu-Scanner: scn0.migadu.com X-TUID: H4LNBe9OAgTm * 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