-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdoskey_popup.lua
62 lines (51 loc) · 1.88 KB
/
doskey_popup.lua
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
--------------------------------------------------------------------------------
-- Provides a command for showing a list of doskey aliases and their expansions.
--
-- KEY BINDING:
--
-- Each default key binding here is only applied if the key isn't already bound
-- to something else.
--
-- You may also set key bindings manually in your .inputrc file.
--
--[[
# Default key bindings for abbr.
"\C-xd": "luafunc:doskey_popup" # CTRL-X,D show doskey aliases and their expansions in a popup list.
]]
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Helper functions.
local function sort_by_name(a, b)
return string.comparematches(a.value, b.value)
end
--------------------------------------------------------------------------------
-- Commands available for key bindings.
local function add_desc(macro, desc)
if rl.describemacro then
rl.describemacro(macro, desc)
end
end
add_desc("luafunc:doskey_popup", "Show doskey aliases and their expansions in a popup list")
-- luacheck: globals doskey_popup
function doskey_popup(rl_buffer, line_state) -- luacheck: no unused
local items = {}
for _,name in pairs(os.getaliases()) do
local command = os.getalias(name)
table.insert(items, { value=name, description=command.."\t" })
end
table.sort(items, sort_by_name)
local value = clink.popuplist("Doskey Aliases and Expansions", items)
if value then
rl_buffer:beginundogroup()
rl_buffer:setcursor(1)
rl_buffer:insert(value.." ")
rl_buffer:endundogroup()
end
end
--------------------------------------------------------------------------------
-- Default key bindings.
if rl.getbinding then
if not rl.getbinding([["\C-Xd"]]) then
rl.setbinding([["\C-Xd"]], [["luafunc:doskey_popup"]])
end
end