finally fixed crussh up
This commit is contained in:
parent
a84fa83cf2
commit
07b0d31543
76
crussh.py
76
crussh.py
@ -12,21 +12,20 @@ from gi.repository import GLib as glib
|
||||
from gi.repository.Pango import FontDescription
|
||||
gi.require_version('Vte', '2.91')
|
||||
from gi.repository import Vte as vte
|
||||
import sys
|
||||
import math
|
||||
import json
|
||||
import yaml
|
||||
import os.path
|
||||
from EntryDialog import EntryDialog
|
||||
from collections import OrderedDict
|
||||
|
||||
|
||||
### Config Dialog ###
|
||||
# Config Dialog #
|
||||
class CruSSHConf:
|
||||
### State Vars ###
|
||||
# State Vars #
|
||||
Config = {}
|
||||
MainWin = gtk.Window()
|
||||
|
||||
### Signal Hooks ###
|
||||
# Signal Hooks #
|
||||
def save_hook(self, discard, save_func):
|
||||
self.MainWin.destroy()
|
||||
if save_func is not None:
|
||||
@ -44,7 +43,7 @@ class CruSSHConf:
|
||||
def maximized_hook(self, checkbutton):
|
||||
self.Config["start-maximized"] = checkbutton.get_active()
|
||||
|
||||
### GUI Objects ###
|
||||
# GUI Objects #
|
||||
def initGUI(self, save_func=None):
|
||||
self.MainWin.set_modal(True)
|
||||
|
||||
@ -115,7 +114,7 @@ class CruSSHConf:
|
||||
self.initGUI(save_func)
|
||||
|
||||
|
||||
### Hosts Mask Dialog ###
|
||||
# Hosts Mask Dialog #
|
||||
class HostsMask:
|
||||
Terminals = {}
|
||||
MainWin = gtk.Window()
|
||||
@ -151,7 +150,7 @@ class HostsMask:
|
||||
HostCheckbox = gtk.CheckButton()
|
||||
HostCheckbox.set_active(self.Terminals[host].copy_input)
|
||||
HostCheckbox.connect("toggled", self.toggle_func, host)
|
||||
HostTable.attach(HostCheckbox, 1, 2, 0, 1,gtk.AttachOptions.EXPAND, gtk.AttachOptions.EXPAND, 0, 0)
|
||||
HostTable.attach(HostCheckbox, 1, 2, 0, 1, gtk.AttachOptions.EXPAND, gtk.AttachOptions.EXPAND, 0, 0)
|
||||
row = i / cols
|
||||
col = i % cols
|
||||
HostsConfTable.attach(HostTable, col, col+1, row, row+1, gtk.AttachOptions.EXPAND, gtk.AttachOptions.EXPAND, 0, 0)
|
||||
@ -173,9 +172,9 @@ class HostsMask:
|
||||
self.InitGUI()
|
||||
|
||||
|
||||
### CruSSH! ###
|
||||
# CruSSH! #
|
||||
class CruSSH:
|
||||
### Config Vars ###
|
||||
# Config Vars #
|
||||
# config defaults
|
||||
Config = {
|
||||
"min-width": 80,
|
||||
@ -184,19 +183,19 @@ class CruSSH:
|
||||
"start-maximized": True
|
||||
}
|
||||
|
||||
### State Vars ###
|
||||
# State Vars #
|
||||
Terminals = OrderedDict()
|
||||
TermMinWidth = 1
|
||||
TermMinHeight = 1
|
||||
|
||||
### GUI Objects ###
|
||||
# GUI Objects #
|
||||
MainWin = gtk.Window()
|
||||
ScrollWin = gtk.ScrolledWindow()
|
||||
LayoutTable = gtk.Table()
|
||||
EntryBox = gtk.Entry()
|
||||
Clipboard = gtk.Clipboard()
|
||||
|
||||
### Methods ###
|
||||
# Methods #
|
||||
def reflowTable(self, cols=1, rows=1):
|
||||
# empty table and re-size
|
||||
hosts = list(self.Terminals.keys())
|
||||
@ -245,15 +244,15 @@ class CruSSH:
|
||||
|
||||
# check for paste key shortcut (ctl-shift-v)
|
||||
if (event.type == gdk.EventType.KEY_PRESS) \
|
||||
and (event.state & gdk.ModifierType.CONTROL_MASK == gdk.ModifierType.CONTROL_MASK) \
|
||||
and (event.state & gdk.ModifierType.SHIFT_MASK == gdk.ModifierType.SHIFT_MASK) \
|
||||
and (event.keyval == gdk.keyval_from_name('V')):
|
||||
and (event.state & gdk.ModifierType.CONTROL_MASK == gdk.ModifierType.CONTROL_MASK) \
|
||||
and (event.state & gdk.ModifierType.SHIFT_MASK == gdk.ModifierType.SHIFT_MASK) \
|
||||
and (event.keyval == gdk.keyval_from_name('V')):
|
||||
widget.paste_clipboard()
|
||||
return True
|
||||
elif (event.type == gdk.EventType.KEY_PRESS) \
|
||||
and (event.state & gdk.ModifierType.CONTROL_MASK == gdk.ModifierType.CONTROL_MASK) \
|
||||
and (event.state & gdk.ModifierType.SHIFT_MASK == gdk.ModifierType.SHIFT_MASK) \
|
||||
and (event.keyval == gdk.keyval_from_name('C')):
|
||||
and (event.state & gdk.ModifierType.CONTROL_MASK == gdk.ModifierType.CONTROL_MASK) \
|
||||
and (event.state & gdk.ModifierType.SHIFT_MASK == gdk.ModifierType.SHIFT_MASK) \
|
||||
and (event.keyval == gdk.keyval_from_name('C')):
|
||||
widget.copy_clipboard()
|
||||
return True
|
||||
terminal = vte.Terminal()
|
||||
@ -348,13 +347,10 @@ class CruSSH:
|
||||
self.Config = new_config
|
||||
self.reflow(force=True)
|
||||
# save to file last, so it doesn't hold up other GUI actions
|
||||
conf_json = json.dumps(self.Config, sort_keys=True, indent=4)
|
||||
try:
|
||||
conf_file = open(os.path.expanduser("~/.crusshrc"), 'w')
|
||||
conf_file.write(conf_json)
|
||||
conf_file.close()
|
||||
except:
|
||||
pass
|
||||
conf_yaml = yaml.dump(self.Config, sort_keys=True, indent=4)
|
||||
conf_file = open(os.path.expanduser("~/.config/crussh.yml"), 'w')
|
||||
conf_file.write(conf_yaml)
|
||||
conf_file.close()
|
||||
PrefsItem.connect("activate", lambda discard: CruSSHConf(self.Config, save_func))
|
||||
EditMenu.append(PrefsItem)
|
||||
MainMenuBar.append(EditItem)
|
||||
@ -389,8 +385,8 @@ class CruSSH:
|
||||
if (event.type == gdk.EventType.KEY_PRESS) \
|
||||
and (event.state & gdk.ModifierType.CONTROL_MASK == gdk.ModifierType.CONTROL_MASK) \
|
||||
and (event.state & gdk.ModifierType.SHIFT_MASK == gdk.ModifierType.SHIFT_MASK) \
|
||||
and (event.get_keyval == gdk.keyval_from_name('V')):
|
||||
feed_paste(widget)
|
||||
and (event.get_keyval == gdk.keyval_from_name('V')):
|
||||
feed_paste(widget)
|
||||
else:
|
||||
# propagate to every terminal
|
||||
for host in self.Terminals:
|
||||
@ -423,9 +419,10 @@ class CruSSH:
|
||||
# load existing config file, if present
|
||||
try:
|
||||
# merge dicts to allow upgrade from old configs
|
||||
new_config = json.load(open(os.path.expanduser('~/.crusshrc')))
|
||||
self.Config.update(new_config)
|
||||
except:
|
||||
new_config = yaml.safe_load(open(os.path.expanduser('~/.config/crussh.yml')))
|
||||
if new_config is not None:
|
||||
self.Config.update(new_config)
|
||||
except (FileNotFoundError, yaml.scanner.ScannerError):
|
||||
pass
|
||||
|
||||
# init all terminals
|
||||
@ -446,15 +443,15 @@ class CruSSH:
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
|
||||
### Parse CLI Args ###
|
||||
# Parse CLI Args #
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Connect to multiple hosts in parallel.",
|
||||
usage="%(prog)s [OPTIONS] [--] HOST [HOST ...]",
|
||||
epilog="* NOTE: options before '--' will be passed directly to the SSH client.")
|
||||
parser.add_argument("--ssh", "-s", dest='ssh', default="/usr/bin/ssh",
|
||||
help="specify the SSH executable to use (default: %(default)s)")
|
||||
help="specify the SSH executable to use (default: %(default)s)")
|
||||
parser.add_argument("--hosts-file", "-f", dest='hosts_file', default="",
|
||||
help="A file containing a list of hosts to connect to.")
|
||||
help="A file containing a list of hosts to connect to.")
|
||||
(args, hosts) = parser.parse_known_args()
|
||||
|
||||
# load hosts from file, if available
|
||||
@ -469,12 +466,13 @@ if __name__ == "__main__":
|
||||
|
||||
try:
|
||||
offset = hosts.index("--")
|
||||
except:
|
||||
ssh_args = hosts[0:offset]
|
||||
except ValueError:
|
||||
offset = -1
|
||||
ssh_args = []
|
||||
else:
|
||||
ssh_args = " ".join(hosts[0:offset])
|
||||
hosts = hosts[offset + 1:]
|
||||
|
||||
### Start Execution ###
|
||||
hosts = hosts[offset + 1:]
|
||||
|
||||
# Start Execution #
|
||||
crussh = CruSSH(hosts, args.ssh, ssh_args)
|
||||
gtk.main()
|
||||
|
Loading…
Reference in New Issue
Block a user