get "svn info" to not complain if it's not in an svn folder
I'm tinkering with some bash scripting for the PS1 variable, to control my command line colors. On开发者_JS百科e 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.
Redirect the standard error of your command to /dev/null
:
local branch=$(svn info | grep URL: 2> /dev/null)
The svn
command probably writes an error to stderr
when it fails to find a repo.
精彩评论