diff --git a/cli/Valet/Site.php b/cli/Valet/Site.php index 448cde0..4797163 100644 --- a/cli/Valet/Site.php +++ b/cli/Valet/Site.php @@ -22,6 +22,23 @@ function __construct(Configuration $config, CommandLine $cli, Filesystem $files) $this->config = $config; } + /** + * Get the real hostname for the given path, checking links. + * + * @param string $path + * @return string|null + */ + function hostForDirectory($path) + { + foreach ($this->files->scandir($this->sitesPath()) as $link) { + if ($resolved = realpath($this->sitesPath().'/'.$link) == $path) { + return $link; + } + } + + return basename($path); + } + /** * Link the current working directory with the given name. * diff --git a/cli/valet.php b/cli/valet.php index 1ac97de..c67c1eb 100755 --- a/cli/valet.php +++ b/cli/valet.php @@ -154,6 +154,15 @@ } })->descriptions('Get all of the paths registered with Valet'); +/** + * Open the current directory in the browser. + */ + $app->command('open', function () { + $url = "http://".Site::hostForDirectory(getcwd()).'.'.Configuration::read()['domain'].'/'; + + passthru("open ".escapeshellarg($url)); + }); + /** * Echo the currently tunneled URL. */ @@ -221,17 +230,6 @@ include $extension; } -/** - * Open the current url. - */ - $app->command('open', function () { - $url = "http://".basename(getcwd()).'.'.Configuration::read()['domain'].'/'; - - passthru("open ".escapeshellarg($url)); - - info('The url ['.$url.'] has been openend.'); - }); - /** * Run the application. */