From: "Ludovic Courtès" <ludo@gnu.org>
To: 51285@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>
Subject: [bug#51285] [PATCH 3/3] shell: Suggest running '--check' once for interactive use.
Date: Tue, 19 Oct 2021 12:13:11 +0200 [thread overview]
Message-ID: <20211019101311.10174-3-ludo@gnu.org> (raw)
In-Reply-To: <20211019101311.10174-1-ludo@gnu.org>
* guix/scripts/shell.scm (hint-directory, hint-file, record-hint)
(hint-given?): New procedures.
(guix-shell): Record and probe the 'shell-check' hint.
---
guix/scripts/shell.scm | 41 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 40 insertions(+), 1 deletion(-)
diff --git a/guix/scripts/shell.scm b/guix/scripts/shell.scm
index 4062e8155d..43e8484333 100644
--- a/guix/scripts/shell.scm
+++ b/guix/scripts/shell.scm
@@ -331,6 +331,30 @@ (define (profile-cached-gc-root file)
(#f #f)
(key (string-append (%profile-cache-directory) "/" key))))
+\f
+;;;
+;;; One-time hints.
+;;;
+
+(define (hint-directory)
+ "Return the directory name where previously given hints are recorded."
+ (let ((directory (string-append (cache-directory #:ensure? #f)
+ "/hints")))
+ (mkdir-p directory)
+ directory))
+
+(define (hint-file hint)
+ "Return the name of the file that marks HINT as already printed."
+ (string-append (hint-directory) "/" (symbol->string hint)))
+
+(define (record-hint hint)
+ "Mark HINT as already given."
+ (close-port (open-file (hint-file hint) "w")))
+
+(define (hint-given? hint)
+ "Return true if HINT was already given."
+ (file-exists? (hint-file hint)))
+
\f
(define-command (guix-shell . args)
(category development)
@@ -348,7 +372,22 @@ (define* (entry-expiration file)
(#f 0) ;FILE may have been deleted in the meantime
(st (+ (stat:atime st) (* 60 60 24 7)))))
- (let ((result (guix-environment* (parse-args args))))
+ (define opts
+ (parse-args args))
+
+ (define interactive?
+ (not (assoc-ref opts 'exec)))
+
+ (if (assoc-ref opts 'check?)
+ (record-hint 'shell-check)
+ (when (and interactive?
+ (not (hint-given? 'shell-check))
+ (not (assoc-ref opts 'container?))
+ (not (assoc-ref opts 'search-paths)))
+ (display-hint (G_ "Consider passing the @option{--check} option once
+to make sure your shell does not clobber environment variables."))) )
+
+ (let ((result (guix-environment* opts)))
(maybe-remove-expired-cache-entries (%profile-cache-directory)
cache-entries
#:entry-expiration entry-expiration)
--
2.33.0
next prev parent reply other threads:[~2021-10-19 10:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-19 10:03 [bug#51285] [PATCH 0/3] Add 'guix shell --check' Ludovic Courtès
2021-10-19 10:13 ` [bug#51285] [PATCH 1/3] syscalls: Add 'openpty' and 'login-tty' Ludovic Courtès
2021-10-19 10:13 ` [bug#51285] [PATCH 2/3] environment: Add '--check' Ludovic Courtès
2021-10-19 10:13 ` Ludovic Courtès [this message]
2021-10-26 10:48 ` bug#51285: [PATCH 0/3] Add 'guix shell --check' Ludovic Courtès
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=20211019101311.10174-3-ludo@gnu.org \
--to=ludo@gnu.org \
--cc=51285@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).