Skip to content

Instantly share code, notes, and snippets.

@alrayyes alrayyes/ssh-dmenu
Created Jun 1, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.