Skip to content

Commit

Permalink
Expose functionality to get plugin short name (#861)
Browse files Browse the repository at this point in the history
  • Loading branch information
runiq committed Mar 23, 2022
1 parent 2d08167 commit 4dedd3b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
9 changes: 1 addition & 8 deletions lua/packer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,7 @@ manage = function(plugin_data)
return
end

local path = vim.fn.expand(plugin_spec[1])
local name_segments = vim.split(path, util.get_separator())
local segment_idx = #name_segments
local name = plugin_spec.as or name_segments[segment_idx]
while name == '' and segment_idx > 0 do
name = name_segments[segment_idx]
segment_idx = segment_idx - 1
end
local name, path = util.get_plugin_short_name(plugin_spec)

if name == '' then
log.warn('"' .. plugin_spec[1] .. '" is an invalid plugin name!')
Expand Down
12 changes: 12 additions & 0 deletions lua/packer/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ util.join_paths = function(...)
return table.concat({ ... }, separator)
end

util.get_plugin_short_name = function(plugin)
local path = vim.fn.expand(plugin[1])
local name_segments = vim.split(path, util.get_separator())
local segment_idx = #name_segments
local name = plugin.as or name_segments[segment_idx]
while name == '' and segment_idx > 0 do
name = name_segments[segment_idx]
segment_idx = segment_idx - 1
end
return name, path
end

util.get_plugin_full_name = function(plugin)
local plugin_name = plugin.name
if plugin.branch and plugin.branch ~= 'master' then
Expand Down

0 comments on commit 4dedd3b

Please sign in to comment.