forked from wsdjeg/SpaceVim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.lua
More file actions
276 lines (256 loc) · 6.6 KB
/
file.lua
File metadata and controls
276 lines (256 loc) · 6.6 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
local M = {}
local system = require('spacevim.api').import('system')
local fn = nil
if vim.fn == nil then
fn = require('spacevim').fn
else
fn = vim.fn
end
if system.isWindows then
M.separator = '\\'
M.pathSeparator = ';'
else
M.separator = '/'
M.pathSeparator = ':'
end
local file_node_extensions = {
['styl'] = '',
['scss'] = '',
['htm'] = '',
['html'] = '',
['erb'] = '',
['slim'] = '',
['ejs'] = '',
['wxml'] = '',
['css'] = '',
['less'] = '',
['wxss'] = '',
['md'] = '',
['markdown'] = '',
['json'] = '',
['js'] = '',
['jsx'] = '',
['rb'] = '',
['php'] = '',
['py'] = '',
['pyc'] = '',
['pyo'] = '',
['pyd'] = '',
['coffee'] = '',
['mustache'] = '',
['hbs'] = '',
['conf'] = '',
['ini'] = '',
['yml'] = '',
['bat'] = '',
['jpg'] = '',
['jpeg'] = '',
['bmp'] = '',
['png'] = '',
['gif'] = '',
['ico'] = '',
['twig'] = '',
['cpp'] = '',
['c++'] = '',
['cxx'] = '',
['cc'] = '',
['cp'] = '',
['c'] = '',
['hs'] = '',
['lhs'] = '',
['lua'] = '',
['java'] = '',
['sh'] = '',
['fish'] = '',
['ml'] = 'λ',
['mli'] = 'λ',
['diff'] = '',
['db'] = '',
['sql'] = '',
['dump'] = '',
['clj'] = '',
['cljc'] = '',
['cljs'] = '',
['edn'] = '',
['scala'] = '',
['go'] = '',
['dart'] = '',
['xul'] = '',
['sln'] = '',
['suo'] = '',
['pl'] = '',
['pm'] = '',
['t'] = '',
['rss'] = '',
['f#'] = '',
['fsscript'] = '',
['fsx'] = '',
['fs'] = '',
['fsi'] = '',
['rs'] = '',
['rlib'] = '',
['d'] = '',
['erl'] = '',
['hrl'] = '',
['vim'] = '',
['ai'] = '',
['psd'] = '',
['psb'] = '',
['ts'] = '',
['tsx'] = '',
['jl'] = '',
['ex'] = '',
['exs'] = '',
['eex'] = '',
['leex'] = ''
}
local file_node_exact_matches = {
['exact-match-case-sensitive-1.txt'] = 'X1',
['exact-match-case-sensitive-2'] = 'X2',
['gruntfile.coffee'] = '',
['gruntfile.js'] = '',
['gruntfile.ls'] = '',
['gulpfile.coffee'] = '',
['gulpfile.js'] = '',
['gulpfile.ls'] = '',
['dropbox'] = '',
['.ds_store'] = '',
['.gitconfig'] = '',
['.gitignore'] = '',
['.bashrc'] = '',
['.bashprofile'] = '',
['favicon.ico'] = '',
['license'] = '',
['node_modules'] = '',
['react.jsx'] = '',
['Procfile'] = '',
['.vimrc'] = '',
['mix.lock'] = '',
}
local file_node_pattern_matches = {
['.*jquery.*\\.js$'] = '',
['.*angular.*\\.js$'] = '',
['.*backbone.*\\.js$'] = '',
['.*require.*\\.js$'] = '',
['.*materialize.*\\.js$'] = '',
['.*materialize.*\\.css$'] = '',
['.*mootools.*\\.js$'] = ''
}
function M.fticon(path)
local file = fn.fnamemodify(path, ':t')
if file_node_exact_matches[file] ~= nil then
return file_node_exact_matches[file]
end
for k,v in ipairs(file_node_pattern_matches) do
if fn.match(file, k) ~= -1 then
return v
end
end
local ext = fn.fnamemodify(file, ':e')
if file_node_extensions[ext] ~= nil then
return file_node_extensions[ext]
else
return ''
end
end
function M.read(path)
if fn.filereadable(path) then
return fn.readfile(path, '')
else
return ''
end
end
function M.write(msg, fname)
local flags
if fn.filereadable(fname) == 1 then
flags = 'a'
else
flags = ''
end
fn.writefile({msg}, fname, flags)
end
function M.override(msg, fname)
local flags
if fn.filereadable(fname) == 1 then
flags = 'b'
else
flags = ''
end
fn.writefile({msg}, fname, flags)
end
function M.read(fname)
if fn.filereadable(fname) == 1 then
return fn.readfile(fname, '')
else
return ''
end
end
function M.unify_path(_path, ...)
local mod = select('1', ...)
if mod == nil then
mod = ':p'
end
local path = fn.fnamemodify(_path, mod .. ':gs?[\\\\/]?/?')
if fn.isdirectory(path) == 1 and string.sub(path, -1) ~= '/' then
return path .. '/'
elseif string.sub(_path, -1) == '/' and string.sub(path, -1) ~= '/' then
return path .. '/'
else
return path
end
end
function M.path_to_fname(path)
return fn.substitute(M.unify_path(path), '[\\/:;.]', '_', 'g')
end
function M.findfile(what, where, ...)
-- let old_suffixesadd = &suffixesadd
-- let &suffixesadd = ''
local count = select('1', ...)
if count == nil then
count = 0
end
local file = ''
if fn.filereadable(where) == 1 and fn.isdirectory(where) == 0 then
path = fn.fnamemodify(where, ':h')
else
path = where
end
if count > 0 then
file = fn.findfile(what, fn.escape(path, ' ') .. ';', count)
elseif #{...} == 0 then
file = fn.findfile(what, fn.escape(path, ' ') .. ';')
elseif count == 0 then
file = fn.findfile(what, fn.escape(path, ' ') .. ';', -1)
else
file = fn.get(fn.findfile(what, fn.escape(path, ' ') .. ';', -1), count, '')
end
-- let &suffixesadd = old_suffixesadd
return file
end
function M.finddir(what, where, ...)
-- let old_suffixesadd = &suffixesadd
-- let &suffixesadd = ''
local count = select('1', ...)
if count == nil then
count = 0
end
local path = ''
local file = ''
if fn.filereadable(where) == 1 and fn.isdirectory(where) == 0 then
path = fn.fnamemodify(where, ':h')
else
path = where
end
if count > 0 then
file = fn.finddir(what, fn.escape(path, ' ') .. ';', count)
elseif #{...} == 0 then
file = fn.finddir(what, fn.escape(path, ' ') .. ';')
elseif count == 0 then
file = fn.finddir(what, fn.escape(path, ' ') .. ';', -1)
else
file = fn.get(fn.finddir(what, fn.escape(path, ' ') .. ';', -1), count, '')
end
-- let &suffixesadd = old_suffixesadd
return file
end
return M