Created
June 17, 2024 13:23
-
-
Save 7shi/56eb227b2a84b1e2e1ad9188acf51708 to your computer and use it in GitHub Desktop.
[py] clipboard utility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, pyperclip | |
args = sys.argv[1:] | |
if len(args): | |
if args[0] == "-g": | |
if len(args) == 1: | |
print(pyperclip.paste().rstrip()) | |
elif len(args) == 2: | |
with open(args[1], "wb") as f: | |
f.write(pyperclip.paste().replace("\r\n", "\n").encode("utf-8")) | |
else: | |
print(f"Usage: getclip [file]", file=sys.stderr) | |
sys.exit(1) | |
elif args[0] == "-s": | |
if len(args) >= 3 and args[1] == "-f": | |
text = "" | |
for file in args[2:]: | |
with open(file, "r", encoding="utf-8") as f: | |
text += f.read().rstrip().replace("\r\n", "\n") + "\n" | |
pyperclip.copy(text) | |
elif len(args) >= 2 and args[1] != "-f": | |
pyperclip.copy(" ".join(args[1:])) | |
else: | |
print(f"Usage: setclip text ... | -f file ...", file=sys.stderr) | |
sys.exit(1) | |
else: | |
print(f"Usage: python {sys.argv[0]} -g file | -s (text ... | -f file ...)") | |
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
python.exe ~/share/clipboard.py -g $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
python.exe ~/share/clipboard.py -s $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment