Skip to content

Commit

Permalink
Add support for git aliases that include flags or !.
Browse files Browse the repository at this point in the history
NOTE: This has no effect unless it's running in Clink v1.6.18 or higher.

The new version of Clink is expected to be published in a few days.
  • Loading branch information
chrisant996 committed Jul 27, 2024
1 parent da3c878 commit fc951ef
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
20 changes: 19 additions & 1 deletion git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2771,10 +2771,28 @@ local function init(argmatcher, full_init)
-- function, the sort order when displaying completions is defined by the
-- alias function. But these do affect input line parsing and coloring.
local aliases = get_git_aliases()
local complex, chain
for _, a in ipairs(aliases) do
local linked = linked_parsers[a.command]
local linked
if not clink_version.supports_onalias then
linked = linked_parsers[a.command]
end
if linked then
table.insert(commands, a.name..linked)
else
local bang = a.command:match("^%!") and true or nil
local command = a.command:sub(bang and 2 or 1)
complex = complex or {}
chain = chain or {}
complex[a.name] = command
chain[a.name] = bang
table.insert(commands, a.name)
end
end

if complex then
commands.onalias = function(arg_index, word, word_index, line_state, user_data) -- luacheck: no unused
return complex[word], chain[word]
end
end

Expand Down
7 changes: 7 additions & 0 deletions modules/arghelper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@
--------------------------------------------------------------------------------
-- Changes:
--
-- 2024/07/23
-- - Support for `onalias=func`.
--
-- 2024/04/11
-- - Support for `hide_unless=func`.
--
-- 2023/11/18
-- - Support for `hide=true` in _addexarg().
--
Expand Down Expand Up @@ -394,6 +400,7 @@ if not tmp._addexflags or not tmp._addexarg then
list.loopchars = tbl.loopchars
list.nosort = tbl.nosort
list.onadvance = tbl.onadvance
list.onalias = tbl.onalias
list.onlink = tbl.onlink
list.onarg = tbl.onarg
if hide_unless then
Expand Down
1 change: 1 addition & 0 deletions modules/clink_version.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ exports.has_volatile_matches_fix = (clink_version_encoded >= 10040013)
exports.supports_argmatcher_onlink = (clink_version_encoded >= 10050014)
exports.has_linked_setdelayinit_fix = (clink_version_encoded >= 10050016)
exports.supports_argmatcher_nowordbreakchars = (clink_version_encoded >= 10050017)
exports.supports_onalias = (clink_version_encoded >= 10060018)

return exports

0 comments on commit fc951ef

Please sign in to comment.