diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
index 0071b1aad3..ee8e2d5879 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 (" + 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 f325951821..d3fae3ee62 100644
--- a/src/Microsoft.PowerShell.PSReadLine/Cmdlets.cs
+++ b/src/Microsoft.PowerShell.PSReadLine/Cmdlets.cs
@@ -180,23 +180,23 @@ namespace Microsoft.PowerShell
else
{
//PSReadline does not have access to Utils.CorePSPlatform. Must set PSReadline path seperately
- string modulepath = System.Environment.GetEnvironmentVariable("XDG_CACHE_HOME");
+ string historypath = System.Environment.GetEnvironmentVariable("XDG_DATA_HOME");
- if (!String.IsNullOrEmpty(modulepath))
+ if (!String.IsNullOrEmpty(historypath))
{
- modulepath = System.IO.Path.Combine(modulepath, "powershell");
- HistorySavePath = modulepath;
+ historypath = System.IO.Path.Combine(historypath, "powershell");
+ HistorySavePath = historypath;
}
else
{
- modulepath = System.IO.Path.Combine(
+ historypath = System.IO.Path.Combine(
Environment.GetEnvironmentVariable("HOME"),
- ".config/powershell/modules");
+ ".local/share/powershell/modules");
HistorySavePath = System.IO.Path.Combine(
Environment.GetEnvironmentVariable("HOME"),
- modulepath,
+ historypath,
"PSReadLine",
hostName + "_history.txt");
}
diff --git a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs
index 7865c05ab2..ecf7d8b2a5 100644
--- a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs
+++ b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs
@@ -109,66 +109,66 @@ namespace System.Management.Automation
public static string SelectProductNameForDirectory (Platform.XDG_Type dirpath)
{
+ //TODO: XDG_DATA_DIRS implementation as per GitHub issue #1060
+
string xdgconfighome = System.Environment.GetEnvironmentVariable("XDG_CONFIG_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");
+ string xdgConfigHomeDefault = Path.Combine ( System.Environment.GetEnvironmentVariable("HOME"), ".config/powershell");
+ string moduleDefault = Path.Combine ( System.Environment.GetEnvironmentVariable("HOME"), ".local/share/powershell/modules");
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;
+ //xdg values have not been set
+ return xdgConfigHomeDefault;
}
else
{
- //xdg values have not been set
- return profileDefault;
+ return Path.Combine(xdgconfighome, "powershell");
}
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
- {
+ if (String.IsNullOrEmpty(xdgdatahome)){
//xdg values have not been set
- if (!Directory.Exists(profileDefault)) //module folder not always guaranteed to exist
+ if (!Directory.Exists(moduleDefault)) //module folder not always guaranteed to exist
{
Directory.CreateDirectory(moduleDefault);
}
- return profileDefault;
+ return xdgConfigHomeDefault;
+ }
+
+ else
+ {
+ return Path.Combine(xdgdatahome, "powershell");
}
case Platform.XDG_Type.HISTORY:
//the user has set XDG_CACHE_HOME
- if (!String.IsNullOrEmpty(xdgcachehome)){
- xdgcachehome = Path.Combine(xdgcachehome, "powershell");
- return xdgcachehome;
+ if (String.IsNullOrEmpty(xdgcachehome)){
+ return xdgConfigHomeDefault;
}
else
{
- return profileDefault;
+ return Path.Combine(xdgcachehome, "powershell");
+
}
case Platform.XDG_Type.DEFAULT:
//default for profile location
- return profileDefault;
+ return xdgConfigHomeDefault;
default:
- if (!Directory.Exists(profileDefault))
+ if (!Directory.Exists(xdgConfigHomeDefault))
{
- Directory.CreateDirectory(profileDefault);
+ Directory.CreateDirectory(xdgConfigHomeDefault);
}
- return profileDefault;
+ return xdgConfigHomeDefault;
}
}
diff --git a/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs b/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs
index ca976181c0..12a9c81f70 100644
--- a/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs
+++ b/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs
@@ -548,8 +548,20 @@ namespace System.Management.Automation
/// personal module path
internal static string GetPersonalModulePath()
{
- string personalModuleRoot = Platform.SelectProductNameForDirectory(Platform.XDG_Type.MODULES);
- return personalModuleRoot;
+ if (Platform.IsWindows)
+ {
+ string personalModuleRoot = Path.Combine(
+ Path.Combine(
+ Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
+ Utils.ProductNameForDirectory),
+ Utils.ModuleDirectory);
+ return personalModuleRoot;
+ }
+ else
+ {
+ string personalModuleRoot = Platform.SelectProductNameForDirectory(Platform.XDG_Type.MODULES);
+ return personalModuleRoot;
+ }
}
///
diff --git a/test/powershell/Profile.Tests.ps1 b/test/powershell/Profile.Tests.ps1
index 701d6b623d..2722d8f827 100644
--- a/test/powershell/Profile.Tests.ps1
+++ b/test/powershell/Profile.Tests.ps1
@@ -26,9 +26,9 @@ Describe "XDG Base Directory Specification" {
}
It "Should start with the default profile" -Skip:$IsWindows {
- $expected = [IO.Path]::Combine($env:HOME, ".config/powershell", $profileName)
+ $expected = [IO.Path]::Combine($env:HOME, "Documents", "WindowsPowerShell", $PROFILE)
# Escape variable with backtick so new process interpolates it
- & $powershell -noprofile `$PROFILE | Should Be $expected
+ & $powershell -noprofile `$PROFILE | Should Be $expected
}
It "Should respect XDG_CONFIG_HOME" -Skip:$IsWindows {
@@ -41,11 +41,11 @@ Describe "XDG Base Directory Specification" {
Context "Modules" {
- It "Should start with the default module path" -Skip:$IsWindows {
- $expected = [IO.Path]::Combine($env:HOME, ".config", "powershell")
+ It "Should respect XDG_DATA_HOME" -Skip:$IsWindows {
+ $env:XDG_DATA_HOME = [IO.Path]::Combine($env:HOME, ".local", "share", "powershell", "Modules")
$modulepath = & $powershell -noprofile `$env:PSMODULEPATH
$modulepath = $modulepath.split(';')[0]
- $modulepath | Should Be $expected
+ $modulepath | Should Be $env:XDG_DATA_HOME
}
It "Should respect XDG_CACHE_HOME" -Skip:$IsWindows {
@@ -54,11 +54,9 @@ Describe "XDG Base Directory Specification" {
& $powershell -noprofile `$env:XDG_CACHE_HOME | Should Be $expected
}
- It "Should respect XDG_DATA_HOME" -Skip:$IsWindows {
- $env:XDG_DATA_HOME = [IO.Path]::Combine($pwd, "test", "path")
- $datahomeDir = [IO.Path]::Combine($env:XDG_DATA_HOME, "ConsoleHost_history.txt")
- $expected = [IO.Path]::Combine($HOME, "Powershell", "test", "path", "ConsoleHost_history.txt")
- $datahomeDir | Should Be $expected
+ It "Should respect PSReadLine history" -Skip:$IsWindows {
+ $env:XDG_DATA_HOME = [IO.Path]::Combine($env:HOME, ".local", "share", "powershell", "PSReadLine", "ConsoleHost_history.txt")
+ "a" | Should Be $expected
}
}
}