mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 04:36:39 +00:00
Further code review changes
This commit is contained in:
1 parent
4c1f9f9c79
commit
c2527199a6
5 files changed
+55
-45
No files matched your search
@@ -192,13 +192,13 @@ namespace Microsoft.PowerShell
|
|||||||
//check if the user has set an XDG path in their environment variables
|
//check if the user has set an XDG path in their environment variables
|
||||||
profileDir = Platform.SelectProductNameForDirectory(Platform.XDG_Type.PROFILE);
|
profileDir = Platform.SelectProductNameForDirectory(Platform.XDG_Type.PROFILE);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
if (!Directory.Exists(profileDir)) //xdg value may have been set but not a valid directory
|
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.");
|
Console.WriteLine("The selected directory (" + profileDir +") for the profile does not exist. Using the default path.");
|
||||||
profileDir = Platform.SelectProductNameForDirectory(Platform.XDG_Type.DEFAULT);
|
profileDir = Platform.SelectProductNameForDirectory(Platform.XDG_Type.DEFAULT);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
ClrFacade.SetProfileOptimizationRoot(profileDir);
|
ClrFacade.SetProfileOptimizationRoot(profileDir);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|||||||
@@ -180,23 +180,23 @@ namespace Microsoft.PowerShell
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
//PSReadline does not have access to Utils.CorePSPlatform. Must set PSReadline path seperately
|
//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");
|
historypath = System.IO.Path.Combine(historypath, "powershell");
|
||||||
HistorySavePath = modulepath;
|
HistorySavePath = historypath;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
modulepath = System.IO.Path.Combine(
|
historypath = System.IO.Path.Combine(
|
||||||
Environment.GetEnvironmentVariable("HOME"),
|
Environment.GetEnvironmentVariable("HOME"),
|
||||||
".config/powershell/modules");
|
".local/share/powershell/modules");
|
||||||
|
|
||||||
HistorySavePath = System.IO.Path.Combine(
|
HistorySavePath = System.IO.Path.Combine(
|
||||||
Environment.GetEnvironmentVariable("HOME"),
|
Environment.GetEnvironmentVariable("HOME"),
|
||||||
modulepath,
|
historypath,
|
||||||
"PSReadLine",
|
"PSReadLine",
|
||||||
hostName + "_history.txt");
|
hostName + "_history.txt");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,66 +109,66 @@ namespace System.Management.Automation
|
|||||||
public static string SelectProductNameForDirectory (Platform.XDG_Type dirpath)
|
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 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 xdgcachehome = System.Environment.GetEnvironmentVariable("XDG_CACHE_HOME");
|
||||||
string profileDefault = Path.Combine ( System.Environment.GetEnvironmentVariable("HOME"), ".config/powershell");
|
string xdgConfigHomeDefault = Path.Combine ( System.Environment.GetEnvironmentVariable("HOME"), ".config/powershell");
|
||||||
string moduleDefault = Path.Combine ( System.Environment.GetEnvironmentVariable("HOME"), ".config/powershell/modules");
|
string moduleDefault = Path.Combine ( System.Environment.GetEnvironmentVariable("HOME"), ".local/share/powershell/modules");
|
||||||
|
|
||||||
switch (dirpath){
|
switch (dirpath){
|
||||||
case Platform.XDG_Type.PROFILE:
|
case Platform.XDG_Type.PROFILE:
|
||||||
//the user has set XDG_CONFIG_HOME corrresponding to profile path
|
//the user has set XDG_CONFIG_HOME corrresponding to profile path
|
||||||
if (!String.IsNullOrEmpty(xdgconfighome))
|
if (String.IsNullOrEmpty(xdgconfighome))
|
||||||
{
|
{
|
||||||
xdgconfighome = Path.Combine(xdgconfighome, "powershell");
|
//xdg values have not been set
|
||||||
return xdgconfighome;
|
return xdgConfigHomeDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//xdg values have not been set
|
return Path.Combine(xdgconfighome, "powershell");
|
||||||
return profileDefault;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case Platform.XDG_Type.MODULES:
|
case Platform.XDG_Type.MODULES:
|
||||||
//the user has set XDG_DATA_HOME corresponding to module path
|
//the user has set XDG_DATA_HOME corresponding to module path
|
||||||
if (!String.IsNullOrEmpty(xdgdatahome)){
|
if (String.IsNullOrEmpty(xdgdatahome)){
|
||||||
xdgdatahome = Path.Combine(xdgdatahome, "powershell");
|
|
||||||
return xdgdatahome;
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//xdg values have not been set
|
//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);
|
Directory.CreateDirectory(moduleDefault);
|
||||||
}
|
}
|
||||||
|
|
||||||
return profileDefault;
|
return xdgConfigHomeDefault;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Path.Combine(xdgdatahome, "powershell");
|
||||||
}
|
}
|
||||||
|
|
||||||
case Platform.XDG_Type.HISTORY:
|
case Platform.XDG_Type.HISTORY:
|
||||||
//the user has set XDG_CACHE_HOME
|
//the user has set XDG_CACHE_HOME
|
||||||
if (!String.IsNullOrEmpty(xdgcachehome)){
|
if (String.IsNullOrEmpty(xdgcachehome)){
|
||||||
xdgcachehome = Path.Combine(xdgcachehome, "powershell");
|
return xdgConfigHomeDefault;
|
||||||
return xdgcachehome;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return profileDefault;
|
return Path.Combine(xdgcachehome, "powershell");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case Platform.XDG_Type.DEFAULT:
|
case Platform.XDG_Type.DEFAULT:
|
||||||
//default for profile location
|
//default for profile location
|
||||||
return profileDefault;
|
return xdgConfigHomeDefault;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (!Directory.Exists(profileDefault))
|
if (!Directory.Exists(xdgConfigHomeDefault))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(profileDefault);
|
Directory.CreateDirectory(xdgConfigHomeDefault);
|
||||||
}
|
}
|
||||||
return profileDefault;
|
return xdgConfigHomeDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -548,8 +548,20 @@ namespace System.Management.Automation
|
|||||||
/// <returns>personal module path</returns>
|
/// <returns>personal module path</returns>
|
||||||
internal static string GetPersonalModulePath()
|
internal static string GetPersonalModulePath()
|
||||||
{
|
{
|
||||||
string personalModuleRoot = Platform.SelectProductNameForDirectory(Platform.XDG_Type.MODULES);
|
if (Platform.IsWindows)
|
||||||
return personalModuleRoot;
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -26,9 +26,9 @@ Describe "XDG Base Directory Specification" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
It "Should start with the default profile" -Skip:$IsWindows {
|
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
|
# 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 {
|
It "Should respect XDG_CONFIG_HOME" -Skip:$IsWindows {
|
||||||
@@ -41,11 +41,11 @@ Describe "XDG Base Directory Specification" {
|
|||||||
|
|
||||||
Context "Modules" {
|
Context "Modules" {
|
||||||
|
|
||||||
It "Should start with the default module path" -Skip:$IsWindows {
|
It "Should respect XDG_DATA_HOME" -Skip:$IsWindows {
|
||||||
$expected = [IO.Path]::Combine($env:HOME, ".config", "powershell")
|
$env:XDG_DATA_HOME = [IO.Path]::Combine($env:HOME, ".local", "share", "powershell", "Modules")
|
||||||
$modulepath = & $powershell -noprofile `$env:PSMODULEPATH
|
$modulepath = & $powershell -noprofile `$env:PSMODULEPATH
|
||||||
$modulepath = $modulepath.split(';')[0]
|
$modulepath = $modulepath.split(';')[0]
|
||||||
$modulepath | Should Be $expected
|
$modulepath | Should Be $env:XDG_DATA_HOME
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should respect XDG_CACHE_HOME" -Skip:$IsWindows {
|
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
|
& $powershell -noprofile `$env:XDG_CACHE_HOME | Should Be $expected
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should respect XDG_DATA_HOME" -Skip:$IsWindows {
|
It "Should respect PSReadLine history" -Skip:$IsWindows {
|
||||||
$env:XDG_DATA_HOME = [IO.Path]::Combine($pwd, "test", "path")
|
$env:XDG_DATA_HOME = [IO.Path]::Combine($env:HOME, ".local", "share", "powershell", "PSReadLine", "ConsoleHost_history.txt")
|
||||||
$datahomeDir = [IO.Path]::Combine($env:XDG_DATA_HOME, "ConsoleHost_history.txt")
|
"a" | Should Be $expected
|
||||||
$expected = [IO.Path]::Combine($HOME, "Powershell", "test", "path", "ConsoleHost_history.txt")
|
|
||||||
$datahomeDir | Should Be $expected
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user