X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=cmd%2Fnewliner-cmd.py;h=20027ab104a1e495b4abff2b9853e1818430b3ed;hb=e4ada8c5f7ba1b8273fa8edcda226fe526647e7b;hp=6b505b4a992b97d913cb1679ba11b99a0a4f9065;hpb=26a32bacfa97dcb2297f3c0723ef7507bcaf056a;p=bup.git diff --git a/cmd/newliner-cmd.py b/cmd/newliner-cmd.py index 6b505b4..20027ab 100755 --- a/cmd/newliner-cmd.py +++ b/cmd/newliner-cmd.py @@ -1,11 +1,17 @@ -#!/usr/bin/env python +#!/bin/sh +"""": # -*-python-*- +bup_python="$(dirname "$0")/bup-python" || exit $? +exec "$bup_python" "$0" ${1+"$@"} +""" +# end of bup preamble import sys, os, re from bup import options +from bup import _helpers # fixes up sys.argv on import optspec = """ bup newliner """ -o = options.Options('bup newliner', optspec) +o = options.Options(optspec) (opt, flags, extra) = o.parse(sys.argv[1:]) if extra: @@ -14,6 +20,7 @@ if extra: r = re.compile(r'([\r\n])') lastlen = 0 all = '' +width = options._tty_width() or 78 while 1: l = r.split(all, 1) if len(l) <= 1: @@ -31,7 +38,8 @@ while 1: else: assert(len(l) == 3) (line, splitchar, all) = l - #splitchar = '\n' + if splitchar == '\r': + line = line[:width] sys.stdout.write('%-*s%s' % (lastlen, line, splitchar)) if splitchar == '\r': lastlen = len(line) @@ -39,5 +47,7 @@ while 1: lastlen = 0 sys.stdout.flush() -if lastlen or all: - sys.stdout.write('%-*s\n' % (lastlen, all)) +if lastlen: + sys.stdout.write('%-*s\r' % (lastlen, '')) +if all: + sys.stdout.write('%s\n' % all)