From bf1bd19713c596c518df1deeec83084632f16c3c Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Wed, 13 Jul 2016 15:31:31 +0300 Subject: [PATCH] Implement activation script for powershell Also fix activation script for batch error when location path contains spaces. --- hererocks.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/hererocks.py b/hererocks.py index 9922da4..87151d7 100755 --- a/hererocks.py +++ b/hererocks.py @@ -120,13 +120,28 @@ activation_script_templates = { """, "deactivate-lua.bat": """ @echo off - if exist "#LOCATION#\\bin\\lua.exe" for /f "delims=" %%p in ('#LOCATION#\\bin\\lua #LOCATION#\\bin\\get_deactivated_path.lua') DO set "PATH=%%p" + if exist "#LOCATION#\\bin\\lua.exe" for /f "usebackq delims=" %%p in (`""#LOCATION#\\bin\\lua" "#LOCATION#\\bin\\get_deactivated_path.lua""`) DO set "PATH=%%p" + """, + "activate.ps1": """ + if (test-path function:deactivate-lua) { + deactivate-lua + } + + function global:deactivate-lua () { + if (test-path "#LOCATION#\\bin\\lua.exe") { + $env:PATH = & "#LOCATION#\\bin\\lua.exe" "#LOCATION#\\bin\\get_deactivated_path.lua" + } + + remove-item function:deactivate-lua + } + + $env:PATH = "#LOCATION#\\bin;" + $env:PATH """ } def write_activation_scripts(): if os.name == "nt": - template_names = ["get_deactivated_path.lua", "activate.bat", "deactivate-lua.bat"] + template_names = ["get_deactivated_path.lua", "activate.bat", "deactivate-lua.bat", "activate.ps1"] else: template_names = ["get_deactivated_path.lua", "activate", "activate.csh", "activate.fish"]