-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvgit
More file actions
executable file
·80 lines (57 loc) · 1.8 KB
/
vgit
File metadata and controls
executable file
·80 lines (57 loc) · 1.8 KB
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
#!/usr/bin/env python3
import os.path
import sys
import subprocess
from visidata import Sheet, Column, ColumnAttr, Path, ENTER, asyncthread, vd, TextSheet
from visidata import *
import git
__version__ = 'v0.4-dev'
__version_info__ = 'saul.pw/vgit ' + __version__
#vd.option('config', '~/.vgitrc', 'config file to exec in Python')
vd.options.motd_url = 'https://visidata.org/vgit/motd-' + __version__
vd.option('vgit_pager', False, 'fallback to pager instead of passthrough')
@VisiData.api
def git_log(vd, args, topsheet):
return git.GitLogSheet(topsheet.branch+"_log", ref=topsheet.branch, source=topsheet)
@VisiData.api
def git_status(vd, args, topsheet):
return git.GitStatus(topsheet.source)
@VisiData.api
def git_blame(vd, args, topsheet):
return git.GitBlame(GitFile(args[0]), source=topsheet)
@VisiData.api
def git_grep(vd, args, topsheet):
return git.GitGrep(args[0], regex=args[0], source=topsheet)
def somegit(args=None):
cwd = Path('.')
if cwd.joinpath('.git').exists() or git.getRepoPath(cwd):
top = git.GitStatus(cwd)
else:
top = git.GitOverview('gitrepos', source=cwd)
if not args:
return top
cmd = args[0]
funcname = 'git_'+args[0]
func = getattr(vd, funcname, None)
if func:
return func(args[1:], top)
else:
print(f"no {funcname}")
def main():
args = sys.argv[1:]
vd.loadConfigAndPlugins()
vs = somegit(args)
print(vs)
if vs is None:
if vd.options.vgit_pager:
cmdstr = ' '.join(args)
vs = TextSheet(cmdstr, source=somegit().git_lines(*args))
else:
return subprocess.run(['git', *args]).returncode
vd.domotd()
vd.run(vs)
vd.addGlobals(globals())
if __name__ == '__main__':
vd.status(__version_info__)
rc = main()
sys.exit(rc)