From mboxrd@z Thu Jan 1 00:00:00 1970 From: Roel Janssen Subject: [PATCH] environment: Add a prompt-name argument. Date: Thu, 20 Oct 2016 13:09:45 +0200 Message-ID: <87lgxjp98m.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54396) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxBDA-000443-HE for guix-devel@gnu.org; Thu, 20 Oct 2016 07:08:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bxBD5-00012l-Bq for guix-devel@gnu.org; Thu, 20 Oct 2016 07:08:36 -0400 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:43214) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxBD5-00012h-8I for guix-devel@gnu.org; Thu, 20 Oct 2016 07:08:31 -0400 Received: from [143.121.198.169] (port=58830 helo=roel-tp) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1bxBD4-0004Kp-CH for guix-devel@gnu.org; Thu, 20 Oct 2016 07:08:30 -0400 List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: guix-devel@gnu.org Dear Guix, Having multiple virtual terminals open, each running in their own environment created with @code{guix environment} can become confusing to the user. Therefore, I would like to add an option to pass a name to the shell prompt. Currently we default to "[env]". This patch adds a -p and --prompt-name argument to @code{guix environment}, and puts the argument's value between the square brackets instead of "env". Examples: [roel@hostname guix]$ guix environment --container --prompt-name="guile" guile roel@hostname ~/sources/guix [guile]# [roel@hostname guix]$ guix environment --container -p "guile" guile roel@hostname ~/sources/guix [guile]# [roel@hostname guix]$ guix environment --container guile roel@hostname ~/sources/guix [env]# Now, I don't know what the correct naming for the argument is (prompt-name). So, I have two questions: 0. Do you think we should apply this patch? 1. What name should the argument have? Kind regards, Roel Janssen >From ea958e847019c94a2bde49285f1436dfec72e570 Mon Sep 17 00:00:00 2001 From: Roel Janssen Date: Thu, 20 Oct 2016 13:07:15 +0200 Subject: [PATCH] environment: Add a prompt-name argument. * guix/scripts/environment.scm: Add --prompt-name (-p) argument. --- guix/scripts/environment.scm | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index 0c69bfc..e36c97e 100644 --- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm @@ -149,6 +149,8 @@ COMMAND or an interactive shell in that environment.\n")) --ad-hoc include all specified packages in the environment instead of only their inputs")) (display (_ " + -p, --prompt-name use PROMPT-NAME in the command prompt of the environment")) + (display (_ " --pure unset existing environment variables")) (display (_ " --search-paths display needed environment variable definitions")) @@ -237,6 +239,9 @@ COMMAND or an interactive shell in that environment.\n")) (option '(#\N "network") #f #f (lambda (opt name arg result) (alist-cons 'network? #t result))) + (option '(#\p "prompt-name") #t #f + (lambda (opt name arg result) + (alist-cons 'prompt-name arg result))) (option '("share") #t #f (lambda (opt name arg result) (alist-cons 'file-system-mapping @@ -376,7 +381,7 @@ environment variables are cleared before setting the new ones." ((_ . status) status))))) (define* (launch-environment/container #:key command bash user-mappings - profile paths network?) + profile paths network? prompt-name) "Run COMMAND within a container that features the software in PROFILE. Environment variables are set according to PATHS, a list of native search paths. The global shell is BASH, a file name for a GNU Bash binary in the @@ -434,7 +439,11 @@ host file systems to mount inside the container." (symlink bash "/bin/sh") ;; Set a reasonable default PS1. - (setenv "PS1" "\\u@\\h \\w [env]\\$ ") + (setenv "PS1" (string-append "\\u@\\h \\w [" + (if (not prompt-name) + "env" + prompt-name) + "]\\$ ")) ;; Setup directory for temporary files. (mkdir-p "/tmp") @@ -525,13 +534,14 @@ message if any test fails." ;; Entry point. (define (guix-environment . args) (with-error-handling - (let* ((opts (parse-args args)) - (pure? (assoc-ref opts 'pure)) - (container? (assoc-ref opts 'container?)) - (network? (assoc-ref opts 'network?)) - (bootstrap? (assoc-ref opts 'bootstrap?)) - (system (assoc-ref opts 'system)) - (command (or (assoc-ref opts 'exec) + (let* ((opts (parse-args args)) + (pure? (assoc-ref opts 'pure)) + (container? (assoc-ref opts 'container?)) + (network? (assoc-ref opts 'network?)) + (prompt-name (assoc-ref opts 'prompt-name)) + (bootstrap? (assoc-ref opts 'bootstrap?)) + (system (assoc-ref opts 'system)) + (command (or (assoc-ref opts 'exec) ;; Spawn a shell if the user didn't specify ;; anything in particular. (if container? @@ -604,6 +614,7 @@ message if any test fails." #:user-mappings mappings #:profile profile #:paths paths + #:prompt-name prompt-name #:network? network?))) (else (return -- 2.10.0