天天看點

使用cmder時,通路svn目錄報錯的問題修複

用cmder通路,在有中文的目錄,會提示錯誤。我這裡修改了它的代碼,解決這個問題。

打開cmder\vendor\clink.lua,找到function svn_prompt_filter(),然後用下面的代碼替換就可以了。主要原因是帶中文擴URL是%XX表示漢字的,在這裡處理的時候,報錯了。下面是修改後的代碼:

function decodeURI(s)
    s = string.gsub(s, '%%(%x%x)', function(h) return string.char(tonumber(h, 16)) end)
    return s
end

function svn_prompt_filter()
    -- //Colors for svn status
    local colors = {
        clean = "\x1b[1;37;40m",
        dirty = "\x1b[31;1m",
    }

    if get_svn_dir() then
        -- //if we are inside of svn repo then try to detect current branch
        local branch = get_svn_branch()
        local color
        if branch then
            if get_svn_status() then
                color = colors.clean
            else
                color = colors.dirty
            end
			local newBranch = decodeURI(branch)

            clink.prompt.value = string.gsub(clink.prompt.value, "{svn}", color.."("..newBranch..")")
            return false
        end
    end

    -- //No mercurial present or not in mercurial file
    clink.prompt.value = string.gsub(clink.prompt.value, "{svn}", "")
    return false
end