Skip to content

Instantly share code, notes, and snippets.

@pantox
Created April 1, 2016 06:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pantox/0e54ea3cb1144756f9e6f1b34f456dad to your computer and use it in GitHub Desktop.
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
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
@erkantaylan
Copy link

Nice work :) Consider a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment