6

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?

1 Answer 1

8

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.

2
  • 1
    I like the solution.
    – ulidtko
    Feb 4, 2011 at 21:44
  • 1
    Thank you from 12 years in the future. Nov 8, 2023 at 14:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .