Skip to content

Instantly share code, notes, and snippets.

@bahamas10
Last active January 4, 2019 18:02
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bahamas10/d58ea9d51493d7f99f19 to your computer and use it in GitHub Desktop.
Save bahamas10/d58ea9d51493d7f99f19 to your computer and use it in GitHub Desktop.
Joyent Manta Functions

Joyent Manta Functions

Taken from https://github.com/bahamas10/dotfiles/blob/master/bashrc

mbillable

Show amount of billable storage spaced used in Manta

Allows the user to optionally be specified as the first argument

Example

$ mbillable 
bahamas10 => using 2 GB (3 GB billable)
$ mbillable papertigers
papertigers => using 4 GB (5 GB billable)

mopen

Open Manta files using open on the current system

Example

$ mopen /Joyent_Dev/public/SmartOS/smartos.html

Will open the SmartOS changelog in your browser (on a Mac).

mpaste

Store pastebin style pastes with syntax highlighting in Manta

Pass a file as the first argument, or as stdin, to create a paste in manta and print the URL to stdout

Requires Pygments, which can be installed with sudo easy_install Pygments or similiar.

Example

$ mpaste .bashrc
https://us-east.manta.joyent.com/dave.eddy@joyent.com/public/pastes/1438621637.html
$ cat .vimrc | mpaste
https://us-east.manta.joyent.com/dave.eddy@joyent.com/public/pastes/1438621641.html

(see https://us-east.manta.joyent.com/dave.eddy@joyent.com/public/pastes/1438621637.html)

murl

Convert Manta filenames to URLs

Example

$ murl ~~/public/foo /papertigers/public/foo 
https://us-east.manta.joyent.com/bahamas10/public/foo
https://us-east.manta.joyent.com/papertigers/public/foo

License

MIT License

# Total the billable amount in Manta
mbillable() {
local u=${1:-$MANTA_USER}
mget -q "/$u/reports/usage/storage/latest" |\
json storage | json {public,stor,reports,jobs}.bytes |\
awk -v "u=$u" "
{
s += \$1;
}
END {
gb = s / 1024 / 1024 / 1024;
billable = gb + 1;
printf(\"%s => using %d GB (%d GB billable)\\n\",
u, gb, billable);
}
"
}
# Open files from manta in the browser
mopen() {
murl "$@" | xargs open
}
# Paste bin using manta
mpaste() {
local mfile=~~/public/pastes/$(date +%s).html
pygmentize -f html -O full "$@" | mput -p "$mfile"
murl "$mfile"
}
# convert manta paths into URLs
murl() {
local u
for u in "$@"; do
echo "$MANTA_URL${u/#~~//$MANTA_USER}"
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment