From 2a493c1318cc26cb68fefb3613309d14e859ef2c Mon Sep 17 00:00:00 2001 From: William Lee Date: Mon, 12 Feb 2018 14:59:43 -0800 Subject: [PATCH] Support TildeSlash expand (#8589) --- .../EnvironmentProvider.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.DotNet.Cli.Utils/EnvironmentProvider.cs b/src/Microsoft.DotNet.Cli.Utils/EnvironmentProvider.cs index 65db78e825..b8d85b3b72 100644 --- a/src/Microsoft.DotNet.Cli.Utils/EnvironmentProvider.cs +++ b/src/Microsoft.DotNet.Cli.Utils/EnvironmentProvider.cs @@ -14,6 +14,7 @@ public class EnvironmentProvider : IEnvironmentProvider private static char[] s_pathSeparator = new char[] { Path.PathSeparator }; private static char[] s_quote = new char[] { '"' }; private IEnumerable _searchPaths; + private readonly Lazy _userHomeDirectory = new Lazy(() => Environment.GetEnvironmentVariable("HOME") ?? string.Empty); private IEnumerable _executableExtensions; public IEnumerable ExecutableExtensions @@ -45,7 +46,8 @@ private IEnumerable SearchPaths 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 @@ private IEnumerable SearchPaths } } + 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 extensionsOverride = null, IEnumerable searchPathsOverride = null)