1

I made a bash function to beautify svn output, this function show logs one line per commit, it is great! I like it, but if I use it with pipe it does not work. You can find it on github svn-beautify

$ svn -log -l 2
r22  fabio  2014-03-27 12:38:10 +0100 (gio, 27 mar 2014)  1 line  Some comments
r23  fabio  2014-03-27 13:35:17 +0100 (gio, 27 mar 2014)  1 line  Some comments

it would be nice if I could use it with | grep.

closed as unclear what you're asking by Gilles, strugee, jasonwryan, Braiam, Chris Down Mar 28 '14 at 2:08

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    What happens when you pipe into grep? What's the problem? – glenn jackman Mar 27 '14 at 21:40
  • I put svn function into my .bashrc so when I use svn log -l 10 I see output from my function instead svn standard command, but if I use svn log -l 10 | grep foo or svn log -l 10 | cat i see output from standartd svn command I would like use |grep from my svn function – Fabio Mar 27 '14 at 21:51
  • 3
    Your command is producing color escape sequence. Grepping for e.g. "Some comments" won't work, because it's really "<blue>Some<black> comments". – Mikel Mar 27 '14 at 21:56
  • ok, i don't care color into grep command, but if I use | grep foo grep don't use output from my function (one line per commit) but from standard svn (more lines per commit). – Fabio Mar 27 '14 at 22:00
  • 3
    Please edit your question to make it self-contained. That means posting (the relevant parts of) your code here, and explaining why it doesn't work (everything you posted in the comments here). – Gilles Mar 27 '14 at 23:24
3

You have this:

if [ "$SVN_COLOR" != "always" ] && ( 
        [ $NOCOL = 1 ] || [ "$SVN_COLOR" = "never" ] || [ ! -t 1 ]
)

It's the [ ! -t 1 ] test that is causing your function to return too early. When you pipe your function into a pipe, stdout (file descriptor 1) is not a terminal.

  • Beat me to it. Indeed this is exactly why. You may want to mention the potential problems with piping colored output, due to color being escape codes mixed in with the output. – derobert Mar 27 '14 at 22:05
  • I decided to leave the fix as an exercise for the author of the function :) – glenn jackman Mar 27 '14 at 22:10
  • GREAT it works !!!! I put if [ "$SVN_COLOR" != "always" ] && ([ $NOCOL = 1 ] || [ "$SVN_COLOR" = "never" ]) but what changes? – Fabio Mar 27 '14 at 22:17
  • The original function is svn-color i just modify log and diff case. – Fabio Mar 27 '14 at 22:23
  • I assume the original author did not want to pollute the svn output with colour codes if the output was going to be parsed by some program: colour codes are intended for human eyes. – glenn jackman Mar 27 '14 at 22:27
0

This definitely is not a general bash-function-with-pipes-problem.

~$ x() { ls "$@" ; }
~$ x / | cat -n | head
     1  bin
     2  boot
     3  dev
     4  etc
     5  home
     6  initrd.img
     7  initrd.img.old
     8  lib
     9  lib32
    10  lib64

...isn't there a special Stackexchange site for codereview? Maybe ask there?

Not the answer you're looking for? Browse other questions tagged or ask your own question.