Skip to content

Instantly share code, notes, and snippets.

@koirikivi
Last active February 24, 2020 12:10
Show Gist options
  • Save koirikivi/893cf5c7c838bf8d6661d17fdff3747d to your computer and use it in GitHub Desktop.
Save koirikivi/893cf5c7c838bf8d6661d17fdff3747d to your computer and use it in GitHub Desktop.
Copy selection as un-indented code block (for Slack, Telegram, etc)
#!/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