forked from papajoker/git_terminator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_plugin.py
92 lines (74 loc) · 3.53 KB
/
git_plugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""
Terminator plugin to find git repo.
License: GPLv2
"""
import inspect, os, shlex, subprocess
import gtk
from terminatorlib.util import err, dbg
from terminatorlib import plugin
from terminatorlib import config
AVAILABLE = ['GitPlugin']
class GitPlugin(plugin.MenuItem):
""" Process URLs returned by commands. """
capabilities = ['terminal_menu']
def __init__(self):
plugin.MenuItem.__init__(self)
self.plugin_name = self.__class__.__name__
self.current_path = None
def get_cwd(self):
""" Return current working directory. """
# HACK: Because the current working directory is not available to plugins,
# we need to use the inspect module to climb up the stack to the Terminal
# object and call get_cwd() from there.
for frameinfo in inspect.stack():
frameobj = frameinfo[0].f_locals.get('self')
if frameobj and frameobj.__class__.__name__ == 'Terminal':
return frameobj.get_cwd()
return None
def callback(self, menuitems, menu, terminal):
filepath = self.get_cwd()
gitpath = filepath + '/.git/'
#BUG si ls -l /etc/ suis encore dans home :( filepath pas bon !!
print 'mon dossier: ' + gitpath
if os.path.exists(gitpath):
#item = gtk.MenuItem('Git Status')
#menuitems.append(item)
#item.connect("activate", self._execute, {'terminal' : terminal, 'command' : 'git status' })
#dbg('Menu items git appended')
item = gtk.MenuItem('Git')
menuitems.append(item)
submenu = gtk.Menu()
item.set_submenu(submenu)
menuitem = gtk.MenuItem('Status')
submenu.append(menuitem)
menuitem.connect("activate", self._execute, {'terminal' : terminal, 'command' : 'git status' })
menuitem = gtk.SeparatorMenuItem()
submenu.append(menuitem)
myBranche = subprocess.check_output(['git', 'symbolic-ref','HEAD', '--short'])
menuitem = gtk.MenuItem('Branches')
submenu.append(menuitem)
#menuitem.connect("activate", self._execute, {'terminal' : terminal, 'command' : 'git branch -a' })
myBranches = subprocess.check_output(['git', 'branch']).split('\n')
ssubmenu = gtk.Menu()
menuitem.set_submenu(ssubmenu)
for element in myBranches:
if len(element)>1:
smenuitem = gtk.MenuItem(element)
ssubmenu.append(smenuitem)
smenuitem.connect("activate", self._execute, {'terminal' : terminal, 'command' : 'git checkout '+element.replace('* ','') })
menuitem = gtk.SeparatorMenuItem()
ssubmenu.append(menuitem)
menuitem = gtk.MenuItem('List Branches')
ssubmenu.append(menuitem)
menuitem.connect("activate", self._execute, {'terminal' : terminal, 'command' : 'git branch -a' })
menuitem = gtk.MenuItem('Logs')
menuitem.connect("activate", self._execute, {'terminal' : terminal, 'command' : 'git log --oneline -n 6' })
submenu.append(menuitem)
else:
dbg('Menu items git remove')
def _execute(self, _widget, data):
command = data['command']+"\n"
terminal = data['terminal']
#print 'exec: ? ' + command
terminal.feed(command)
return command