summaryrefslogtreecommitdiffstats
path: root/player/lua
diff options
context:
space:
mode:
authorGuido Cella <guido@guidocella.xyz>2023-12-25 22:14:56 +0100
committerDudemanguy <random342@airmail.cc>2024-01-04 13:41:15 +0000
commit448cb4d13d92a815e23cd4b6e93a16a67fa951b6 (patch)
tree57ac9affe1cce0bbf26e005b81203a3f8de8ca0a /player/lua
parent5864b72d1a0aecd7e2d56e546fb615d291c88274 (diff)
downloadmpv-448cb4d13d92a815e23cd4b6e93a16a67fa951b6.tar.bz2
mpv-448cb4d13d92a815e23cd4b6e93a16a67fa951b6.tar.xz
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.
Diffstat (limited to 'player/lua')
-rw-r--r--player/lua/console.lua10
1 files changed, 10 insertions, 0 deletions
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)