Last active
February 24, 2020 12:10
-
-
Save koirikivi/893cf5c7c838bf8d6661d17fdff3747d to your computer and use it in GitHub Desktop.
Copy selection as un-indented code block (for Slack, Telegram, etc)
This file contains hidden or 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
#!/usr/bin/env python3 | |
""" | |
Turn input into something that's easy to paste to telegram/slack/other channels | |
as a code block | |
Usage: | |
$ cat foo | codify.py | xclip -selection clipboard | |
Vim shortcut to copy visual selection on <leader>c (add to .vimrc): | |
vmap <leader>c :w !cat \| codify.py \| xclip -selection clipboard<cr> | |
""" | |
import sys | |
from textwrap import dedent | |
def main(): | |
s = sys.stdin.read() | |
s = dedent(s) | |
print(f'```\n{s}```') | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment