Feature request , or question about how if it's already implemented regarding custom commands menu

Asked by Jamie S. on 2016-10-03

Is it possible in the Custom Commands menu to make it setup as a tree with related commands grouped together? Right now I have about 50 commands and they are in a list based on the application they are for or main purpose but I would like to be able to have them show under a sub-menu tree. Like when going to encodings > other encodings where they are in a child menu. If this already exists I'd love to know how and also could the documentation be updated with it as well. I thought maybe it was just a

I was thinking something like instead of this

 general/Check swap usage
 general/Load investigations
 Netstat/Current SSH connections
 Netstat/SSH/Failed SSH logins

I could have

menu option Netstat opens a tree layer with Current SSH connections and Failed SSH logins

menu option general opens Check swap usage and Load investigations as options.

Thank you

Question information

Language:
English Edit question
Status:
Solved
For:
Terminator Edit question
Assignee:
No assignee Edit question
Solved by:
Stephen Boddy
Solved:
2016-10-10
Last query:
2016-10-10
Last reply:
2016-10-08
Jamie S. (jamiesexton35) said : #1

sorry part of the message was missing.

One the line I thought maybe it was just a

I thought maybe it was just a simple delimiter but wasn't able to figure it out or find where it is documented.

Thanks again.

Nope. Currently this is not implemented.

The custom commands are provided as a plugin (<basedir>/terminatorlib/plugins/custom_commands.py). The "simplest" way of doing this would be to decide on a delimiter (i.e. "/") and adjust the code in the callback method to construct the menu tree, creating sub-menus when needed. More complicated would be to "treeify" the config/dialog too, but that might be overkill for this.

This should be raised as a feature request.

Jamie S. (jamiesexton35) said : #3

Thank you for the reply. I will submit as a feature request then. That was
exactly what I needed to know.

On Oct 8, 2016 15:47, "Stephen Boddy" <email address hidden>
wrote:

> Your question #402708 on Terminator changed:
> https://answers.launchpad.net/terminator/+question/402708
>
> Status: Open => Answered
>
> Stephen Boddy proposed the following answer:
> Nope. Currently this is not implemented.
>
> The custom commands are provided as a plugin
> (<basedir>/terminatorlib/plugins/custom_commands.py). The "simplest" way
> of doing this would be to decide on a delimiter (i.e. "/") and adjust
> the code in the callback method to construct the menu tree, creating
> sub-menus when needed. More complicated would be to "treeify" the
> config/dialog too, but that might be overkill for this.
>
> This should be raised as a feature request.
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
> https://answers.launchpad.net/terminator/+question/402708/+
> confirm?answer_id=1
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/terminator/+question/402708
>
> You received this question notification because you asked the question.
>

In fact... it was super simple to do a rough and ready implementation:

=== modified file 'terminatorlib/plugins/custom_commands.py'
--- terminatorlib/plugins/custom_commands.py 2016-06-01 22:34:31 +0000
+++ terminatorlib/plugins/custom_commands.py 2016-10-08 20:19:45 +0000
@@ -58,6 +58,7 @@

     def callback(self, menuitems, menu, terminal):
         """Add our menu items to the menu"""
+ submenus = {}
         item = gtk.MenuItem(_('_Custom Commands'))
         menuitems.append(item)

@@ -77,16 +78,30 @@
             continue
           exe = command['command'].split(' ')[0]
           iconinfo = theme.choose_icon([exe], gtk.ICON_SIZE_MENU, gtk.ICON_LOOKUP_USE_BUILTIN)
+ leaf_name = command['name'].split('/')[-1]
+ branch_names = command['name'].split('/')[:-1]
+ target_submenu = submenu
+ parent_submenu = submenu
+ for idx in range(len(branch_names)):
+ lookup_name = '/'.join(branch_names[0:idx+1])
+ target_submenu = submenus.get(lookup_name, None)
+ if not target_submenu:
+ item = gtk.MenuItem(_(branch_names[idx]))
+ parent_submenu.append(item)
+ target_submenu = gtk.Menu()
+ item.set_submenu(target_submenu)
+ submenus[lookup_name] = target_submenu
+ parent_submenu = target_submenu
           if iconinfo:
             image = gtk.Image()
             image.set_from_icon_name(exe, gtk.ICON_SIZE_MENU)
- menuitem = gtk.ImageMenuItem(command['name'])
+ menuitem = gtk.ImageMenuItem(leaf_name)
             menuitem.set_image(image)
           else:
- menuitem = gtk.MenuItem(command["name"])
+ menuitem = gtk.MenuItem(leaf_name)
           terminals = terminal.terminator.get_target_terms(terminal)
           menuitem.connect("activate", self._execute, {'terminals' : terminals, 'command' : command['command'] })
- submenu.append(menuitem)
+ target_submenu.append(menuitem)

     def _save_config(self):
       config = Config()

Let me know if that does the trick.

Ugh! It trashed the indentation. You should be able to figure it out easily enough. If you raise a feature request, I'll attach it there, where the indentation is preserved.

Jamie S. (jamiesexton35) said : #6

Okay I created an official feature request here https://bugs.launchpad.net/terminator/+bug/1631759. I tried to run the patch against the file with version 0.98-2 on Arch and Kubuntu 16.10 but it's just failing on me.

```
patching file custom_commands.py
Hunk #1 FAILED at 77.
1 out of 1 hunk FAILED -- saving rejects to file custom_commands.py.rej
```

Both with the file I have and the bzr trunk one in terminator/terminatorlib/plugins/custom_commands.py
Maybe I'm just missing something simple though.

Oh I did have another actual question as well. Is their a donation page for terminator?

Thank you!

Jamie S. (jamiesexton35) said : #7

Thanks Stephen Boddy, that solved my question.

Mega (megetron) said : #8

oh no!
when try to patch I go this:
sudo patch -u /usr/lib/python2.7/site-packages/terminatorlib/plugins/custom_commands.py < ~/cc_tree.diff

patching file /usr/lib/python2.7/site-packages/terminatorlib/plugins/custom_commands.py
Hunk #1 FAILED at 58.
Hunk #2 FAILED at 77.
2 out of 2 hunks FAILED -- saving rejects to file /usr/lib/python2.7/site-packages/terminatorlib/plugins/custom_commands.py.rej

So, I edit the changes of the diff file by myself (sudo vi /usr/lib/python2.7/site-packages/terminatorlib/plugins/custom_commands.py)

But the "custom commands" menu in preferences -> plugins disappear.
So I revert the changes but still no menu....I lost my custom commands...what to do?

Mega (megetron) said : #9

oh no!
when try to patch I go this:
sudo patch -u /usr/lib/python2.7/site-packages/terminatorlib/plugins/custom_commands.py < ~/cc_tree.diff

patching file /usr/lib/python2.7/site-packages/terminatorlib/plugins/custom_commands.py
Hunk #1 FAILED at 58.
Hunk #2 FAILED at 77.
2 out of 2 hunks FAILED -- saving rejects to file /usr/lib/python2.7/site-packages/terminatorlib/plugins/custom_commands.py.rej

So, I edit the changes of the diff file by myself (sudo vi /usr/lib/python2.7/site-packages/terminatorlib/plugins/custom_commands.py)

But the "custom commands" menu in preferences -> plugins disappear.
So I revert the changes but still no menu....I lost my custom commands...what to do?