Commit 94b54094 authored by Kris Leech's avatar Kris Leech

Allow http://localhost:$port to be opened in the default browser using either...

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.
parent 388e15f6
# Opens http://localhost:3000 (and other ports) in the default browser # Opens http://localhost:3000 (and other ports) in the default browser
# Requires `open` to be installed (MacOS only) #
# Usage:
# Example: #
# open a commonly used port with just the port number
# $ 3000 # $ 3000
#
# open an arbitrary port using the `lh` command
# $ lh 3001
## Functions ## Functions
function _open-installed function _open-installed
which open >/dev/null ^&1 which open >/dev/null ^&1
end end
function _open_browser ## Main program
function lh
if _open-installed 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 command open http://localhost:$argv
else else
echo 'Requires open to be installed' echo 'Requires open (MacOS only) to be installed'
end end
end end
## Main program set -l common_localhost_ports 3000 4000 5000 6000 7000 8000 9000 8080
set -l localhost_ports 3000 4000 5000 6000 7000 8000 9000 8080
for port in $localhost_ports for port in $common_localhost_ports
eval "function $port; _open_browser $port; end" eval "function $port; lh $port; end"
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment