diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua index cf904ccf..404642c3 100644 --- a/data/core/commands/core.lua +++ b/data/core/commands/core.lua @@ -7,6 +7,33 @@ local LogView = require "core.logview" 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, { ["core:quit"] = function() core.quit() @@ -126,6 +153,7 @@ command.add(nil, { ["core:change-project-folder"] = function() core.command_view:enter("Change Project Folder", function(text) + text = home_expand (text) local path_stat = system.get_file_info(text) if not path_stat or path_stat.type ~= 'dir' then core.error("Cannot open folder %q", text) @@ -134,21 +162,18 @@ command.add(nil, { if core.confirm_close_all() then core.open_folder_project(text) end - end, function(text) - return text == "" and core.recent_projects or common.dir_path_suggest(text) - end) + end, suggest_directory) end, ["core:open-project-folder"] = function() core.command_view:enter("Open Project", function(text) + text = home_expand (text) local path_stat = system.get_file_info(text) if not path_stat or path_stat.type ~= 'dir' then core.error("Cannot open folder %q", text) return end system.exec(string.format("%q %q", EXEFILE, text)) - end, function(text) - return text == "" and core.recent_projects or common.dir_path_suggest(text) - end) + end, suggest_directory) end, }) diff --git a/src/main.c b/src/main.c index f982e12d..6b05b769 100644 --- a/src/main.c +++ b/src/main.c @@ -132,14 +132,12 @@ init_lua: " DATADIR = prefix and (prefix .. '/share/lite-xl') or (EXEDIR .. '/data')\n" " end\n" #endif - " do\n" #ifdef _WIN32 - " local home = os.getenv('USERPROFILE')\n" + " HOME = os.getenv('USERPROFILE')" #else - " local home = os.getenv('HOME')\n" + " HOME = os.getenv('HOME')" #endif - " USERDIR = home and (home .. '/.config/lite-xl') or (EXEDIR .. '/user')\n" - " end\n" + " USERDIR = HOME and (HOME .. '/.config/lite-xl') or (EXEDIR .. '/user')\n" " package.path = package.path .. ';' .. USERDIR .. '/?.lua'\n" " package.path = package.path .. ';' .. USERDIR .. '/?/init.lua'\n" " package.path = DATADIR .. '/?.lua;' .. package.path\n"