{"action":"created","comment":{"url":"https://api.github.com/repos/xp-runners/reference/pulls/comments/48999621","id":48999621,"diff_hunk":"@@ -0,0 +1,91 @@\n+using System;\n+using System.IO;\n+using System.Linq;\n+using System.Collections.Generic;\n+using Microsoft.Win32;\n+\n+namespace Xp.Runners.IO\n+{\n+    static class Cygwin\n+    {\n+        private const string CYGDRIVE_PATH = \"/cygdrive/\";\n+        private const string INSTALLATIONS = @\"Software\\Cygwin\\Installations\";\n+        private static byte[] SYMLINK_COOKIE = new byte[] { 33, 60, 115, 121, 109, 108, 105, 110, 107, 62 };\n+        private static IEnumerable<string> cygpath;\n+\n+        /// <summary>Determine whether we're runnning inside Cygwin</summary>\n+        public static bool Active { get { return null != Environment.GetEnvironmentVariable(\"SHELL\"); } }\n+\n+        /// <summary>Determine Cygwin installation directories. Caches information</summary>\n+        public static IEnumerable<string> Installations(bool cached = true)\n+        {\n+            if (cygpath == null || !cached)\n+            {\n+                var installed = Registry.CurrentUser.OpenSubKey(INSTALLATIONS) ?? Registry.LocalMachine.OpenSubKey(INSTALLATIONS);\n+                if (null == installed)\n+                {\n+                    throw new NotSupportedException(\"Cannot determine Cygwin path via registry [\" + INSTALLATIONS + \"]\");\n+                }\n+\n+                cygpath = installed.GetValueNames()\n+                    .Select(key => installed.GetValue(key) as string)\n+                    .Select(path => path.Replace(@\"\\??\\\", \"\"))\n+                    .ToArray()\n+                ;\n+            }\n+            return cygpath;\n+        }\n+\n+        /// <summary>Expands home directories in path</summary>\n+        public static string Expand(string path)\n+        {\n+            if (\"~\" == path || path.StartsWith(\"~/\"))  // ~ = /home/$USER, ~/bin := /home/$USER/bin\n+            {\n+                return \"/home\" + Path.DirectorySeparatorChar + Environment.UserName + path.Substring(1);\n+            }\n+            else if (path.StartsWith(\"~\"))             // ~thekid/bin := /home/thekid/bin\n+            {\n+                return \"/home\" + Path.DirectorySeparatorChar + path.Substring(1);\n+            }","path":"src/xp.runner/io/Cygwin.cs","position":49,"original_position":49,"commit_id":"490e8106cae7b3d3417f8931fd6d2371f8b8cdb1","original_commit_id":"490e8106cae7b3d3417f8931fd6d2371f8b8cdb1","user":{"login":"thekid","id":696742,"avatar_url":"https://avatars.githubusercontent.com/u/696742?v=3","gravatar_id":"","url":"https://api.github.com/users/thekid","html_url":"https://github.com/thekid","followers_url":"https://api.github.com/users/thekid/followers","following_url":"https://api.github.com/users/thekid/following{/other_user}","gists_url":"https://api.github.com/users/thekid/gists{/gist_id}","starred_url":"https://api.github.com/users/thekid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thekid/subscriptions","organizations_url":"https://api.github.com/users/thekid/orgs","repos_url":"https://api.github.com/users/thekid/repos","events_url":"https://api.github.com/users/thekid/events{/privacy}","received_events_url":"https://api.github.com/users/thekid/received_events","type":"User","site_admin":false},"body":"I'm unclear whether this is actually necessary, the shell does the expansion *before* passing the argument.","created_at":"2016-01-06T19:40:23Z","updated_at":"2016-01-06T19:40:23Z","html_url":"https://github.com/xp-runners/reference/pull/8#discussion_r48999621","pull_request_url":"https://api.github.com/repos/xp-runners/reference/pulls/8","_links":{"self":{"href":"https://api.github.com/repos/xp-runners/reference/pulls/comments/48999621"},"html":{"href":"https://github.com/xp-runners/reference/pull/8#discussion_r48999621"},"pull_request":{"href":"https://api.github.com/repos/xp-runners/reference/pulls/8"}}},"pull_request":{"url":"https://api.github.com/repos/xp-runners/reference/pulls/8","id":55248540,"html_url":"https://github.com/xp-runners/reference/pull/8","diff_url":"https://github.com/xp-runners/reference/pull/8.diff","patch_url":"https://github.com/xp-runners/reference/pull/8.patch","issue_url":"https://api.github.com/repos/xp-runners/reference/issues/8","number":8,"state":"open","locked":false,"title":"Cygwin path support","user":{"login":"thekid","id":696742,"avatar_url":"https://avatars.githubusercontent.com/u/696742?v=3","gravatar_id":"","url":"https://api.github.com/users/thekid","html_url":"https://github.com/thekid","followers_url":"https://api.github.com/users/thekid/followers","following_url":"https://api.github.com/users/thekid/following{/other_user}","gists_url":"https://api.github.com/users/thekid/gists{/gist_id}","starred_url":"https://api.github.com/users/thekid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thekid/subscriptions","organizations_url":"https://api.github.com/users/thekid/orgs","repos_url":"https://api.github.com/users/thekid/repos","events_url":"https://api.github.com/users/thekid/events{/privacy}","received_events_url":"https://api.github.com/users/thekid/received_events","type":"User","site_admin":false},"body":"This pull request adds support for Cygwin paths in `-cp` and `-m`, including Cygwin symlinks.\r\n\r\n### What happens internally\r\nAssume we're inside a Cygwin Terminal:\r\n\r\n```\r\n$ xp -cp ~/devel/xp/sequence/ ...\r\n# Expanded by bash\r\n# Passed to C# as /home/$USER/devel/xp/sequence/\r\n# Cygwin environment detected via getenv(\"SHELL\")\r\n# Cygwin installation path(s) determined via registry, HKCU\\Software\\Cygwin\\Installations\r\n# Mapped to Windows directory, passed to PHP as C:\\tools\\cygwin\\home\\$USER\\deve\\xp\\sequence\r\n```","created_at":"2016-01-06T18:48:18Z","updated_at":"2016-01-06T19:40:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"456c837cbc8fc16c0b8fa5cab6602bec4b41839a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/xp-runners/reference/pulls/8/commits","review_comments_url":"https://api.github.com/repos/xp-runners/reference/pulls/8/comments","review_comment_url":"https://api.github.com/repos/xp-runners/reference/pulls/comments{/number}","comments_url":"https://api.github.com/repos/xp-runners/reference/issues/8/comments","statuses_url":"https://api.github.com/repos/xp-runners/reference/statuses/490e8106cae7b3d3417f8931fd6d2371f8b8cdb1","head":{"label":"xp-runners:feature/cygwin-path-support","ref":"feature/cygwin-path-support","sha":"490e8106cae7b3d3417f8931fd6d2371f8b8cdb1","user":{"login":"xp-runners","id":16525735,"avatar_url":"https://avatars.githubusercontent.com/u/16525735?v=3","gravatar_id":"","url":"https://api.github.com/users/xp-runners","html_url":"https://github.com/xp-runners","followers_url":"https://api.github.com/users/xp-runners/followers","following_url":"https://api.github.com/users/xp-runners/following{/other_user}","gists_url":"https://api.github.com/users/xp-runners/gists{/gist_id}","starred_url":"https://api.github.com/users/xp-runners/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xp-runners/subscriptions","organizations_url":"https://api.github.com/users/xp-runners/orgs","repos_url":"https://api.github.com/users/xp-runners/repos","events_url":"https://api.github.com/users/xp-runners/events{/privacy}","received_events_url":"https://api.github.com/users/xp-runners/received_events","type":"Organization","site_admin":false},"repo":{"id":48945596,"name":"reference","full_name":"xp-runners/reference","owner":{"login":"xp-runners","id":16525735,"avatar_url":"https://avatars.githubusercontent.com/u/16525735?v=3","gravatar_id":"","url":"https://api.github.com/users/xp-runners","html_url":"https://github.com/xp-runners","followers_url":"https://api.github.com/users/xp-runners/followers","following_url":"https://api.github.com/users/xp-runners/following{/other_user}","gists_url":"https://api.github.com/users/xp-runners/gists{/gist_id}","starred_url":"https://api.github.com/users/xp-runners/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xp-runners/subscriptions","organizations_url":"https://api.github.com/users/xp-runners/orgs","repos_url":"https://api.github.com/users/xp-runners/repos","events_url":"https://api.github.com/users/xp-runners/events{/privacy}","received_events_url":"https://api.github.com/users/xp-runners/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/xp-runners/reference","description":"Reference implementation in C#","fork":false,"url":"https://api.github.com/repos/xp-runners/reference","forks_url":"https://api.github.com/repos/xp-runners/reference/forks","keys_url":"https://api.github.com/repos/xp-runners/reference/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xp-runners/reference/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xp-runners/reference/teams","hooks_url":"https://api.github.com/repos/xp-runners/reference/hooks","issue_events_url":"https://api.github.com/repos/xp-runners/reference/issues/events{/number}","events_url":"https://api.github.com/repos/xp-runners/reference/events","assignees_url":"https://api.github.com/repos/xp-runners/reference/assignees{/user}","branches_url":"https://api.github.com/repos/xp-runners/reference/branches{/branch}","tags_url":"https://api.github.com/repos/xp-runners/reference/tags","blobs_url":"https://api.github.com/repos/xp-runners/reference/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xp-runners/reference/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xp-runners/reference/git/refs{/sha}","trees_url":"https://api.github.com/repos/xp-runners/reference/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xp-runners/reference/statuses/{sha}","languages_url":"https://api.github.com/repos/xp-runners/reference/languages","stargazers_url":"https://api.github.com/repos/xp-runners/reference/stargazers","contributors_url":"https://api.github.com/repos/xp-runners/reference/contributors","subscribers_url":"https://api.github.com/repos/xp-runners/reference/subscribers","subscription_url":"https://api.github.com/repos/xp-runners/reference/subscription","commits_url":"https://api.github.com/repos/xp-runners/reference/commits{/sha}","git_commits_url":"https://api.github.com/repos/xp-runners/reference/git/commits{/sha}","comments_url":"https://api.github.com/repos/xp-runners/reference/comments{/number}","issue_comment_url":"https://api.github.com/repos/xp-runners/reference/issues/comments{/number}","contents_url":"https://api.github.com/repos/xp-runners/reference/contents/{+path}","compare_url":"https://api.github.com/repos/xp-runners/reference/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xp-runners/reference/merges","archive_url":"https://api.github.com/repos/xp-runners/reference/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xp-runners/reference/downloads","issues_url":"https://api.github.com/repos/xp-runners/reference/issues{/number}","pulls_url":"https://api.github.com/repos/xp-runners/reference/pulls{/number}","milestones_url":"https://api.github.com/repos/xp-runners/reference/milestones{/number}","notifications_url":"https://api.github.com/repos/xp-runners/reference/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xp-runners/reference/labels{/name}","releases_url":"https://api.github.com/repos/xp-runners/reference/releases{/id}","created_at":"2016-01-03T12:54:10Z","updated_at":"2016-01-03T13:38:22Z","pushed_at":"2016-01-06T19:35:25Z","git_url":"git://github.com/xp-runners/reference.git","ssh_url":"git@github.com:xp-runners/reference.git","clone_url":"https://github.com/xp-runners/reference.git","svn_url":"https://github.com/xp-runners/reference","homepage":null,"size":105,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":0,"default_branch":"master"}},"base":{"label":"xp-runners:master","ref":"master","sha":"31c426f995c98859fceb0ce3eb8ab48792dbbb0a","user":{"login":"xp-runners","id":16525735,"avatar_url":"https://avatars.githubusercontent.com/u/16525735?v=3","gravatar_id":"","url":"https://api.github.com/users/xp-runners","html_url":"https://github.com/xp-runners","followers_url":"https://api.github.com/users/xp-runners/followers","following_url":"https://api.github.com/users/xp-runners/following{/other_user}","gists_url":"https://api.github.com/users/xp-runners/gists{/gist_id}","starred_url":"https://api.github.com/users/xp-runners/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xp-runners/subscriptions","organizations_url":"https://api.github.com/users/xp-runners/orgs","repos_url":"https://api.github.com/users/xp-runners/repos","events_url":"https://api.github.com/users/xp-runners/events{/privacy}","received_events_url":"https://api.github.com/users/xp-runners/received_events","type":"Organization","site_admin":false},"repo":{"id":48945596,"name":"reference","full_name":"xp-runners/reference","owner":{"login":"xp-runners","id":16525735,"avatar_url":"https://avatars.githubusercontent.com/u/16525735?v=3","gravatar_id":"","url":"https://api.github.com/users/xp-runners","html_url":"https://github.com/xp-runners","followers_url":"https://api.github.com/users/xp-runners/followers","following_url":"https://api.github.com/users/xp-runners/following{/other_user}","gists_url":"https://api.github.com/users/xp-runners/gists{/gist_id}","starred_url":"https://api.github.com/users/xp-runners/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xp-runners/subscriptions","organizations_url":"https://api.github.com/users/xp-runners/orgs","repos_url":"https://api.github.com/users/xp-runners/repos","events_url":"https://api.github.com/users/xp-runners/events{/privacy}","received_events_url":"https://api.github.com/users/xp-runners/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/xp-runners/reference","description":"Reference implementation in C#","fork":false,"url":"https://api.github.com/repos/xp-runners/reference","forks_url":"https://api.github.com/repos/xp-runners/reference/forks","keys_url":"https://api.github.com/repos/xp-runners/reference/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xp-runners/reference/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xp-runners/reference/teams","hooks_url":"https://api.github.com/repos/xp-runners/reference/hooks","issue_events_url":"https://api.github.com/repos/xp-runners/reference/issues/events{/number}","events_url":"https://api.github.com/repos/xp-runners/reference/events","assignees_url":"https://api.github.com/repos/xp-runners/reference/assignees{/user}","branches_url":"https://api.github.com/repos/xp-runners/reference/branches{/branch}","tags_url":"https://api.github.com/repos/xp-runners/reference/tags","blobs_url":"https://api.github.com/repos/xp-runners/reference/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xp-runners/reference/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xp-runners/reference/git/refs{/sha}","trees_url":"https://api.github.com/repos/xp-runners/reference/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xp-runners/reference/statuses/{sha}","languages_url":"https://api.github.com/repos/xp-runners/reference/languages","stargazers_url":"https://api.github.com/repos/xp-runners/reference/stargazers","contributors_url":"https://api.github.com/repos/xp-runners/reference/contributors","subscribers_url":"https://api.github.com/repos/xp-runners/reference/subscribers","subscription_url":"https://api.github.com/repos/xp-runners/reference/subscription","commits_url":"https://api.github.com/repos/xp-runners/reference/commits{/sha}","git_commits_url":"https://api.github.com/repos/xp-runners/reference/git/commits{/sha}","comments_url":"https://api.github.com/repos/xp-runners/reference/comments{/number}","issue_comment_url":"https://api.github.com/repos/xp-runners/reference/issues/comments{/number}","contents_url":"https://api.github.com/repos/xp-runners/reference/contents/{+path}","compare_url":"https://api.github.com/repos/xp-runners/reference/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xp-runners/reference/merges","archive_url":"https://api.github.com/repos/xp-runners/reference/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xp-runners/reference/downloads","issues_url":"https://api.github.com/repos/xp-runners/reference/issues{/number}","pulls_url":"https://api.github.com/repos/xp-runners/reference/pulls{/number}","milestones_url":"https://api.github.com/repos/xp-runners/reference/milestones{/number}","notifications_url":"https://api.github.com/repos/xp-runners/reference/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xp-runners/reference/labels{/name}","releases_url":"https://api.github.com/repos/xp-runners/reference/releases{/id}","created_at":"2016-01-03T12:54:10Z","updated_at":"2016-01-03T13:38:22Z","pushed_at":"2016-01-06T19:35:25Z","git_url":"git://github.com/xp-runners/reference.git","ssh_url":"git@github.com:xp-runners/reference.git","clone_url":"https://github.com/xp-runners/reference.git","svn_url":"https://github.com/xp-runners/reference","homepage":null,"size":105,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/xp-runners/reference/pulls/8"},"html":{"href":"https://github.com/xp-runners/reference/pull/8"},"issue":{"href":"https://api.github.com/repos/xp-runners/reference/issues/8"},"comments":{"href":"https://api.github.com/repos/xp-runners/reference/issues/8/comments"},"review_comments":{"href":"https://api.github.com/repos/xp-runners/reference/pulls/8/comments"},"review_comment":{"href":"https://api.github.com/repos/xp-runners/reference/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/xp-runners/reference/pulls/8/commits"},"statuses":{"href":"https://api.github.com/repos/xp-runners/reference/statuses/490e8106cae7b3d3417f8931fd6d2371f8b8cdb1"}}}}