Created
April 1, 2016 06:29
-
-
Save pantox/0e54ea3cb1144756f9e6f1b34f456dad to your computer and use it in GitHub Desktop.
remove (<invalid_name>@<invalid_version>) from cmder promt when there is no name and version field in your package.json file
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
function npm_prompt_filter() | |
local package = io.open('package.json') | |
if package ~= nil then | |
local package_info = package:read('*a') | |
package:close() | |
local package_name = string.match(package_info, '"name"%s*:%s*"(.-)"') | |
or "" | |
local package_version = string.match(package_info, '"version"%s*:%s*"(.-)"') | |
or "" | |
if package_name == "" and package_version == "" then | |
local package_string = "" | |
else | |
local package_string = color.color_text("("..package_name.."@"..package_version..")", color.YELLOW) | |
clink.prompt.value = clink.prompt.value:gsub('{git}', '{git} '..package_string) | |
end | |
end | |
return false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice work :) Consider a pull request.