Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Support TildeSlash expand
Browse files Browse the repository at this point in the history
  • Loading branch information
William Li committed Feb 12, 2018
1 parent 6ef587d commit 64bfb5b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Microsoft.DotNet.Cli.Utils/EnvironmentProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> _searchPaths;
private readonly Lazy<string> _userHomeDirectory = new Lazy<string>(() => Environment.GetEnvironmentVariable("HOME") ?? string.Empty);
private IEnumerable<string> _executableExtensions;

public IEnumerable<string> ExecutableExtensions
Expand Down Expand Up @@ -45,7 +46,8 @@ private IEnumerable<string> 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;
}
Expand All @@ -54,6 +56,19 @@ private IEnumerable<string> 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<string> extensionsOverride = null,
IEnumerable<string> searchPathsOverride = null)
Expand Down

0 comments on commit 64bfb5b

Please sign in to comment.