获取“svn 信息”如果它不在 svn 文件夹中,不要抱怨
我正在修改 PS1 变量的一些 bash 脚本,以控制我的命令行颜色。我想做的一件事是,如果我位于 svn 存储库中,则在本地文件夹名称后面加上“(svn)”。我尝试使用 .bashrc 中的这个函数来实现此 atm,当我设置 PS1 时我会调用该函数:
function __svn_branch {
local branch=$(svn info | grep URL:)
[ "$branch" != "" ] && echo "(svn)"
}
如果我位于 svn 文件夹中,则效果很好。但是,如果我转到非 svn 文件夹,则会触发此投诉 “svn: '.'不是工作副本”
这显然很烦人。我不是 bash 脚本专家,有人能知道如何阻止这个吗?
谢谢,max
我想到了另一种方法来判断我是否在 svn 文件夹中,即查找 .svn 目录,但 svn 信息似乎更干净。另外,我只是好奇如何停止错误消息,或者以某种方式将其隐藏在我的 bash 脚本中。
I'm tinkering with some bash scripting for the PS1 variable, to control my command line colors. One of the things i want to do is to put "(svn)" after the local folder name if i'm in an svn repo. How i'm trying to do this atm is with this function in my .bashrc, which i call when i set PS1:
function __svn_branch {
local branch=$(svn info | grep URL:)
[ "$branch" != "" ] && echo "(svn)"
}
This works fine if i'm in an svn folder. However, if i go to a non-svn folder, it triggers this complaint "svn: '.' is not a working copy"
which is obviously annoying. I'm not a bash scripting expert, can anyone see how to stop this?
thanks, max
I thought of an alternative way to tell if i'm in an svn folder, which is to look for a .svn directory, but svn info seems cleaner somehow. Plus i'm just curious as to how to stop the error message, or hide it in my bash script somehow.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将命令的标准错误重定向到
/dev/null
:svn
命令在找不到存储库时可能会向stderr
写入错误。Redirect the standard error of your command to
/dev/null
:The
svn
command probably writes an error tostderr
when it fails to find a repo.