Skip to content

Instantly share code, notes, and snippets.

@revans
Created November 30, 2015 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save revans/3f9e6fd2ffde6fd706ff to your computer and use it in GitHub Desktop.
Save revans/3f9e6fd2ffde6fd706ff to your computer and use it in GitHub Desktop.
SSH Config - Open HostNames in a Browser window
#!/usr/bin/env bash
#
# About:
#
# If you use ~/.ssh/config often enough that you cannot remember the URLs
# anymore, but you do know the SSH Host names you gave each SSH entry,
# then this might be helpful. This script will find the Host and open
# the HostName up in a new browser window, using your default browser.
#
# Installation:
#
# 1. Place this file in ~/bin/
# 2. chmod +x ~/bin/ssh-open
# 3. Make sure ~/bin is in your PATH
#
# Usage:
#
# If you have an SSH config host, named apple, then you can do:
#
# ssh-open apple
#
# This will find the URL inside your ~/.ssh/config and open it within your default
# browser.
#
# Gotchas:
#
# 1. Does not handle HTTPS.
# 2. Currently, this does only EXACT matches.
# 3. Test on OSX only, so probably only works on OSX.
# 4. This is a first pass, so it's pretty rough coding.
#
#
set -e
# Set some variables
#
config=$HOME/.ssh/config
search=$1
find_host() {
clear
echo "--> Searching for ${search}..."
host=$(grep -w "Host ${search}" $config | cut -d' ' -f2 | xargs -I '{}' echo -n "{}")
url=$(grep -w -A1 "Host ${search}" $config | cut -d' ' -f4 | xargs -I '{}' echo -n "{}")
echo "--> Found ${host}...Opening in a new browser window..."
open "http://${url}"
}
find_host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment