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
|
||||
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
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -548,8 +548,20 @@ namespace System.Management.Automation
|
||||
/// <returns>personal module path</returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in new issue
Block a user