-
Notifications
You must be signed in to change notification settings - Fork 0
/
prompt.py
59 lines (48 loc) · 1.62 KB
/
prompt.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
from __future__ import unicode_literals
from prompt_toolkit.contrib.completers import WordCompleter
from util.GitCompleter import GitCompleter
from prompt_toolkit import prompt
from prompt_toolkit.interface import AbortAction
from prompt_toolkit.styles import style_from_dict
from prompt_toolkit.token import Token
from prompt_toolkit.history import FileHistory
import subprocess
import os
import sys
from os.path import expanduser
import json
cli_style = style_from_dict({
Token.Comment: '#888888 italic',
Token.Keyword: '#ff88ff bold',
Token: '#ff0066'
})
scriptDir=os.path.dirname(os.path.abspath(sys.argv[0]))
with open(os.path.join(scriptDir,'git_command.json'), 'r') as f:
git_command=json.load(f)
cli_completer = GitCompleter(git_command.keys(),meta_dict=git_command,ignore_case=True,sentence=True)
def main():
home = expanduser("~")
git_history = FileHistory(home+'/.git-inter-cli-history')
try:
while True:
text = prompt('$ git ', completer=cli_completer,
style=cli_style,complete_while_typing=True,
mouse_support=True,history=git_history,
on_abort=AbortAction.RETRY)
if text=='q':
while True:
text=prompt('$ ',style=cli_style)
if text=='git':
break
status=subprocess.call(text, shell=True)
elif text=='':
currentBranchName=subprocess.check_output('git rev-parse --abbrev-ref HEAD', shell=True)
currentPath=os.getcwd()
print(currentPath.replace('\n','')+' ('+currentBranchName.replace('\n','')+')')
continue
else:
status=subprocess.call("git " + text, shell=True)
except EOFError:
print('exit')
if __name__ == '__main__':
main()