ikame committed 969eb7c

Better clipboard access from the terminal

Comments (0)

Files changed (1)

  • +42 -0
+#!/usr/bin/env python
+"""System clipboard access.
+If executed normally send the contents of the clipboard to stdout. If you pipe
+to it, it will put that content in the clipboard.
+import sys
+import argparse
+import subprocess
+import shlex
+if 'darwin' in sys.platform:
+    copy_cmd = 'pbcopy'
+    paste_cmd = 'pbpaste'
+elif 'linux' in sys.platform:
+    copy_cmd = paste_cmd = 'xclip'
+    sys.exit('Unsupported platform')
+copy = shlex.split(copy_cmd)
+paste = shlex.split(paste_cmd)
+def main(argv=None):
+    if argv is None:
+        argv = sys.argv[1:]
+    parser = argparse.ArgumentParser(description=__doc__)
+    parser.parse_args(argv)
+    input_data = None if sys.stdin.isatty() else sys.stdin
+    if input_data:
+, stdin=input_data)
+    else:
+, stdout=sys.stdout)
+if __name__ == '__main__':
+    sys.exit(main())
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.