SVN: add colors to svn command line with awk (in bash)

EDIT: Here is the updated version of this Github snippet, stable.


Here is the piece of Bash code (I put it in the .bashrc file) that works :

function svn { command svn " $@ " | awk ' BEGIN { cpt_c=0; } { if ($1=="C") { cpt_c=cpt_c+1; print "\033[31m" $0 "\033[00m"; # Conflicts are displayed in red } else if ($1=="A") { print "\033[32m" $0 "\033[00m"; # Add in green } else if ($1=="?") { print "\033[36m" $0 "\033[00m"; # New in cyan } else if ($1=="D") { print "\033[35m" $0 "\033[00m"; # Delete in magenta } else { print $0; # No color, just print the line } } END { print cpt_c, " conflicts are found."; }'; } 

This piece of code does exactly what I want. Svn functions (status, update, etc.) are printed in colors. For internal needs, I don’t want to install things like colorsvn or svn-color .

Here is an example of the above code: (not enough reputation for posting images)

svn command displayed in colors

And again, this is exactly what I want . The problem occurs when a conflict is detected (for example, when I do an update): indeed, when a file conflicts, svn is passed to the user to type a few letters (see below)

 # svn update Conflict discovered in 'test.txt'. Select: (p) postpone, (df) diff-full, (e) edit, (mc) mine-conflict, (tc) theirs-conflict, (s) show all options: 

Is there an awk way to let the user enter something (for example, e, open a conflicting file in the VIm), do something (for example, delete some lines after type e, then save and close) and type another letter to confirm the resolution of the conflict , then finally display the next svn update step (other files, etc.)?

In other words, I want to β€œpause” a script that displays colors to allow the user to interact with svn and then update svn. I think that in the future it will be very useful for you to know how to get awk to pause the caller script and then resume!

+7
source share
3 answers

Have you tried running svn update --accept postpone so that svn does not request conflicts?

+3
source

Although you are not particularly answering your question - I created a slightly modified version of your script in which I bypassed awk when running svn commit . In addition, I have added several colors for certain types of output. The script is available online - feel free to make changes.

+2
source

Here is a simple and safe workaround (tested with a script). Because svn just calls

 system(getenv("SVN_EDITOR")) // or something similar 

you can simply do the following (in bash, configure for other shells):

 export SVN_EDITOR="</dev/tty >&/dev/tty vi" 

Then you can make your changes and save your awk coloring scheme.

I don’t know if he works with other editors, but I hope that it is. This should mean that these are standard redirects.

0
source

All Articles