Commit e0ea6dd8a89bb6a0b8afae8da429af86810fb8ca
0 parents
Exists in
master
Clone de terminator-applauncher
plugin para terminator
Showing
3 changed files
with
196 additions
and
0 deletions
 
Show diff stats
README.md
| File was created | 1 | # AppLauncher | |
| 2 | |||
| 3 | I want to share this plugin, I use [Terminator](http://www.tenshu.net/p/terminator.html), and every time I wanted to set up my development environment, I had to launch Terminator and execute the commands needed. In order to avoid this repetitive sequence, I decided to write a plugin that, with just one click, launches Terminator, creates divisions in it, and executes the commands needed for every project. | ||
| 4 | |||
| 5 | ## Installation | ||
| 6 | |||
| 7 | 1. Put files in `~/.config/terminator/plugins/`: | ||
| 8 | |||
| 9 | mkdir -p ~/.config/terminator/plugins | ||
| 10 | cp applauncher.py ~/.config/terminator/plugins/ | ||
| 11 | cp projects.py ~/.config/terminator/plugins/ | ||
| 12 | |||
| 13 | 2. Restart [Terminator](http://www.tenshu.net/p/terminator.html), go to `Context menu > Preferences > Plugins` and select `AppLauncher`. | ||
| 14 | |||
| 15 | ## Setup | ||
| 16 | |||
| 17 | 1. Edit `~/.config/terminator/plugins/projects.py`, example: | ||
| 18 | |||
| 19 | :::python | ||
| 20 | PROJECTS = {"Project 1": {"split": "vert", | ||
| 21 | "terminal1": {"split": "horiz", | ||
| 22 | "terminal1": {"commands": ["dir"], | ||
| 23 | }, | ||
| 24 | "terminal2": {"commands": ["ls"], | ||
| 25 | } | ||
| 26 | }, | ||
| 27 | "terminal2": {"commands": ["dir"], | ||
| 28 | }, | ||
| 29 | }, | ||
| 30 | "Project 2": {"enabled": False, | ||
| 31 | "split": "vert", | ||
| 32 | "terminal1": {"split": "horiz", | ||
| 33 | "terminal1": {"commands": ["command 1", | ||
| 34 | "command 2", | ||
| 35 | "command 3"], | ||
| 36 | }, | ||
| 37 | "terminal2": {"commands": ["command"], | ||
| 38 | } | ||
| 39 | }, | ||
| 40 | "terminal2": {"split": "horiz", | ||
| 41 | "terminal1": {"commands": ["command"], | ||
| 42 | }, | ||
| 43 | "terminal2": {"commands": ["command"], | ||
| 44 | } | ||
| 45 | }, | ||
| 46 | }, | ||
| 47 | "Project 3": {"commands": ["history", ] } | ||
| 48 | } | ||
| 49 | |||
| 50 | EDITOR = "gedit" | ||
| 51 | |||
| 52 | 2. Restart Terminator. | ||
| 53 | |||
| 54 | ## Use | ||
| 55 | |||
| 56 | * Go to `Context menu > AppLauncher`, and select your project. | ||
| 57 | |||
| 58 | ## Autor | ||
| 59 | |||
| 60 | * Guido Castillo Gómez <[gcasgo@gmail.com](https://plus.google.com/116701415230747107577)> | ||
| 61 | 
applauncher.py
| File was created | 1 | #!/usr/bin/python | |
| 2 | # Written by Guido Castillo Gomez <gcasgo@gmail.com> | ||
| 3 | # GPL v2 only | ||
| 4 | |||
| 5 | import os | ||
| 6 | import gtk | ||
| 7 | import terminatorlib.plugin as plugin | ||
| 8 | from terminatorlib.translation import _ | ||
| 9 | |||
| 10 | try: | ||
| 11 | from projects import PROJECTS | ||
| 12 | except ImportError: | ||
| 13 | PROJECTS = {} | ||
| 14 | |||
| 15 | try: | ||
| 16 | from projects import EDITOR | ||
| 17 | except ImportError: | ||
| 18 | EDITOR = "gedit" | ||
| 19 | |||
| 20 | AVAILABLE = ['AppLauncher'] | ||
| 21 | |||
| 22 | |||
| 23 | class AppLauncher(plugin.Plugin): | ||
| 24 | capabilities = ['terminal_menu'] | ||
| 25 | |||
| 26 | def callback(self, menuitems, menu, terminal): | ||
| 27 | """Add our menu item to the menu""" | ||
| 28 | |||
| 29 | item = gtk.MenuItem('AppLauncher') | ||
| 30 | menuitems.append(item) | ||
| 31 | |||
| 32 | submenu = gtk.Menu() | ||
| 33 | item.set_submenu(submenu) | ||
| 34 | |||
| 35 | projects = PROJECTS.keys() | ||
| 36 | projects.sort() | ||
| 37 | for project in projects: | ||
| 38 | if not PROJECTS[project].get('enabled', True): | ||
| 39 | continue | ||
| 40 | menuitem = gtk.MenuItem(project) | ||
| 41 | menuitem.connect("activate", self.launch_project, terminal, project) | ||
| 42 | submenu.append(menuitem) | ||
| 43 | |||
| 44 | menuitem = gtk.SeparatorMenuItem() | ||
| 45 | submenu.append(menuitem) | ||
| 46 | |||
| 47 | menuitem = gtk.ImageMenuItem(gtk.STOCK_PREFERENCES) | ||
| 48 | menuitem.connect("activate", self.configure) | ||
| 49 | submenu.append(menuitem) | ||
| 50 | |||
| 51 | #if config.has_key("default"): | ||
| 52 | # self.launch_project("widget", terminal, DEFAULT_PROJECT) | ||
| 53 | |||
| 54 | def launch_project(self, widget, terminal, project): | ||
| 55 | |||
| 56 | if PROJECTS.has_key(project): | ||
| 57 | |||
| 58 | focussed_terminal = None | ||
| 59 | widget_win = terminal.terminator.windows[0] | ||
| 60 | widget_win.set_maximised(True) | ||
| 61 | widget_win.tab_new(widget_win.get_focussed_terminal()) | ||
| 62 | visible_terminals = widget_win.get_visible_terminals() | ||
| 63 | for visible_terminal in visible_terminals: | ||
| 64 | if visible_terminal.vte.is_focus(): | ||
| 65 | focussed_terminal = visible_terminal | ||
| 66 | |||
| 67 | project_config = PROJECTS[project] | ||
| 68 | self.split_terminal(focussed_terminal, project_config, widget_win) | ||
| 69 | |||
| 70 | def split_terminal(self, terminal, terminal_config, window): | ||
| 71 | self.execute_command(terminal, terminal_config.get('commands')) | ||
| 72 | |||
| 73 | if terminal_config.has_key('split'): | ||
| 74 | visible_terminals_temp = window.get_visible_terminals() | ||
| 75 | if terminal_config['split'].lower().count("vert"): | ||
| 76 | terminal.key_split_vert() | ||
| 77 | else: | ||
| 78 | terminal.key_split_horiz() | ||
| 79 | visible_terminals = window.get_visible_terminals() | ||
| 80 | |||
| 81 | for visible_terminal in visible_terminals: | ||
| 82 | if not visible_terminal in visible_terminals_temp: | ||
| 83 | terminal2 = visible_terminal | ||
| 84 | |||
| 85 | if terminal_config.has_key('terminal1'): | ||
| 86 | self.split_terminal(terminal, terminal_config['terminal1'], window) | ||
| 87 | if terminal_config.has_key('terminal2'): | ||
| 88 | self.split_terminal(terminal2, terminal_config['terminal2'], window) | ||
| 89 | |||
| 90 | def execute_command(self, terminal, command): | ||
| 91 | if command: | ||
| 92 | if isinstance(command, list): | ||
| 93 | command = "\n".join(command) | ||
| 94 | else: | ||
| 95 | command = command | ||
| 96 | if command[len(command)-1] != '\n': | ||
| 97 | command = command + '\n' | ||
| 98 | terminal.vte.feed_child(command) | ||
| 99 | |||
| 100 | def configure(self, widget): | ||
| 101 | filename = os.path.realpath(os.path.join(os.path.dirname(__file__), 'projects.py')) | ||
| 102 | editor = os.getenv('EDITOR') or EDITOR | ||
| 103 | os.system('%s %s' % (editor, filename)) | ||
| 104 | |||
| 105 | 
projects.py
| File was created | 1 | PROJECTS = {"Project 1": {"split": "vert", | |
| 2 | "terminal1": {"split": "horiz", | ||
| 3 | "terminal1": {"commands": ["dir"], | ||
| 4 | }, | ||
| 5 | "terminal2": {"commands": ["ls"], | ||
| 6 | } | ||
| 7 | }, | ||
| 8 | "terminal2": {"commands": ["dir"], | ||
| 9 | }, | ||
| 10 | }, | ||
| 11 | "Project 2": {"enabled": False, | ||
| 12 | "split": "vert", | ||
| 13 | "terminal1": {"split": "horiz", | ||
| 14 | "terminal1": {"commands": ["command 1", | ||
| 15 | "command 2", | ||
| 16 | "command 3"], | ||
| 17 | }, | ||
| 18 | "terminal2": {"commands": ["command"], | ||
| 19 | } | ||
| 20 | }, | ||
| 21 | "terminal2": {"split": "horiz", | ||
| 22 | "terminal1": {"commands": ["command"], | ||
| 23 | }, | ||
| 24 | "terminal2": {"commands": ["command"], | ||
| 25 | } | ||
| 26 | }, | ||
| 27 | }, | ||
| 28 | "Project 3": {"commands": ["history", ] } | ||
| 29 | } | ||
| 30 | |||
| 31 | EDITOR = "gedit" | ||
| 32 | |||
| 33 |