-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitWorkingFiles.groovy
103 lines (95 loc) · 2.59 KB
/
gitWorkingFiles.groovy
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
92
93
94
95
96
97
98
99
100
101
102
103
def fileList = "git ls-files".execute().text
def submoduleList = "git ls-files --stage | grep 160000".execute().text
def gitBranch = ("git branch".execute().text.readLines().grep {it =~ /^\*/}.collect {
it.replaceAll(/^\* /,'')
}?:[]).first();
def allFiles = new ConfigObject()
def readFiles;
readFiles = {
ConfigObject cfg
}
def debug(String text) {
// println text
}
fileList.readLines().each {
line ->
def path = line.split("/")
//debug path
def cfg = allFiles;
if (path.size() > 1) {
cfg = path[0..-2].inject(allFiles) {
root, dirname ->
//debug ">> $root, $dirname"
root.dir."$dirname"
}
}
def files = (cfg.files?:[])
files << path[-1]
cfg.files = files;
//debug cfg
}
//debug allFiles
String getProtocol(String fileName) {
def ext = fileName.replaceAll(/.*\./,'').toLowerCase();
// println "# ext = $ext"
def extList = ['html': 'file+emacs',
'pdf': 'file+sys',
'dat': 'file+emacs',
'service': 'file+emacs',
'docx': 'file+sys',
'xlsx': 'file+sys',
]
String protocol = extList.containsKey(ext)?extList[ext]:'file'
//println "# protocol=$protocol"
return protocol
};
def printDir(ConfigObject cfg, int level, String dirName, String path) {
debug "# in printDir(${cfg.keySet()}, $level, $dirName, $path)"
debug "cfg=$cfg"
if (cfg.files.size() || cfg.dir.keySet().size() > 1) {
println "${'*' * level} $dirName"
cfg.files.each {
println "- [[${getProtocol(it)}:$path$it][$it]]"
}
debug "# cfg.dir=${cfg.dir.keySet()}"
cfg.dir.keySet().each {
dir ->
debug "# dir=$dir"
def dd = cfg.dir."$dir"
debug "dd=$dd"
printDir(cfg.dir."$dir", level + 1, dir, "$path$dir/")
}
}
else {
cfg.dir.each {
subDirName, dirContents ->
printDir(dirContents, level, "$dirName/$subDirName",
"$path$subDirName/")
}
}
}
def printHeader = {
println """#+TITLE: Working Files
#+STARTUP: content
#+OPTIONS: toc:nil num:nil html-preamble:nil html-postamble:nil ^:{}
""".replaceAll("\r?\n", System.getProperty('line.separator'))
}
def printGitState = {
"""* Git
- current branch :: ${gitBranch}
** Remotes""".readLines().each {
println it
}
// Fetch Remotes
"git config --local -l".execute().text.readLines().grep {
it =~ /^remote\..*\.url/
}.collect {
rm ->
(rm =~ /^remote\.([^.]*)\.url=(.*)/).each {
m -> println "- ${m[1]} :: ${m[2]}"
}
}
}
printHeader()
// printGitState()
printDir(allFiles, 1, "Files", "");