-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2832a23
commit 859c7aa
Showing
2 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |