Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install fails when running PowerShell from emulated terminal cmder #20

Open
pstephenson02 opened this issue Dec 28, 2018 · 0 comments
Open

Comments

@pstephenson02
Copy link

First of all, thank you for this library - it's great.

When running PowerShell, cmder by default invoke's the shell with a few parameters:

*PowerShell -ExecutionPolicy Bypass -NoLogo -NoProfile -NoExit -Command "Invoke-Expression '. ''%ConEmuDir%\..\profile.ps1'''"

(these can be found in the cmder Settings)

These parameters affect click-completion install a couple of ways:

  1. The above command sets the ExecutionPolicy on the Process scope to Bypass. When click-completion's install command runs, it tries to set the ExecutionPolicy to Unrestricted on the CurrentUser scope. We end up with this:
Set-ExecutionPolicy : Windows PowerShell updated your execution policy successfully, but the setting is overridden by a policy defined at a more
specific scope.  Due to the override, your shell will retain its current effective execution policy of Bypass. Type "Get-ExecutionPolicy -List" to
view your execution policy settings. For more information please see "Get-Help Set-ExecutionPolicy".
At line:1 char:1
+ Set-ExecutionPolicy Unrestricted -Scope CurrentUser
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (:) [Set-ExecutionPolicy], SecurityException
    + FullyQualifiedErrorId : ExecutionPolicyOverride,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand
Traceback (most recent call last):

...
  File "c:\code\click-completion\click_completion\core.py", line 353, in install
    subprocess.check_call(['powershell', 'Set-ExecutionPolicy Unrestricted -Scope CurrentUser'])
  File "c:\users\pstephenson.aa\appdata\local\programs\python\python37-32\lib\subprocess.py", line 328, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['powershell', 'Set-ExecutionPolicy Unrestricted -Scope CurrentUser']' returned non-zero exit status 1.
  1. cmder also defines its own user_profile.ps1 file that, by default, does not load the PowerShell profile defined in $profile. This has been noted in some GitHub issues, but it's also relevant for this project because it means that while the completion code gets added to the $profile file, you won't get the expected behavior without dot sourcing $profile each time you load a new cmder window.

I am happy to submit some documentation for cmder users to look out for these things. However, I wanted to ask your thoughts on the first issue: One thing to consider might be to before setting the execution policy, you could first check the execution policy on the Process scope to see if it's anything other than Undefined or Unrestricted: https://github.com/click-contrib/click-completion/blob/master/click_completion/core.py#L353. If that is the case, maybe we throw an exception and display a helpful error message to the user indicating the issue? What are your thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant