-
-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathprovider_fileinfo.lua
More file actions
197 lines (176 loc) · 5.29 KB
/
Copy pathprovider_fileinfo.lua
File metadata and controls
197 lines (176 loc) · 5.29 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
local vim = vim
local M = {}
local function file_readonly(readonly_icon)
if vim.bo.filetype == 'help' then
return ''
end
local icon = readonly_icon or ''
if vim.bo.readonly == true then
return " " .. icon .. " "
end
return ''
end
-- get current file name
function M.get_current_file_name(modified_icon, readonly_icon)
local file = vim.fn.expand('%:t')
if vim.fn.empty(file) == 1 then return '' end
if string.len(file_readonly(readonly_icon)) ~= 0 then
return file .. file_readonly(readonly_icon)
end
local icon = modified_icon or ''
if vim.bo.modifiable then
if vim.bo.modified then
return file .. ' ' .. icon .. ' '
end
end
return file .. ' '
end
-- format print current file size
function M.format_file_size(file)
local size = vim.fn.getfsize(file)
if size == 0 or size == -1 or size == -2 then
return ''
end
if size < 1024 then
size = size .. 'b'
elseif size < 1024 * 1024 then
size = string.format('%.1f',size/1024) .. 'k'
elseif size < 1024 * 1024 * 1024 then
size = string.format('%.1f',size/1024/1024) .. 'm'
else
size = string.format('%.1f',size/1024/1024/1024) .. 'g'
end
return size .. ' '
end
function M.get_file_size()
local file = vim.fn.expand('%:p')
if string.len(file) == 0 then return '' end
return M.format_file_size(file)
end
-- get file encode
function M.get_file_encode()
local encode = vim.bo.fenc ~= '' and vim.bo.fenc or vim.o.enc
return ' ' .. encode:upper()
end
-- get file format
-- and cover to upper
function M.get_file_format()
return vim.bo.fileformat:upper()
end
-- show line:column
function M.line_column()
local line = vim.fn.line('.')
local column = vim.fn.col('.')
return string.format("%3d :%2d ", line, column)
end
-- show current line percent of all lines
function M.current_line_percent()
local current_line = vim.fn.line('.')
local total_line = vim.fn.line('$')
if current_line == 1 then
return ' Top '
elseif current_line == vim.fn.line('$') then
return ' Bot '
end
local result,_ = math.modf((current_line/total_line)*100)
return ' '.. result .. '% '
end
local icon_colors = {
Brown = '#905532',
Aqua = '#3AFFDB',
Blue = '#689FB6',
Darkblue = '#44788E',
Purple = '#834F79',
Red = '#AE403F',
Beige = '#F5C06F',
Yellow = '#F09F17',
Orange = '#D4843E',
Darkorange = '#F16529',
Pink = '#CB6F6F',
Salmon = '#EE6E73',
Green = '#8FAA54',
Lightgreen = '#31B53E',
White = '#FFFFFF',
LightBlue = '#5fd7ff',
}
local icons = {
Brown = {''},
Aqua = {''},
LightBlue = {'',''},
Blue = {'','','','','','','','','','','','',''},
Darkblue = {'',''},
Purple = {'','','','',''},
Red = {'','','','','',''},
Beige = {'','',''},
Yellow = {'','','λ','',''},
Orange = {'',''},
Darkorange = {'','','','',''},
Pink = {'',''},
Salmon = {''},
Green = {'','','','','',''},
Lightgreen = {'','','','﵂'},
White = {'','','','','',''},
}
-- filetype or extensions : { colors ,icon}
local user_icons = {}
function M.define_file_icon()
return user_icons
end
local function get_file_info()
return vim.fn.expand('%:t'), vim.fn.expand('%:e')
end
function M.get_file_icon()
local icon = ''
if vim.fn.exists("*WebDevIconsGetFileTypeSymbol") == 1 then
icon = vim.fn.WebDevIconsGetFileTypeSymbol()
return icon .. ' '
end
local ok,devicons = pcall(require,'nvim-web-devicons')
if not ok then print('No icon plugin found. Please install \'kyazdani42/nvim-web-devicons\'') return '' end
local f_name,f_extension = get_file_info()
icon = devicons.get_icon(f_name,f_extension)
if icon == nil then
if user_icons[vim.bo.filetype] ~= nil then
icon = user_icons[vim.bo.filetype][2]
elseif user_icons[f_extension] ~= nil then
icon = user_icons[f_extension][2]
else
icon = ''
end
end
return icon .. ' '
end
function M.get_file_icon_color()
local filetype = vim.bo.filetype
local f_name, f_ext = get_file_info()
if user_icons[filetype] ~= nil then return user_icons[filetype][1] end
if user_icons[f_ext] ~= nil then return user_icons[f_ext][1] end
local has_devicons, devicons = pcall(require, 'nvim-web-devicons')
if has_devicons then
local icon, iconhl = devicons.get_icon(f_name, f_ext)
if icon ~= nil then
return vim.fn.synIDattr(vim.fn.hlID(iconhl), 'fg')
end
end
local icon = M.get_file_icon():match('%S+')
for k, _ in pairs(icons) do
if vim.fn.index(icons[k], icon) ~= -1 then return icon_colors[k] end
end
end
function M.filename_in_special_buffer()
local short_list = require('galaxyline').short_line_list
local fname = M.get_current_file_name()
for _,v in ipairs(short_list) do
if v == vim.bo.filetype then
return ''
end
end
local short_list_buftypes = require('galaxyline').short_list_buftypes
for _,v in ipairs(short_list_buftypes) do
if v == vim.bo.buftype then
return ''
end
end
return fname
end
return M