Blame


1 f8b8653d 2024-10-17 o #!/bin/sh
2 f8b8653d 2024-10-17 o
3 94ef9b78 2024-10-17 oliver.lo usage='usage: bbsnip file [...]'
4 f8b8653d 2024-10-17 o
5 f8b8653d 2024-10-17 o # Snippets overview | Bitbucket Cloud
6 f8b8653d 2024-10-17 o # https://support.atlassian.com/bitbucket-cloud/docs/snippets-overview/
7 f8b8653d 2024-10-17 o # https://developer.atlassian.com/bitbucket/api/2/reference/resource/snippets
8 f8b8653d 2024-10-17 o
9 f8b8653d 2024-10-17 o # https://docs.atlassian.com
10 94ef9b78 2024-10-17 oliver.lo confpath="$HOME/.config/atlassian/bitbucket.org"
11 f8b8653d 2024-10-17 o if ! test -f $confpath
12 f8b8653d 2024-10-17 o then
13 f8b8653d 2024-10-17 o echo "load auth from $confpath: no such file"
14 f8b8653d 2024-10-17 o exit 1
15 f8b8653d 2024-10-17 o fi
16 94ef9b78 2024-10-17 oliver.lo auth=`sed 1q $confpath`
17 f8b8653d 2024-10-17 o
18 94ef9b78 2024-10-17 oliver.lo if ! test $1
19 f8b8653d 2024-10-17 o then
20 94ef9b78 2024-10-17 oliver.lo echo $usage
21 94ef9b78 2024-10-17 oliver.lo exit 2
22 f8b8653d 2024-10-17 o fi
23 f8b8653d 2024-10-17 o
24 94ef9b78 2024-10-17 oliver.lo for f in $@
25 94ef9b78 2024-10-17 oliver.lo do
26 94ef9b78 2024-10-17 oliver.lo if ! test -f $f
27 94ef9b78 2024-10-17 oliver.lo then
28 94ef9b78 2024-10-17 oliver.lo echo "open $f: no such file" 1>&2
29 94ef9b78 2024-10-17 oliver.lo continue
30 94ef9b78 2024-10-17 oliver.lo fi
31 94ef9b78 2024-10-17 oliver.lo files="-F file=@$f $files"
32 94ef9b78 2024-10-17 oliver.lo done
33 94ef9b78 2024-10-17 oliver.lo if test -z "$files"
34 94ef9b78 2024-10-17 oliver.lo then
35 94ef9b78 2024-10-17 oliver.lo echo "no files" 1>&2
36 94ef9b78 2024-10-17 oliver.lo exit 1
37 94ef9b78 2024-10-17 oliver.lo fi
38 94ef9b78 2024-10-17 oliver.lo
39 94ef9b78 2024-10-17 oliver.lo curl -s -u $auth $files https://api.bitbucket.org/2.0/snippets/audinate \
40 94ef9b78 2024-10-17 oliver.lo | sed 's/}/\n/g' \
41 94ef9b78 2024-10-17 oliver.lo | tr -d '{}",' \
42 94ef9b78 2024-10-17 oliver.lo | sed 's/href//g' \
43 94ef9b78 2024-10-17 oliver.lo | grep '^html' \
44 94ef9b78 2024-10-17 oliver.lo | sed 's/^html:://g' \
45 94ef9b78 2024-10-17 oliver.lo | sed 1q
46 94ef9b78 2024-10-17 oliver.lo
47 94ef9b78 2024-10-17 oliver.lo # the pipeline creates newline-delimited links from JSON structured like below
48 94ef9b78 2024-10-17 oliver.lo # {"links":{"self":{"href":"https://api.bitbucket.org/2.0/snippets/example/MzBoBz"},"html":{"href":"https://bitbucket.org/example/workspace/snippets/MzBoBz"},"commits":{"href":"https://api.bitbucket.org/2.0/snippets/example/MzBoBz/commits"},"comments":{"href":"https://api.bitbucket.org/2.0/snippets/example/MzBoBz/comments"},"watchers":{"href":"https://api.bitbucket.org/2.0/snippets/example/MzBoBz/watchers"},"diff":{"href":"https://api.bitbucket.org/2.0/snippets/example/MzBoBz/c81b16e0a2ff5a62421210dd42d4118bb2407a8d/diff"},"clone":[{"name":"https","href":"https://oliverlowe@bitbucket.org/snippets/example/MzBoBz/untitled-snippet.git"},{"name":"ssh","href":"git@bitbucket.org:snippets/example/MzBoBz/untitled-snippet.git"}],"patch":{"href":"https://api.bitbucket.org/2.0/snippets/example/MzBoBz/c81b16e0a2ff5a62421210dd42d4118bb2407a8d/patch"}},"type":"snippet","id":"MzBoBz","title":"","scm":"git","created_on":"2024-10-17T09:54:00.728326+00:00","updated_on":"2024-10-17T09:54:00.728340+00:00","owner":{"display_name":"example","links":{"self":{"href":"https://api.bitbucket.org/2.0/workspaces/%7Bced171c1-c5f6-4764-a40f-2f3d95e465c0%7D"},"avatar":{"href":"https://bitbucket.org/account/example/avatar/"},"html":{"href":"https://bitbucket.org/%7Bced171c1-c5f6-4764-a40f-2f3d95e465c0%7D/"}},"type":"team","uuid":"{ced171c1-c5f6-4764-a40f-2f3d95e465c0}","username":"example"},"workspace":{"type":"workspace","uuid":"{ced171c1-c5f6-4764-a40f-2f3d95e465c0}","name":"example","slug":"example","links":{"avatar":{"href":"https://bitbucket.org/workspaces/example/avatar/?ts=1725923130"},"html":{"href":"https://bitbucket.org/example/"},"self":{"href":"https://api.bitbucket.org/2.0/workspaces/example"}}},"creator":{"display_name":"Oliver Lowe","links":{"self":{"href":"https://api.bitbucket.org/2.0/users/%7B10a97824-3836-4423-b44b-102c46c2b49c%7D"},"avatar":{"href":"https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/initials/OL-6.png"},"html":{"href":"https://bitbucket.org/%7B10a97824-3836-4423-b44b-102c46c2b49c%7D/"}},"type":"user","uuid":"{10a97824-3836-4423-b44b-102c46c2b49c}","account_id":"712020:7e4caa14-0f34-4288-ae22-288b37e49dc7","nickname":"oliver.lowe"},"is_private":false,"files":{"bbsnip.1":{"links":{"self":{"href":"https://api.bitbucket.org/2.0/snippets/example/MzBoBz/c81b16e0a2ff5a62421210dd42d4118bb2407a8d/files/bbsnip.1"},"html":{"href":"https://bitbucket.org/snippets/example/MzBoBz/revisions/c81b16e0a2ff5a62421210dd42d4118bb2407a8d#file-bbsnip.1"}}}}}