From 388e15f6c5b34a855bc9788f1853cafdd069067b Mon Sep 17 00:00:00 2001 From: Kris Leech Date: Fri, 8 Mar 2013 20:53:48 +0000 Subject: [PATCH 1/2] localhost plugin which opens http://localhost:3000 (and other ports) in the default browser --- plugins/localhost/localhost.load | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 plugins/localhost/localhost.load diff --git a/plugins/localhost/localhost.load b/plugins/localhost/localhost.load new file mode 100644 index 0000000..ed62f7f --- /dev/null +++ b/plugins/localhost/localhost.load @@ -0,0 +1,25 @@ +# Opens http://localhost:3000 (and other ports) in the default browser +# Requires `open` to be installed (MacOS only) + +# Example: +# $ 3000 + +## Functions +function _open-installed + which open >/dev/null ^&1 +end + +function _open_browser + if _open-installed + command open http://localhost:$argv + else + echo 'Requires open to be installed' + end +end + +## Main program +set -l localhost_ports 3000 4000 5000 6000 7000 8000 9000 8080 + +for port in $localhost_ports + eval "function $port; _open_browser $port; end" +end From 94b54094dd067deacf097eff72ffb9dacd78ba74 Mon Sep 17 00:00:00 2001 From: Kris Leech Date: Mon, 11 Mar 2013 22:07:44 +0000 Subject: [PATCH 2/2] Allow http://localhost:$port to be opened in the default browser using either the port number for common ports or `lh` for an arbitrary port. --- plugins/localhost/localhost.load | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/plugins/localhost/localhost.load b/plugins/localhost/localhost.load index ed62f7f..3f74a93 100644 --- a/plugins/localhost/localhost.load +++ b/plugins/localhost/localhost.load @@ -1,25 +1,33 @@ # Opens http://localhost:3000 (and other ports) in the default browser -# Requires `open` to be installed (MacOS only) - -# Example: +# +# Usage: +# +# open a commonly used port with just the port number # $ 3000 +# +# open an arbitrary port using the `lh` command +# $ lh 3001 ## Functions function _open-installed which open >/dev/null ^&1 end -function _open_browser +## Main program +function lh if _open-installed + if [ (count $argv) -lt 1 ] + echo "You need to specify a port to open" + return 1 + end command open http://localhost:$argv else - echo 'Requires open to be installed' + echo 'Requires open (MacOS only) to be installed' end end -## Main program -set -l localhost_ports 3000 4000 5000 6000 7000 8000 9000 8080 +set -l common_localhost_ports 3000 4000 5000 6000 7000 8000 9000 8080 -for port in $localhost_ports - eval "function $port; _open_browser $port; end" +for port in $common_localhost_ports + eval "function $port; lh $port; end" end