使用cmder时,访问svn目录报错的问题修复

本文介绍了一种在CMder中解决中文路径显示错误的方法,通过修改clink.lua文件中的svn_prompt_filter函数,实现了对带有中文的URL进行正确解析,避免了在含有中文的目录下操作时出现的错误提示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值