Package: shbin
shbinturns a Github repo into a pastebin.It's a tiny command-line tool we've built atShipherothat lets you easily upload code
snippets, notebooks, images, or any other file 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.Why?You want to share code snippets, images, notebooks, etc. with your team,
probably privately. Gist is great, but it has some limitations:The content may be secret but it is not private: if you have the url
you have the access (and to err is human).The ownership of the shared content is in the user's namespace, not
the organization's. What happens if the user leaves the organization?You can't find some secret content shared by a teammate if the URL is
lost. Only the person who created it can find it, and even that isn't
easy if the content doesn't have a good name and description.Content organization is difficult: you can upload multiple files to
a gist, but you can't create folders.The default gist interface does not allow you to "paste" an image (you
can paste it as part of a comment, but not as part of the gist content
itself). Sharing screenshots is a common use case on computers.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.
Butshbinsolves that.Usage#uploadorupdateafile$shbindemo.py#uploadwithacommitdescription$shbindemo.py-m"my cool demo script"#Uploadanycontentinclipboard,discoveringitsformat.e.g.#ascreenshot.Thenamewillberandombuttheextensionwillbe#basedontheformatdetected.$shbin-x#uploadthecontentintheclipboardwithagivenfilename$shbin-x-fmy_snippet.md#uploadfromstdin$echo"some content"|shbin-#downloadagivenfile(insidethenamespace)$shbindlmy_snippet.md#updatethecontentofafilethatalreadyexists$shbinmy_snippet.md#fromclipboardwithagivennametoadirectoryinyouruserdirectory$shbin-x-fthe_coolest_thing.py-dcoolest_things/python#uploadseveralfilesinadirectory$shbin*.ipynb*.csv-dnotebooks/project-m"my new work"#ReformattheURLtolinktoGithubpages.$shbindemo.py-p$shbin-h# show full optionsHow it worksIt
usesGithub APIto create or update files in the given repo. So there is no need to
have the target repository fully cloned locally.InstallThe recommended way is to usepipxpipx install shbinAlternatively, install directly withpip.pip install --user shbinTo install the latest development version from the repository:pip install --user https://github.com/Shiphero/shbin/archive/refs/heads/main.zipOSXshbin depends onpython-magic. This can be
installed as follows.When using Homebrew:brew install libmagicWhen using macports:port install fileSetupCreate anew fine-grained personal tokenon Github restricted to your "pastebin" repository (under your user or
your organization's ownership), with read and write permissions on
"Contents".Then set the environment variables in your preferred place:export SHBIN_GITHUB_TOKEN="<your personal token>"
export SHBIN_REPO="<user_or_org>/<repo>"   # example "Shiphero/pastebin"By defaultshbinassigns a top-level folder to separate the content
uploaded by each user. This can be changed using theSHBIN_NAMESPACEenvironment variable or the--namespaceargument from the command
line. For example:export SHBIN_NAMESPACE=""# no namespaceexport SHBIN_NAMESPACE="pastebin_folder"# the full pastebin is inside pastebin_folder/"export SHBIN_NAMESPACE="pastebin_folder/{user}"# mix of both: each user has its own subfolder
insidepastebin_folder/[optional] To interact with the clipboard, we use the librarypyclip.
This may require some additional system dependencies
depending your operating system.
Seethese notes.If you want to disable the automatic copying of the URL to the clipboard
you can set the environment variableSHBIN_COPY_URL=false(or "0" or "no").This is useful in some Linux distributions that use Wayland as the call viawl-copythatpyclipuses in such environment can be slow.Nice video courtesy oftuterm,asciinemaandsvg-term-cliPRs are welcome!