Skip to content

Instantly share code, notes, and snippets.

@gmzi
Created May 13, 2022 14:39
Show Gist options
  • Save gmzi/5b6564d5829956998a284d748d125cf1 to your computer and use it in GitHub Desktop.
Save gmzi/5b6564d5829956998a284d748d125cf1 to your computer and use it in GitHub Desktop.
open remote machine's localhost server
# This script is to open localhost server from a local browser,
# it has a default-machine.local and :3000 as default port, both
# can be passed as arguments. On execution, it will open the target
# remote machine's localhost server in a Chrome tab.
# USAGE: ./openLocalhost.sh <machine_name> <port_number>
#!/bin/sh
# Uppercase user input for machine name, or use default:
TARGET="$(awk '{print toupper($0)}' <<< $1)"
if [ "$TARGET" = "" ] ; then
echo "no target specified, running default: xxx"
TARGET="XXX"
fi
# parse machine name in url:
URL="http://$TARGET.local:3000"
# check if port is specified:
if [ "$2" != "" ]; then
URL="http://$TARGET.local:$2"
fi
open -a "Google Chrome" $URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment