I am frequently working with subversion in console using its client svn. One of common tasks is viewing svn log; however its output is usually pretty massive despite of --limit option. I would like to pipe the output to my $PAGER (which is less to be exact), just like git log does. I wonder if this can be achieved with zsh advanced completion features; i.e. whenever I type

svn log path1 path2 path3<Enter>

the piping construction will be appended:

svn log path1 path2 path3 | $PAGER

This resembles to me the way aliases work, but from the "other side".

Is this possible in zsh?

up vote 6 down vote accepted

You can do this with a shell function. Just put this in your ~/.zshrc.

svn() {
    if [ "$1" = "log" ]
    then
        command svn "$@" | less -FX
    else
        command svn "$@"
    fi
}

I've tested that with bash and p4, but it should work the same with zsh and svn. The -FX options to less tell it to quit if the entire file fits on the first screen and not to switch to the alternate screen. This makes it appear that less wasn't used at all if the output fits on one screen.

  • I like the solution. – ulidtko Feb 4 '11 at 21:44

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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