Mercurial > dotfiles
annotate unixSoft/bin/patchpipe @ 351:bef29d49d19f
safe-paste: adds support for bracketed paste mode to zsh
Since I don't use oh-my-zsh, just import their code directly with a
reference. Based on the site where I learned about this [0], it's
originally from [1], and I downloaded it from [2].
0: https://cirw.in/blog/bracketed-paste
1: http://www.zsh.org/mla/users/2011/msg00367.html
2: https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/plugins/safe-paste/safe-paste.plugin.zsh
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Mon, 10 Nov 2014 09:26:04 -0500 |
parents | 4e83916a4303 |
children | c7a9cd793e37 |
rev | line source |
---|---|
344
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
2 import os |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
3 import subprocess |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
4 import sys |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
5 import tempfile |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
6 |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
7 _PATCHHDR = '# HG changeset patch' |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
8 |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
9 |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
10 def main(argv): |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
11 tf = tempfile.NamedTemporaryFile(suffix='.diff') |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
12 d = sys.stdin.read() |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
13 if _PATCHHDR in d: |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
14 junk, d = d.split(_PATCHHDR, 1) |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
15 d = _PATCHHDR + d |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
16 tf.write(d) |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
17 tf.flush() |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
18 subprocess.check_call([os.environ['EDITOR'], tf.name], |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
19 stdout=sys.stderr) |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
20 sys.stdout.write(open(tf.name).read()) |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
21 |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
22 |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
23 if __name__ == '__main__': |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
24 main(argv=sys.argv) |