Skip to content

Instantly share code, notes, and snippets.

@alrayyes
Created June 1, 2019 11:42
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 alrayyes/e7ea71658d495058c171c00732bc7955 to your computer and use it in GitHub Desktop.
Save alrayyes/e7ea71658d495058c171c00732bc7955 to your computer and use it in GitHub Desktop.
A little dmenu script I made to handle ssh connections
#!/bin/bash
# get hostnames from ~/.ssh/known_hosts
ssh_host="$(awk -F "[ ,]+" '{print $1}' ~/.ssh/known_hosts | tr -d '[]' | uniq | sort -n | dmenu)"
# split hostnames into array { hostname, port }
mapfile -t params < <(echo "$ssh_host" | awk -F ":" '{print $1} {if ($2) print $2}')
if [ -n "$ssh_host" ]; then
# If array size is two then second parameter is port number
if [ ${#params[@]} -eq 2 ]; then
$TERMINAL -e ssh "${params[0]}" -p "${params[1]}"
else
$TERMINAL -e ssh "${params[0]}"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment