From: Cyril Roelandt <tipecaml@gmail.com>
To: guix-devel@gnu.org
Subject: [PATCH] guix environment: add a '--env-name' option
Date: Wed, 24 Jun 2015 23:41:34 +0200 [thread overview]
Message-ID: <1435182094-13537-1-git-send-email-tipecaml@gmail.com> (raw)
* guix/scripts/environment.scm: add a '--env-name' option.
---
guix/scripts/environment.scm | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm
index 007fde1..1d078ce 100644
--- a/guix/scripts/environment.scm
+++ b/guix/scripts/environment.scm
@@ -30,6 +30,7 @@
#:use-module (gnu packages)
#:use-module (ice-9 format)
#:use-module (ice-9 match)
+ #:use-module (rnrs io ports)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
#:use-module (srfi srfi-37)
@@ -106,6 +107,8 @@ shell command in that environment.\n"))
--ad-hoc include all specified packages in the environment instead
of only their inputs"))
(display (_ "
+ --env-name name of the environment, used in the prompt"))
+ (display (_ "
--pure unset existing environment variables"))
(display (_ "
--search-paths display needed environment variable definitions"))
@@ -124,6 +127,7 @@ shell command in that environment.\n"))
`((exec . ,(or (getenv "SHELL") "/bin/sh"))
(substitutes? . #t)
(max-silent-time . 3600)
+ (env-name . "guix-env")
(verbosity . 0)))
(define %options
@@ -153,6 +157,9 @@ shell command in that environment.\n"))
(option '("ad-hoc") #f #f
(lambda (opt name arg result)
(alist-cons 'ad-hoc? #t result)))
+ (option '("env-name") #t #f
+ (lambda (opt name arg result)
+ (alist-cons 'env-name arg result)))
(option '(#\n "dry-run") #f #f
(lambda (opt name arg result)
(alist-cons 'dry-run? #t result)))
@@ -226,6 +233,20 @@ packages."
(built-derivations drvs)
(return drvs)))))))
+(define (run-shell shell env-name)
+ "Run the given SHELL, adding '(ENV-NAME) ' at the start of the prompt."
+ (cond ((string=? shell "/bin/bash")
+ (let* ((directory (or (getenv "TMPDIR") "/tmp"))
+ (template (string-append directory "/guix-file.XXXXXX"))
+ (out (mkstemp! template)))
+ (format out "export PS1=\"(~a) $PS1\"" env-name)
+ (flush-output-port out)
+ (system (string-append "/bin/bash --rcfile " template))))
+ (else
+ (begin
+ (warning (_ "Unknown shell, will not update the prompt"))
+ (system shell)))))
+
;; Entry point.
(define (guix-environment . args)
(define (handle-argument arg result)
@@ -237,6 +258,7 @@ packages."
(pure? (assoc-ref opts 'pure))
(ad-hoc? (assoc-ref opts 'ad-hoc?))
(command (assoc-ref opts 'exec))
+ (env-name (assoc-ref opts 'env-name))
(packages (pick-all (options/resolve-packages opts) 'package))
(inputs (if ad-hoc?
(packages+propagated-inputs packages)
@@ -254,4 +276,6 @@ packages."
(show-search-paths inputs drvs pure?))
(else
(create-environment inputs drvs pure?)
- (system command)))))))
+ (if (string=? command (assoc-ref %default-options 'exec))
+ (run-shell command env-name)
+ (system command))))))))
--
1.8.4.rc3
next reply other threads:[~2015-06-24 21:41 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-24 21:41 Cyril Roelandt [this message]
2015-06-25 11:45 ` guix environment & PS1 Ludovic Courtès
2015-06-25 12:02 ` Ricardo Wurmus
2015-06-25 13:04 ` Thompson, David
2015-06-25 13:28 ` Ricardo Wurmus
2015-06-25 20:00 ` Claes Wallin (韋嘉誠)
2015-06-25 20:40 ` Claes Wallin (韋嘉誠)
2015-06-29 8:41 ` Ludovic Courtès
2015-06-29 10:04 ` Claes Wallin (韋嘉誠)
2015-06-25 13:02 ` Thompson, David
2015-07-01 13:10 ` Ludovic Courtès
2015-07-01 13:59 ` Thompson, David
2015-07-01 17:07 ` Claes Wallin (韋嘉誠)
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=1435182094-13537-1-git-send-email-tipecaml@gmail.com \
--to=tipecaml@gmail.com \
--cc=guix-devel@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).