x

Programs, configuration and documentation that don't fit anywhere else
Log | Files | Refs | README | LICENSE

bbsnip (3432B)


      1 #!/bin/sh
      2 
      3 usage='usage: bbsnip file [...]'
      4 
      5 # Snippets overview | Bitbucket Cloud
      6 # https://support.atlassian.com/bitbucket-cloud/docs/snippets-overview/
      7 # https://developer.atlassian.com/bitbucket/api/2/reference/resource/snippets
      8 
      9 # https://docs.atlassian.com
     10 confpath="$HOME/.config/atlassian/bitbucket.org"
     11 if ! test -f $confpath
     12 then
     13 	echo "load auth from $confpath: no such file"
     14 	exit 1
     15 fi
     16 auth=`sed 1q $confpath`
     17 
     18 if ! test $1
     19 then
     20 	echo $usage
     21 	exit 2
     22 fi
     23 
     24 for f in $@
     25 do
     26 	if ! test -f $f
     27 	then
     28 		echo "open $f: no such file" 1>&2
     29 		continue
     30 	fi
     31 	files="-F file=@$f $files"
     32 done
     33 if test -z "$files"
     34 then
     35 	echo "no files" 1>&2
     36 	exit 1
     37 fi
     38 
     39 curl -s -u $auth -F is_private=true $files https://api.bitbucket.org/2.0/snippets/audinate \
     40 	| sed 's/}/\n/g' \
     41 	| tr -d '{}",' \
     42 	| sed 's/href//g' \
     43 	| grep '^html' \
     44 	| sed 's/^html:://g' \
     45 	| sed 1q
     46 
     47 # the pipeline creates newline-delimited links from JSON structured like below
     48 # {"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"}}}}}