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.2.tar.gz (14.1 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: snipper-1.2.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for snipper-1.2.tar.gz
Algorithm Hash digest
SHA256 851cd5c037e617b89738e69ff4061ec112e999fdd5f62a92f7aa2caaf613d322
MD5 3f9a91ab2fbbad57f9ef77f05904fd8d
BLAKE2b-256 95023bfc513d8084589b118c91daee1c6395af4d7d1ab3a66f30945b9b066966

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