From c1def3d65194845d0b1049a3c230a0e59d6cbc03 Mon Sep 17 00:00:00 2001 From: William Li Date: Fri, 9 Feb 2018 18:28:48 -0800 Subject: [PATCH] Support TildeSlash expand --- .../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 65db78e8257..e58c891bc5c 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) && !string.IsNullOrEmpty(_userHomeDirectory.Value)) + { + return Path.Combine(_userHomeDirectory.Value, path.Substring(tildeSlash.Length)); + } + else + { + return path; + } + } + public EnvironmentProvider( IEnumerable extensionsOverride = null, IEnumerable searchPathsOverride = null)