From 237c659b5ec701e583e0ad69b4cfc6d567dcf8dc Mon Sep 17 00:00:00 2001 From: v-alexjo Date: Thu, 2 Jun 2016 10:14:51 -0700 Subject: [PATCH] Changes to xdg to append powershell path --- .../host/msh/ConsoleHost.cs | 6 ++-- .../Cmdlets.cs | 34 +++++++++---------- .../CoreCLR/CorePsPlatform.cs | 21 ++++++++---- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs index cd25cf24f5..0071b1aad3 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs @@ -192,13 +192,13 @@ namespace Microsoft.PowerShell //check if the user has set an XDG path in their environment variables profileDir = Platform.SelectProductNameForDirectory(Platform.XDG_Type.PROFILE); } - + /* if (!Directory.Exists(profileDir)) //xdg value may have been set but not a valid directory { - Console.WriteLine("The selected directory for the profile does not exist. Using the default path."); + Console.WriteLine("The selected directory (" + profileDir +") for the profile does not exist. Using the default path."); profileDir = Platform.SelectProductNameForDirectory(Platform.XDG_Type.DEFAULT); } - + */ ClrFacade.SetProfileOptimizationRoot(profileDir); } catch diff --git a/src/Microsoft.PowerShell.PSReadLine/Cmdlets.cs b/src/Microsoft.PowerShell.PSReadLine/Cmdlets.cs index ff6eb9dd05..f325951821 100644 --- a/src/Microsoft.PowerShell.PSReadLine/Cmdlets.cs +++ b/src/Microsoft.PowerShell.PSReadLine/Cmdlets.cs @@ -181,29 +181,27 @@ namespace Microsoft.PowerShell { //PSReadline does not have access to Utils.CorePSPlatform. Must set PSReadline path seperately string modulepath = System.Environment.GetEnvironmentVariable("XDG_CACHE_HOME"); - - if (String.IsNullOrEmpty(modulepath)) - { - modulepath = System.IO.Path.Combine( - Environment.GetEnvironmentVariable("HOME"), - ".config/powershell/modules"); - - HistorySavePath = System.IO.Path.Combine( - Environment.GetEnvironmentVariable("HOME"), - modulepath, - "PSReadLine", - hostName + "_history.txt"); - } - - else { + if (!String.IsNullOrEmpty(modulepath)) + { + modulepath = System.IO.Path.Combine(modulepath, "powershell"); HistorySavePath = modulepath; - } - + else + { + modulepath = System.IO.Path.Combine( + Environment.GetEnvironmentVariable("HOME"), + ".config/powershell/modules"); + + HistorySavePath = System.IO.Path.Combine( + Environment.GetEnvironmentVariable("HOME"), + modulepath, + "PSReadLine", + hostName + "_history.txt"); } - #else + } +#else HistorySavePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft\Windows\PowerShell\PSReadline\" + hostName + "_history.txt"; #endif diff --git a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs index cd948ae430..7865c05ab2 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs @@ -106,10 +106,11 @@ namespace System.Management.Automation }; // function for choosing directory location of PowerShell for profile loading - public static string SelectProductNameForDirectory (Platform.XDG_Type dirpath){ + public static string SelectProductNameForDirectory (Platform.XDG_Type dirpath) + { string xdgconfighome = System.Environment.GetEnvironmentVariable("XDG_CONFIG_HOME"); - string xdgdatahome = System.Environment.GetEnvironmentVariable("XDG_DATA_HOME"); + string xdgdatahome = System.Environment.GetEnvironmentVariable("XDG_DATA_HOME"); string xdgcachehome = System.Environment.GetEnvironmentVariable("XDG_CACHE_HOME"); string profileDefault = Path.Combine ( System.Environment.GetEnvironmentVariable("HOME"), ".config/powershell"); string moduleDefault = Path.Combine ( System.Environment.GetEnvironmentVariable("HOME"), ".config/powershell/modules"); @@ -117,12 +118,14 @@ namespace System.Management.Automation switch (dirpath){ case Platform.XDG_Type.PROFILE: //the user has set XDG_CONFIG_HOME corrresponding to profile path - if (!String.IsNullOrEmpty(xdgconfighome)){ - + if (!String.IsNullOrEmpty(xdgconfighome)) + { + xdgconfighome = Path.Combine(xdgconfighome, "powershell"); return xdgconfighome; } - else { + else + { //xdg values have not been set return profileDefault; } @@ -130,10 +133,12 @@ namespace System.Management.Automation case Platform.XDG_Type.MODULES: //the user has set XDG_DATA_HOME corresponding to module path if (!String.IsNullOrEmpty(xdgdatahome)){ + xdgdatahome = Path.Combine(xdgdatahome, "powershell"); return xdgdatahome; } - else{ + else + { //xdg values have not been set if (!Directory.Exists(profileDefault)) //module folder not always guaranteed to exist { @@ -146,9 +151,11 @@ namespace System.Management.Automation case Platform.XDG_Type.HISTORY: //the user has set XDG_CACHE_HOME if (!String.IsNullOrEmpty(xdgcachehome)){ + xdgcachehome = Path.Combine(xdgcachehome, "powershell"); return xdgcachehome; } - else{ + else + { return profileDefault; }