From 0ea4797813b47350df3563f1b224838ad78190d5 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Mon, 6 May 2019 14:09:55 -0700 Subject: [PATCH 1/2] draft to enable pwsh to be used as login shell --- .../RFCnnnn-PowerShell-as-Login-Shell.md | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 2-Draft-Accepted/RFCnnnn-PowerShell-as-Login-Shell.md diff --git a/2-Draft-Accepted/RFCnnnn-PowerShell-as-Login-Shell.md b/2-Draft-Accepted/RFCnnnn-PowerShell-as-Login-Shell.md new file mode 100644 index 00000000..22b75cf6 --- /dev/null +++ b/2-Draft-Accepted/RFCnnnn-PowerShell-as-Login-Shell.md @@ -0,0 +1,56 @@ +--- +RFC: RFCnnnn +Author: Steve Lee +Status: Draft +SupercededBy: N/A +Version: 1.0 +Area: Console +Comments Due: June 6, 2019 +Plan to implement: Yes +--- + +# Enable PowerShell as Login Shell on POSIX-based systems + +POSIX shells on Unix-based systems use a `-l` switch to start the shell as a login shell. +This means the shell is not being started from an existing configured environment and +needs to execute `/etc/profile` to populate environment variables along with other +environment changes. + +## Motivation + + As a PowerShell user, + I can use PowerShell as my login shell on Unix-based systems, + so that I can use PowerShell everywhere. + +## Specification + +`/etc/profile` is a Bourne shell (sh) script that is executed to configure the +environment and used with login shells. +On Linux systems, this script will typically call out to other scripts (`rc` files) +to perform their own configuration. +On macOS, this script executes `path_helper` which sets up the `$env:PATH` +environment variable and then if the shell is `bash` executes `bashrc`. + +Many existing tools expect `-l` to be accepted by a shell and to act as a login +shell. +Without supporting `/etc/profile`, some environment variables will be missing +in PowerShell rendering it limited as a login or default shell. + +If `-l` (or `-LoadProfile`) is specified, PowerShell will execute `/etc/profile` +using `sh` in a new process and dump out the resulting environment variables. +It will then set those variables in the current PowerShell process. + +On Windows, this switch will only explicitly load the PowerShell profiles. + +Since PowerShell is starting a new process to process `/etc/profile` which itself +may start child processes like `path_helper`, there should not be more than 100ms +impact when `-l` is specified. + +## Alternate Proposals and Considerations + +This RFC is not intended to address the default behavior of PowerShell to load +the PowerShell profile. +`-NoProfile` is still required to have PowerShell not execute PowerShell profiles. + +The implementation is intended to be limited to just environment variables. +`umask` settings, for example, will not be inherited to PowerShell. From 33019ae41d313c7e51aff6c0ca463e2a36a9d737 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Thu, 23 May 2019 12:47:47 -0700 Subject: [PATCH 2/2] update RFC per feedback --- .../RFCnnnn-PowerShell-as-Login-Shell.md | 57 ++++++++++++------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/2-Draft-Accepted/RFCnnnn-PowerShell-as-Login-Shell.md b/2-Draft-Accepted/RFCnnnn-PowerShell-as-Login-Shell.md index 22b75cf6..6d59714f 100644 --- a/2-Draft-Accepted/RFCnnnn-PowerShell-as-Login-Shell.md +++ b/2-Draft-Accepted/RFCnnnn-PowerShell-as-Login-Shell.md @@ -24,33 +24,48 @@ environment changes. ## Specification -`/etc/profile` is a Bourne shell (sh) script that is executed to configure the -environment and used with login shells. -On Linux systems, this script will typically call out to other scripts (`rc` files) -to perform their own configuration. -On macOS, this script executes `path_helper` which sets up the `$env:PATH` -environment variable and then if the shell is `bash` executes `bashrc`. - Many existing tools expect `-l` to be accepted by a shell and to act as a login shell. -Without supporting `/etc/profile`, some environment variables will be missing -in PowerShell rendering it limited as a login or default shell. -If `-l` (or `-LoadProfile`) is specified, PowerShell will execute `/etc/profile` -using `sh` in a new process and dump out the resulting environment variables. -It will then set those variables in the current PowerShell process. +`-l` (expanded form is `-LoadProfile`) will explicitly have pwsh load the PowerShell +profile. +This is effectively a no-op as if this switch is not specified, pwsh will load +the PowerShell profile and only doesn't load it if `-noprofile` is specified. + +This will allow tools that expect `-l` to be accepted to work. +There is no additional work to process `/etc/profile` when `-l` is used. -On Windows, this switch will only explicitly load the PowerShell profiles. +For cases where you do need `/etc/profile` to be processed, +such as using pwsh as your default shell, +the proposal is to include a Bourne shell script that can be specified as the +shell: -Since PowerShell is starting a new process to process `/etc/profile` which itself -may start child processes like `path_helper`, there should not be more than 100ms -impact when `-l` is specified. +```sh +#!/bin/sh -l +exec /usr/local/bin/pwsh "$@" +``` + +This script will be called `pwsh-login` and should be used whenever you require +a specific login shell. ## Alternate Proposals and Considerations -This RFC is not intended to address the default behavior of PowerShell to load -the PowerShell profile. -`-NoProfile` is still required to have PowerShell not execute PowerShell profiles. +### Process /etc/profile using sh and copy the env vars + +This proposal would be that if `-l` is specified, pwsh would run `/bin/sh -l -c export` +which would create a new shell process that does all the processing needed for +a login shell and export the environment variables that would be exported. +Additional code is needed to take those environment variables and copy them to +the parent pwsh process. + +The downsides to this approach is additional code to maintain, +but more importantly not getting a complete login shell environment as things +like ulimit and umask would not be inherited into pwsh. + +### pwsh to start `/bin/sh -l -c "exec pwsh"` + +This proposal would have pwsh when given the `-l` switch to start Bourne shell +as a login shell and start pwsh within that process. -The implementation is intended to be limited to just environment variables. -`umask` settings, for example, will not be inherited to PowerShell. +This would result in a complete login shell environment, however, would +incur the performance penalty of starting pwsh twice.