unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Bengt Richter <bokr@bokr.com>
To: zimoun <zimon.toutoune@gmail.com>
Cc: jgart <jgart@dismail.de>, "Tobias Geerinckx-Rice" <me@tobias.gr>,
	guix-devel@gnu.org, "Ludovic Courtès" <ludo@gnu.org>
Subject: Re: repl macro (metacommand?) for guix CLI (sub)commands
Date: Sat, 16 Jul 2022 21:08:31 +0200	[thread overview]
Message-ID: <20220716190831.GA5993@LionPure> (raw)
In-Reply-To: <875ykaz9ca.fsf@gmail.com>

Hi Simon,

On +2022-07-06 14:58:29 +0200, zimoun wrote:
> Hi,
> 
> On mer., 06 juil. 2022 at 14:13, bokr@bokr.com wrote:
> 
> > [13:23 ~/bs]$ guile --no-auto-compile -c '(display (getenv "PS1"))(newline)'
> > [\A \w]\$ 
> 
> On my machine, all is as usual and I run Bash:
> 
> --8<---------------cut here---------------start------------->8---
> $ echo $PS1
> \n\w/\n\u@\h$
> $ guile --no-auto-compile -c '(display (getenv "PS1"))(newline)'
> #f
> --8<---------------cut here---------------end--------------->8---
> 
> Maybe I miss something.   Thanks for giving a try.
> 
> 
> Cheers,
> simon
>

Hm, I see that on my system, I don't get #f from guile like you
--8<---------------cut here---------------start------------->8---
$ echo $PS1
[\A \w]\$
$ guile --no-auto-compile -c '(display (getenv "PS1"))(newline)'
[\A \w]\$ 
--8<---------------cut here---------------end--------------->8---

so I'm not sure what is the difference ;/

Since I was getting PS1 from a bash invocation of guile, I was had
a different impression from yours of reality ;-)

So I went looking for a context where invoking something would NOT see PS1 :)

I found that a nested call of a bash script did not see PS1 unless invoked by sourcing.
(Of course I can't source the guile I access with "guile" as a bash command, since it's
a binary.) But IIRC guile under guix is actually a wrapper script to set up the environment,
so maybe you could on your system -- I've no idea what would happen ;-)


I was thinking that the discussed problem must involve a guile script that
might not be able to sense that it was being invoked by an interactive
repl if it got executed in a nested way as a sub-command,
because the latter would not see a PS1 unless it was in its current environment.

So I was trying to point out that if from the repl you invoke the
nesting script by sourcing it instead of executing it, the sourcing
makes the execution happen in the current environment, and PS1 is seen
and apparently passed on to what the sourced script invokes.

I was lazy about separating stuff, sorry. Comments on the pieces follow:

--8<---------------cut here---------------start------------->8---

What you report above:
┌────────────────────────────────────────────────────────────────────┐
│ > $ echo $PS1                                                      │
│ > \n\w/\n\u@\h$                                                    │
│ > $ guile --no-auto-compile -c '(display (getenv "PS1"))(newline)' │
│ > #f                                                               │
│ >                                                                  │
└────────────────────────────────────────────────────────────────────┘

The guile I'm running:

{ which guile; guile -v; } 
--8<---------------cut here---------------start------------->8---
/usr/bin/guile
guile (GNU Guile) 2.2.4
Packaged by Debian (2.2.4-deb+1-2+deb10u1)
Copyright (C) 2018 Free Software Foundation, Inc.

License LGPLv3+: GNU LGPL 3 or later <http://gnu.org/licenses/lgpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
--8<---------------cut here---------------end--------------->8---

Me: Like you, but not getting #f -- my bug, presumably ? Should this return #f for sure?
┌──────────────────────────────────────────────────────────────────────────────┐
│ [13:23 ~/bs]$ guile --no-auto-compile -c '(display (getenv "PS1"))(newline)' │
│ [\A \w]\$                                                                    │
└──────────────────────────────────────────────────────────────────────────────┘
Invoking script[1]  as command, not sourcing -- no PS1 in the command's env nested
guile doesn't see it
┌─────────────────────────────────────┐
│ [13:24 ~/bs]$ ./guile-non-int-call  │
│ PS1_val='#f'                        │
│ #f                                  │
└─────────────────────────────────────┘
Sourcing makes the execution happen in the current env, so PS1 is visible
┌────────────────────────────────────────────┐
│ [13:24 ~/bs]$ source ./guile-non-int-call  │
│ PS1_val='[\A \w]\$ '                       │
│ [\A \w]\$                                  │
└────────────────────────────────────────────┘
[1] The script producing the above results as command vs sourced:
┌──────────────────────────────────────────────────────────────────────────────────────┐
│ [13:24 ~/bs]$ cat -nA ./guile-non-int-call                                           │
│      1  #!/usr/bin/bash$                                                             │
│      2  PS1_val="$(guile --no-auto-compile -c '(display (getenv "PS1"))(newline)')"$ │
│      3  echo "PS1_val='$PS1_val'"$                                                   │
│      4  guile --no-auto-compile -c '(display (getenv "PS1"))(newline)'$              │
│ [13:25 ~/bs]$                                                                        │
└──────────────────────────────────────────────────────────────────────────────────────┘
--8<---------------cut here---------------end--------------->8---

WDYT?
I need to go back to square 1 default .bash_login and .bashrc to debug this I guess :-(
(so .profile and my mods down the .profile sequence will be ignored). Gaah :-/
--
Regards,
Bengt Richter


  reply	other threads:[~2022-07-16 19:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-03 18:11 repl macro (metacommand?) for guix CLI (sub)commands jgart
2022-07-04  8:29 ` zimoun
2022-07-04 13:22 ` Ludovic Courtès
2022-07-04 18:21   ` jgart
2022-07-04 20:28     ` Tobias Geerinckx-Rice
2022-07-04 22:47       ` zimoun
2022-07-05 22:27         ` jgart
2022-07-06  6:44           ` zimoun
2022-07-06 12:13             ` bokr
2022-07-06 12:58               ` zimoun
2022-07-16 19:08                 ` Bengt Richter [this message]
2022-07-07  7:31     ` Ludovic Courtès
2022-07-07  7:58       ` bokr

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=20220716190831.GA5993@LionPure \
    --to=bokr@bokr.com \
    --cc=guix-devel@gnu.org \
    --cc=jgart@dismail.de \
    --cc=ludo@gnu.org \
    --cc=me@tobias.gr \
    --cc=zimon.toutoune@gmail.com \
    /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).