#!/usr/bin/env python
'''
ConnMenu: a simple SSH connection menu
Author: Blake Buckalew
Version: 1
Description: A simple console-based SSH connection menu, fed by an INI style configuration file
Usage: Just execute it. Optionally provide a configuration file as an argument.
Dependencies: cursesmenu (pip install curses-menu)

Configuration example:
	;This is a comment
	[Dev]
	devbox:192.168.0.5,username,passw0rd
	[Production]
	prod01:10.10.10.11,user,pass
	prod02:10.10.10.12,user,hunter2
'''
import ConfigParser, sys, subprocess
import os
from pprint import pprint
from cursesmenu import *
from cursesmenu.items import *

exit_string = 'ConnMenu exiting...'

config_file = os.path.expanduser('~/connmenu.conf')

config_file = sys.argv[1] if (len(sys.argv) > 1) else config_file
print config_file
hosts = ConfigParser.ConfigParser()
hosts.optionxform=str # preserve case in conn labels
hosts.read(config_file)

categories = hosts.sections()

#proceed = raw_input('\nPress enter to proceed.')

category_selection = SelectionMenu.get_selection( categories , 'Connection Categories')

try:
	category_name = categories[category_selection]
except IndexError:
    print exit_string
    sys.exit()
	
servers = hosts.items(category_name)

pprint(servers)

#proceed = raw_input('\nPress enter to proceed.')

selection = SelectionMenu.get_selection( [ s[0] for s in servers ] , category_name )

try:
    print servers[selection]
except IndexError:
    print exit_string
    sys.exit()

label = servers[selection][0]

serverconf = servers[selection][1].split(',')
print 'serverconf', serverconf


host = serverconf[0]
username, password = serverconf[1], serverconf[2]

print "Connecting to %s..." % host
command = "ssh '%s' -l %s" % ( host.strip(), username.strip() )
print command

# Launch interactive SSH
subprocess.call(command, shell=True)
print 'ssh exited.', exit_string

@@ -619,16 +619,94 @@
 port *%0A%0A
+# title settings%0Atitle = True # set terminal title to $hostLabel ($username)%0A%0A
 exit_str
@@ -1715,16 +1715,24 @@
 rconf%5B1%5D
+.strip()
 , server
@@ -1739,16 +1739,16 @@
 conf%5B2%5D%0A
-
 %0Aprint %22
@@ -1810,24 +1810,16 @@
 %25 ( host
-.strip()
 , userna
@@ -1824,17 +1824,8 @@
 name
-.strip() 
 )%0Apr
@@ -1837,16 +1837,122 @@
 ommand%0A%0A
+if title:%0A    subprocess.call(%22xtitle %5C%22%25s (%25s)%5C%22%22 %25 (host.split('.')%5B0%5D.strip(), username), shell=True)%0A%0A
 # Launch

Update connmenu.py