Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added maven prompt #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion _powerline_config.lua.sample
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,7 @@ plc_hg_conflictSymbol = "!"
-- You can use "  " conflict symbol with 'Anonymous Powerline' font.

-- OPTIONAL. npm Symbol used in the NPM segment as visual indicator.
--plc_npm_npmSymbol = "NPM"
--plc_npm_npmSymbol = "NPM"

-- OPTIONAL. maven Symbol used in the maven segment as visual indicator.
--plc_npm_npmSymbol = "MVN"
71 changes: 71 additions & 0 deletions powerline_maven.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
local function get_pom_xml_dir(path)

-- return parent path for specified entry (either file or directory)
local function pathname(path)
local prefix = ""
local postfix = ""
local i = path:find("[\\/:][^\\/:]*$")
if i then
prefix = path:sub(1, i-1)

end
return prefix
end

if not path or path == '.' then path = clink.get_cwd() end

local parent_path = pathname(path)
return io.open(path..'\\pom.xml') or (parent_path ~= path and get_pom_xml_dir(parent_path) or nil)
end

-- * Segment object with these properties:
---- * isNeeded: sepcifies whether a segment should be added or not. For example: no Git segment is needed in a non-git folder
---- * text
---- * textColor: Use one of the color constants. Ex: colorWhite
---- * fillColor: Use one of the color constants. Ex: colorBlue
local segment = {
isNeeded = false,
text = "",
textColor = colorWhite,
fillColor = colorCyan
}

---
-- Sets the properties of the Segment object, and prepares for a segment to be added
---
local function init()
segment.isNeeded = get_pom_xml_dir()
if segment.isNeeded then
local package_info = segment.isNeeded:read('*a')
segment.isNeeded:close()

local package_name = string.match(package_info, '<name>%s*(%g-)%s*</name>')
if package_name == nil then
package_name = ''
end

local package_version = string.match(package_info, '<version>%s*(%g-)%s*</version>')
if package_version == nil then
package_version = ''
end

if plc_mvn_mvnSymbol then
segment.text = " "..mvnSymbol.." "..package_name.."@"..package_version.." "
else
segment.text = " "..package_name.."@"..package_version.." "
end
end
end

---
-- Uses the segment properties to add a new segment to the prompt
---
local function addAddonSegment()
init()
if segment.isNeeded then
addSegment(segment.text, segment.textColor, segment.fillColor)
end
end

-- Register this addon with Clink
clink.prompt.register_filter(addAddonSegment, 60)