diff --git a/README.md b/README.md new file mode 100644 index 0000000..8989442 --- /dev/null +++ b/README.md @@ -0,0 +1,60 @@ +# AppLauncher + +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. + +## Installation + +1. Put files in `~/.config/terminator/plugins/`: + + mkdir -p ~/.config/terminator/plugins + cp applauncher.py ~/.config/terminator/plugins/ + cp projects.py ~/.config/terminator/plugins/ + +2. Restart [Terminator](http://www.tenshu.net/p/terminator.html), go to `Context menu > Preferences > Plugins` and select `AppLauncher`. + +## Setup + +1. Edit `~/.config/terminator/plugins/projects.py`, example: + + :::python + PROJECTS = {"Project 1": {"split": "vert", + "terminal1": {"split": "horiz", + "terminal1": {"commands": ["dir"], + }, + "terminal2": {"commands": ["ls"], + } + }, + "terminal2": {"commands": ["dir"], + }, + }, + "Project 2": {"enabled": False, + "split": "vert", + "terminal1": {"split": "horiz", + "terminal1": {"commands": ["command 1", + "command 2", + "command 3"], + }, + "terminal2": {"commands": ["command"], + } + }, + "terminal2": {"split": "horiz", + "terminal1": {"commands": ["command"], + }, + "terminal2": {"commands": ["command"], + } + }, + }, + "Project 3": {"commands": ["history", ] } + } + + EDITOR = "gedit" + +2. Restart Terminator. + +## Use + +* Go to `Context menu > AppLauncher`, and select your project. + +## Autor + +* Guido Castillo Gómez <[gcasgo@gmail.com](https://plus.google.com/116701415230747107577)> diff --git a/applauncher.py b/applauncher.py new file mode 100644 index 0000000..ed05449 --- /dev/null +++ b/applauncher.py @@ -0,0 +1,104 @@ +#!/usr/bin/python +# Written by Guido Castillo Gomez +# GPL v2 only + +import os +import gtk +import terminatorlib.plugin as plugin +from terminatorlib.translation import _ + +try: + from projects import PROJECTS +except ImportError: + PROJECTS = {} + +try: + from projects import EDITOR +except ImportError: + EDITOR = "gedit" + +AVAILABLE = ['AppLauncher'] + + +class AppLauncher(plugin.Plugin): + capabilities = ['terminal_menu'] + + def callback(self, menuitems, menu, terminal): + """Add our menu item to the menu""" + + item = gtk.MenuItem('AppLauncher') + menuitems.append(item) + + submenu = gtk.Menu() + item.set_submenu(submenu) + + projects = PROJECTS.keys() + projects.sort() + for project in projects: + if not PROJECTS[project].get('enabled', True): + continue + menuitem = gtk.MenuItem(project) + menuitem.connect("activate", self.launch_project, terminal, project) + submenu.append(menuitem) + + menuitem = gtk.SeparatorMenuItem() + submenu.append(menuitem) + + menuitem = gtk.ImageMenuItem(gtk.STOCK_PREFERENCES) + menuitem.connect("activate", self.configure) + submenu.append(menuitem) + + #if config.has_key("default"): + # self.launch_project("widget", terminal, DEFAULT_PROJECT) + + def launch_project(self, widget, terminal, project): + + if PROJECTS.has_key(project): + + focussed_terminal = None + widget_win = terminal.terminator.windows[0] + widget_win.set_maximised(True) + widget_win.tab_new(widget_win.get_focussed_terminal()) + visible_terminals = widget_win.get_visible_terminals() + for visible_terminal in visible_terminals: + if visible_terminal.vte.is_focus(): + focussed_terminal = visible_terminal + + project_config = PROJECTS[project] + self.split_terminal(focussed_terminal, project_config, widget_win) + + def split_terminal(self, terminal, terminal_config, window): + self.execute_command(terminal, terminal_config.get('commands')) + + if terminal_config.has_key('split'): + visible_terminals_temp = window.get_visible_terminals() + if terminal_config['split'].lower().count("vert"): + terminal.key_split_vert() + else: + terminal.key_split_horiz() + visible_terminals = window.get_visible_terminals() + + for visible_terminal in visible_terminals: + if not visible_terminal in visible_terminals_temp: + terminal2 = visible_terminal + + if terminal_config.has_key('terminal1'): + self.split_terminal(terminal, terminal_config['terminal1'], window) + if terminal_config.has_key('terminal2'): + self.split_terminal(terminal2, terminal_config['terminal2'], window) + + def execute_command(self, terminal, command): + if command: + if isinstance(command, list): + command = "\n".join(command) + else: + command = command + if command[len(command)-1] != '\n': + command = command + '\n' + terminal.vte.feed_child(command) + + def configure(self, widget): + filename = os.path.realpath(os.path.join(os.path.dirname(__file__), 'projects.py')) + editor = os.getenv('EDITOR') or EDITOR + os.system('%s %s' % (editor, filename)) + diff --git a/projects.py b/projects.py new file mode 100644 index 0000000..bc43d81 --- /dev/null +++ b/projects.py @@ -0,0 +1,32 @@ +PROJECTS = {"Project 1": {"split": "vert", + "terminal1": {"split": "horiz", + "terminal1": {"commands": ["dir"], + }, + "terminal2": {"commands": ["ls"], + } + }, + "terminal2": {"commands": ["dir"], + }, + }, + "Project 2": {"enabled": False, + "split": "vert", + "terminal1": {"split": "horiz", + "terminal1": {"commands": ["command 1", + "command 2", + "command 3"], + }, + "terminal2": {"commands": ["command"], + } + }, + "terminal2": {"split": "horiz", + "terminal1": {"commands": ["command"], + }, + "terminal2": {"commands": ["command"], + } + }, + }, + "Project 3": {"commands": ["history", ] } + } + +EDITOR = "gedit" +