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

Support TildeSlash expand #8589

Merged
merged 1 commit into from
Feb 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, 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)
Expand Down