Support TildeSlash expand (#8589)
This commit is contained in:
parent
72d9c0f23f
commit
2a493c1318
1 changed files with 16 additions and 1 deletions
|
@ -14,6 +14,7 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
private static char[] s_pathSeparator = new char[] { Path.PathSeparator };
|
||||
private static char[] s_quote = new char[] { '"' };
|
||||
private IEnumerable<string> _searchPaths;
|
||||
private readonly Lazy<string> _userHomeDirectory = new Lazy<string>(() => Environment.GetEnvironmentVariable("HOME") ?? string.Empty);
|
||||
private IEnumerable<string> _executableExtensions;
|
||||
|
||||
public IEnumerable<string> ExecutableExtensions
|
||||
|
@ -45,7 +46,8 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
searchPaths.AddRange(Environment
|
||||
.GetEnvironmentVariable("PATH")
|
||||
.Split(s_pathSeparator)
|
||||
.Select(p => p.Trim(s_quote)));
|
||||
.Select(p => p.Trim(s_quote))
|
||||
.Select(p => ExpandTildeSlash(p)));
|
||||
|
||||
_searchPaths = searchPaths;
|
||||
}
|
||||
|
@ -54,6 +56,19 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
}
|
||||
}
|
||||
|
||||
private string ExpandTildeSlash(string path)
|
||||
{
|
||||
const string tildeSlash = "~/";
|
||||
if (path.StartsWith(tildeSlash, StringComparison.Ordinal) && !string.IsNullOrEmpty(_userHomeDirectory.Value))
|
||||
{
|
||||
return Path.Combine(_userHomeDirectory.Value, path.Substring(tildeSlash.Length));
|
||||
}
|
||||
else
|
||||
{
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
public EnvironmentProvider(
|
||||
IEnumerable<string> extensionsOverride = null,
|
||||
IEnumerable<string> searchPathsOverride = null)
|
||||
|
|
Loading…
Add table
Reference in a new issue