@@ -14,6 +14,7 @@ public class EnvironmentProvider : IEnvironmentProvider
1414 private static char [ ] s_pathSeparator = new char [ ] { Path . PathSeparator } ;
1515 private static char [ ] s_quote = new char [ ] { '"' } ;
1616 private IEnumerable < string > _searchPaths ;
17+ private readonly Lazy < string > _userHomeDirectory = new Lazy < string > ( ( ) => Environment . GetEnvironmentVariable ( "HOME" ) ?? string . Empty ) ;
1718 private IEnumerable < string > _executableExtensions ;
1819
1920 public IEnumerable < string > ExecutableExtensions
@@ -45,7 +46,8 @@ private IEnumerable<string> SearchPaths
4546 searchPaths . AddRange ( Environment
4647 . GetEnvironmentVariable ( "PATH" )
4748 . Split ( s_pathSeparator )
48- . Select ( p => p . Trim ( s_quote ) ) ) ;
49+ . Select ( p => p . Trim ( s_quote ) )
50+ . Select ( p => ExpandTildeSlash ( p ) ) ) ;
4951
5052 _searchPaths = searchPaths ;
5153 }
@@ -54,6 +56,19 @@ private IEnumerable<string> SearchPaths
5456 }
5557 }
5658
59+ private string ExpandTildeSlash ( string path )
60+ {
61+ const string tildeSlash = "~/" ;
62+ if ( path . StartsWith ( tildeSlash , StringComparison . Ordinal ) && ! string . IsNullOrEmpty ( _userHomeDirectory . Value ) )
63+ {
64+ return Path . Combine ( _userHomeDirectory . Value , path . Substring ( tildeSlash . Length ) ) ;
65+ }
66+ else
67+ {
68+ return path ;
69+ }
70+ }
71+
5772 public EnvironmentProvider (
5873 IEnumerable < string > extensionsOverride = null ,
5974 IEnumerable < string > searchPathsOverride = null )
0 commit comments