Use ~ for HOME directory in folder search
This commit is contained in:
parent
03e95b2cc3
commit
35c87462a6
|
@ -7,6 +7,33 @@ local LogView = require "core.logview"
|
||||||
|
|
||||||
local fullscreen = false
|
local fullscreen = false
|
||||||
|
|
||||||
|
local function home_encode(paths)
|
||||||
|
if not HOME then return paths end
|
||||||
|
local home = HOME
|
||||||
|
local t = {}
|
||||||
|
local n = #home
|
||||||
|
for i = 1, #paths do
|
||||||
|
if paths[i]:sub(1, n) == home and paths[i]:sub(n + 1, n + 1):match("[/\\\\]") then
|
||||||
|
t[i] = "~" .. paths[i]:sub(#home + 1)
|
||||||
|
else
|
||||||
|
t[i] = paths[i]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
local function home_expand(text)
|
||||||
|
if HOME then
|
||||||
|
return text:gsub("^~", HOME)
|
||||||
|
end
|
||||||
|
return text
|
||||||
|
end
|
||||||
|
|
||||||
|
local function suggest_directory(text)
|
||||||
|
text = home_expand(text)
|
||||||
|
return home_encode(text == "" and core.recent_projects or common.dir_path_suggest(text))
|
||||||
|
end
|
||||||
|
|
||||||
command.add(nil, {
|
command.add(nil, {
|
||||||
["core:quit"] = function()
|
["core:quit"] = function()
|
||||||
core.quit()
|
core.quit()
|
||||||
|
@ -126,6 +153,7 @@ command.add(nil, {
|
||||||
|
|
||||||
["core:change-project-folder"] = function()
|
["core:change-project-folder"] = function()
|
||||||
core.command_view:enter("Change Project Folder", function(text)
|
core.command_view:enter("Change Project Folder", function(text)
|
||||||
|
text = home_expand (text)
|
||||||
local path_stat = system.get_file_info(text)
|
local path_stat = system.get_file_info(text)
|
||||||
if not path_stat or path_stat.type ~= 'dir' then
|
if not path_stat or path_stat.type ~= 'dir' then
|
||||||
core.error("Cannot open folder %q", text)
|
core.error("Cannot open folder %q", text)
|
||||||
|
@ -134,21 +162,18 @@ command.add(nil, {
|
||||||
if core.confirm_close_all() then
|
if core.confirm_close_all() then
|
||||||
core.open_folder_project(text)
|
core.open_folder_project(text)
|
||||||
end
|
end
|
||||||
end, function(text)
|
end, suggest_directory)
|
||||||
return text == "" and core.recent_projects or common.dir_path_suggest(text)
|
|
||||||
end)
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["core:open-project-folder"] = function()
|
["core:open-project-folder"] = function()
|
||||||
core.command_view:enter("Open Project", function(text)
|
core.command_view:enter("Open Project", function(text)
|
||||||
|
text = home_expand (text)
|
||||||
local path_stat = system.get_file_info(text)
|
local path_stat = system.get_file_info(text)
|
||||||
if not path_stat or path_stat.type ~= 'dir' then
|
if not path_stat or path_stat.type ~= 'dir' then
|
||||||
core.error("Cannot open folder %q", text)
|
core.error("Cannot open folder %q", text)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
system.exec(string.format("%q %q", EXEFILE, text))
|
system.exec(string.format("%q %q", EXEFILE, text))
|
||||||
end, function(text)
|
end, suggest_directory)
|
||||||
return text == "" and core.recent_projects or common.dir_path_suggest(text)
|
|
||||||
end)
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
|
@ -132,14 +132,12 @@ init_lua:
|
||||||
" DATADIR = prefix and (prefix .. '/share/lite-xl') or (EXEDIR .. '/data')\n"
|
" DATADIR = prefix and (prefix .. '/share/lite-xl') or (EXEDIR .. '/data')\n"
|
||||||
" end\n"
|
" end\n"
|
||||||
#endif
|
#endif
|
||||||
" do\n"
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
" local home = os.getenv('USERPROFILE')\n"
|
" HOME = os.getenv('USERPROFILE')"
|
||||||
#else
|
#else
|
||||||
" local home = os.getenv('HOME')\n"
|
" HOME = os.getenv('HOME')"
|
||||||
#endif
|
#endif
|
||||||
" USERDIR = home and (home .. '/.config/lite-xl') or (EXEDIR .. '/user')\n"
|
" USERDIR = HOME and (HOME .. '/.config/lite-xl') or (EXEDIR .. '/user')\n"
|
||||||
" end\n"
|
|
||||||
" package.path = package.path .. ';' .. USERDIR .. '/?.lua'\n"
|
" package.path = package.path .. ';' .. USERDIR .. '/?.lua'\n"
|
||||||
" package.path = package.path .. ';' .. USERDIR .. '/?/init.lua'\n"
|
" package.path = package.path .. ';' .. USERDIR .. '/?/init.lua'\n"
|
||||||
" package.path = DATADIR .. '/?.lua;' .. package.path\n"
|
" package.path = DATADIR .. '/?.lua;' .. package.path\n"
|
||||||
|
|
Loading…
Reference in New Issue