From 448cb4d13d92a815e23cd4b6e93a16a67fa951b6 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Mon, 25 Dec 2023 22:14:56 +0100 Subject: [PATCH] console.lua: expand ~/ in file completion Makes Tab expand loadfile ~/ to loadfile /home/$USER/. I used expand-path instead of os.getenv('HOME') to make it work on Windows. --- player/lua/console.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/player/lua/console.lua b/player/lua/console.lua index ab2edc2eaf..1ddfca151a 100644 --- a/player/lua/console.lua +++ b/player/lua/console.lua @@ -1049,6 +1049,16 @@ function complete(backwards) completion_start_position = s2 end + -- Expand ~ in file completion. + if completer.list == file_list and hint:find('^~' .. path_separator) then + local home = mp.command_native({'expand-path', '~/'}) + before_cur = before_cur:sub(1, completion_start_position - #hint - 1) .. + home .. + before_cur:sub(completion_start_position - #hint + 1) + hint = home .. hint:sub(2) + completion_start_position = completion_start_position + #home - 1 + end + -- If the completer's pattern found a word, check the completer's -- list for possible completions local part = before_cur:sub(completion_start_position)