Nifty bash alias to launch BrowserStack tunnel

We've been using BrowserStack for quite some time now. It's a great tool when testing sites in different browser environments and covers our need for that.

You can either test public sites that are working and in production or you can test sites running in a local staging/development environment. The best way to do that is to tunnel your local site to BrowserStack with the following command:

java -jar ~/Applications/BrowserStackTunnel.jar [KEY_HERE] localhost,3000,0

It's quite a command to type in everytime you need to test something.

Aliases to the resque!

I used to have an alias in my ~/.alias file as follows:

alias browserstack='java -jar ~/Applications/BrowserStackTunnel.ja [KEY_HERE] localhost,3000,0'

I could easily type ´browserstack´ to open up the tunnel to port 3000 on localhost. The only problem with that was that our apps are distributed and therefore running on different ports even locally. I needed a fast way to switch port (altering the parameters of the command).

function bss {
  port=3000
  $(open http://browserstack.com && java -jar ~/Applications/BrowserStackTunnel.jar [KEY_HERE] localhost,${1-$port},0)
}
alias bs=bss

This makes the default port 3000 and enables me to choose port just by passing the port number as an argument right after the command.

Boom, now I can easily just hit bs to launch the BrowserStack tunnel!