Skip to main content

A command-line tool to manage Bitbucket snippets.

Project description

snipper

Manage Bitbucket snippets from command line easy

https://img.shields.io/pypi/v/snipper.svg https://img.shields.io/pypi/pyversions/snipper.svg https://img.shields.io/pypi/l/snipper.svg

Why?

I created snipper because I prefer Bitbucket snippet instead of Github gist. So why?

Because gists are secret but not private. So anyone can discover your secret gists by brute-forcing url or finding url of your gist from somewhere.

Snipper

Usage

Usage: snipper [OPTIONS] COMMAND [ARGS]...

Options:
  -C, --config PATH       Config file path: Default: $HOME/.snipperrc
  --no-color              Disable colorizing output
  -h, --help              Show this message and exit.

Commands:
  ls    List local snippets
  new   Create new snippet from file[s]/STDIN
  add   Add file[s] to snippet
  edit  Edit snippet file
  pull  Update local snippets from Bitbucket.
  sync  Sync snippets with Bitbucket

Installation

pip install snipper

Creating new snippet

Create a snippet from the contents of foo.py by just the following:

snipper new foo.py

Create snippet from multiple files:

snipper new a b c
snipper new *.py

‌By default, it reads from STDIN, and you can set a filename with -f parameter.

snipper new -f test.py < a.py

Alternatively, you can just paste from the clipboard:

snipper new -P

Snipper creates snippets as private by default. ‌Use -p to make the snippet public:

snipper new -p a.py

Use -t parameter to add title to snippet:

snipper new -t "Postgresql notes" postgres.md

If you’d like to copy the resulting URL to your clipboard, use -c parameter.

snipper new -c a.py

And you can just ask snipper to open a created snippet on a browser tab with -o.

snipper new -o < a.md

Adding files to existing snippet

You can add existing file to a snippet:

snipper add [snippetId] a.py

If you don’t give snippet id to add command, snipper opens a fuzzy snippet selection prompt in order to add file to the selected snippet.

snipper add foo.py

Also if you don’t add a file to snipper as parameter, snipper opens a new file with your default editor.

After you save and close the editor, new file will be added to selected snippet.

snipper add

Also you can read content from clipboard by -P or by redirecting output from STDIN to snipper.

cat *.txt | snipper add -f foo.txt
snipper add -P

If you didn’t specified any file name with -f option, default_filename config will be used as the filename.

Editing snippet files

You should give the path of a snippet file for editing.

snipper edit

If you don’t give any path, snipper opens a fuzzy search prompt for file selection:

snipper edit Ahg2l/notes.md

Pulling/Syncing snippets

If you make changes on snippets at bitbucket.org website, you can get these changes from Bitbucket with pull command

snipper pull

If you disabled auto pushing feature from config file, you should sync snippets manually. sync pushes unpushed local changes to Bitbucket and pull the new changes from Bitbucket if any exist.

snipper sync

See snipper --help for more detail. Also you can get help for any specified command as below:

snippet new --help

Login

Bitbucket does not support token authentication for users now, but you can create an app password that is permitted only to snippets on Bitbucket settings page. Nobody cannot login or access to your bitbucket data with given username and password, except making request to Bitbucket API for your snippets.

Bitbucket snippets are git or mercurial repositories. So, pulling changes from Bitbucket or pushing changes to Bitbucket requires public key authentication. Therefore, you can use ssh-agent not to enter password at every snippet pull/push.

Configuration

When you run snipper for the first time, by default snipper creates a config file in your home directory.

Config file example with defaults:

[snipper]
username=
password=
auto_push=on
default_filename=file.txt
colorize=on

username, password: Using for authenticating to Bitbucket API

default_filename : If you did not specify filename with -f parameter, this name will be used as filename while creating a new snippet or adding new files to a snippet.

auto_push : If this option is enabled, snipper pushes changes after new,add and edit commands are executed. Otherwise, you need to push the changes manually.

colorize : By default, snipper colorizes the output, but you can disable colorizing in config file. Also, you can use --no-color option with any snipper command.

If you want to keep snipper config file at another location different from home directory, you can use -C parameter to be the default location. Also you can add an alias to your ~/.bashrc (or equivalent). For example:

alias sp='snipper -C ~/dotfiles/snipperrc'

Environment variables

SNIPPER_USERNAME, SNIPPER_PASSWORD: Use this username and password instead of reading from config file every time.

HTTP_PROXY, HTTPS_PROXY: If you need to use a proxy to access the internet, use one of these environment variables and snipper will use it.

BROWSER : Use specified browser for opening snippets in a browser.

Requirements

  • Git or Mercurial: Each Bitbucket snippet is a git or mercurial repository. So at least one of git or mercurial must be installed.

  • requests

  • prompt-toolkit

  • click

  • pyperclip


Licensed under the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snipper-1.3.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

snipper-1.3-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file snipper-1.3.tar.gz.

File metadata

  • Download URL: snipper-1.3.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for snipper-1.3.tar.gz
Algorithm Hash digest
SHA256 c5645d8d0e9c9e5fdd3d43a66a6af9868964f6e02aa6f57dd2c92a887c74dfa7
MD5 249ef3714ad9bd353318bd9f0c9b0624
BLAKE2b-256 5c28de95647851ebbc9d5d7799b53baba83d117c7d33de42bbbc23070a108ea2

See more details on using hashes here.

File details

Details for the file snipper-1.3-py3-none-any.whl.

File metadata

  • Download URL: snipper-1.3-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for snipper-1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bc35ad7523d5462ece85f433126519b8544cef2e9c6a29412edb1c8ebebbdf92
MD5 d28e729168db37f07df6873d324c2612
BLAKE2b-256 6e8248165f901f435709fd312a4ffb5972919e5b3d4f5d7124188525c4341b24

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page