Skip to content

Instantly share code, notes, and snippets.

@mugyu
Created August 19, 2012 12:33
Show Gist options
  • Save mugyu/3394632 to your computer and use it in GitHub Desktop.
Save mugyu/3394632 to your computer and use it in GitHub Desktop.
nyaos3kの動的プロンプトでsvnのurlやgitのbranch名をプロンプトに出力
-- svnの作業dirでurlを、そしてgitの作業dirでbranch名をプロンプトに出力
function nyaos.prompt(prompt)
local current = nyaos.eval('__pwd__')
if nyaos.access(current .. '/.svn/entries', 0) then
local svn_url = string.match(nyaos.eval('svn info --xml'), '<url>(.*)</url>', 1)
return true, '$e[36;40;1mSVN[' .. svn_url .. ']' .. prompt
else
local git_path = current
repeat
if nyaos.access(git_path .. '/.git', 0) then
local git_branch = string.match(nyaos.eval('git branch'), '* (%S*)', 1)
if git_branch then
return true, '$e[33;40;1mGIT[' .. git_branch .. ']' .. prompt
end
break
end
git_path = string.match(git_path, '^(.+)\\', 1)
until not git_path
end
return nil, prompt
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment