Home

Awesome

tests black PyPI version PyPI - Downloads

shbin turns a Github repo into a pastebin.

It's a tiny command-line tool we've built at Shiphero that lets you easily upload code snippets, notebooks, images or any other content to a Github repository that acts as your internal pastebin, and returns the URL to share it with your team. If possible, this URL is automatically copied to the clipboard.

<p align="center"> <img width="90%" src="https://raw.githubusercontent.com/Shiphero/shbin/main/demo/usage.svg" /> </p>

Why?

You want to share code snippets, images, notebooks, etc. with your team, probably privately. Gist is great, but it has some limitations:

Using a full repository has all the advantages of Gist (rich content rendering like markdown or ipynb, every change is a git commit, etc.) without these limitations.

The only downside of a plain repository is that it is not as easy as "paste" the content, even when editing through the Github interface. But shbin solves that.

Usage

# upload or update a file
$ shbin demo.py

# upload with a commit description
$ shbin demo.py -m "my cool demo script"         

# Upload any content in clipboard, discovering its format. e.g.
# a screenshot. The name will be random but the extension will be
# based on the format detected.
$ shbin -x          

# upload the content in the clipboard with a given filename
$ shbin -x -f my_snippet.md 

# upload from stdin
$ echo "some content" | shbin -

# download a given file (inside the namespace)
$ shbin dl my_snippet.md     

# update the content of a file that already exists
$ shbin my_snippet.md

# from clipboard with a given name to a directory in your user directory
$ shbin -x -f the_coolest_thing.py -d coolest_things/python

# upload several files in a directory
$ shbin *.ipynb *.csv -d notebooks/project -m "my new work"   

# Reformat the URL to link to Github pages.
$ shbin demo.py -p

$ shbin -h   # show full options

How it works

It uses Github API to create or update files in the given repo. So there is no need to have the target repository fully cloned locally.

Install

The recommended way is to use pipx

pipx install shbin 

Alternatively, install directly with pip.

pip install --user shbin

To install the latest development version from the repository:

pip install --user https://github.com/Shiphero/shbin/archive/refs/heads/main.zip

OSX

shbin depends on python-magic. This can be installed as follows.

brew install libmagic
port install file

Setup

Create a new fine-grained personal token on Github restricted to your "pastebin" repository (under your user or your organization's ownership), with read and write permissions on "Contents".

image

Nice video courtesy of tuterm, asciinema and svg-term-cli

PRs are welcome!